“shubhamdhamal” commited on
Commit
94a151a
·
1 Parent(s): a08ee99

Revert to simple SQLite - remove PostgreSQL complexity

Browse files
Files changed (3) hide show
  1. config.py +2 -10
  2. requirements.txt +0 -1
  3. start.sh +3 -38
config.py CHANGED
@@ -16,16 +16,8 @@ class Config:
16
  # SECRET_KEY is CRITICAL for sessions and CSRF
17
  SECRET_KEY = os.environ.get('SECRET_KEY') or os.environ.get('FLASK_SECRET_KEY') or 'dev-secret-key-change-in-production-2024'
18
 
19
- # Database configuration
20
- # Support both DATABASE_URL (Render, Railway) and SUPABASE_DB_URL formats
21
- db_url = os.environ.get('DATABASE_URL') or os.environ.get('SUPABASE_DB_URL')
22
-
23
- # Fix postgres:// to postgresql:// (required by SQLAlchemy 1.4+)
24
- if db_url and db_url.startswith('postgres://'):
25
- db_url = db_url.replace('postgres://', 'postgresql://', 1)
26
-
27
- # Default to SQLite if no external database configured
28
- SQLALCHEMY_DATABASE_URI = db_url or 'sqlite:///' + os.path.join(basedir, 'instance', 'app.db')
29
  SQLALCHEMY_TRACK_MODIFICATIONS = False
30
 
31
  # WTF CSRF Settings - Temporarily disabled due to HF Spaces session issues
 
16
  # SECRET_KEY is CRITICAL for sessions and CSRF
17
  SECRET_KEY = os.environ.get('SECRET_KEY') or os.environ.get('FLASK_SECRET_KEY') or 'dev-secret-key-change-in-production-2024'
18
 
19
+ # Database configuration - Simple SQLite
20
+ SQLALCHEMY_DATABASE_URI = 'sqlite:///learning_path.db'
 
 
 
 
 
 
 
 
21
  SQLALCHEMY_TRACK_MODIFICATIONS = False
22
 
23
  # WTF CSRF Settings - Temporarily disabled due to HF Spaces session issues
requirements.txt CHANGED
@@ -14,7 +14,6 @@ langchain==0.0.267
14
  openai>=1.0.0 # Using new OpenAI API
15
  tiktoken>=0.5.0 # Token counting for cost optimization
16
  Flask-SQLAlchemy==3.1.1
17
- psycopg2-binary>=2.9.9 # Postgres driver for production
18
  Flask-Login==0.6.3
19
  Flask-WTF==1.2.1
20
  Flask-Migrate==4.0.7
 
14
  openai>=1.0.0 # Using new OpenAI API
15
  tiktoken>=0.5.0 # Token counting for cost optimization
16
  Flask-SQLAlchemy==3.1.1
 
17
  Flask-Login==0.6.3
18
  Flask-WTF==1.2.1
19
  Flask-Migrate==4.0.7
start.sh CHANGED
@@ -17,47 +17,12 @@ fi
17
  echo "Initializing database..."
18
  python -c "
19
  from web_app import create_app
20
- from web_app.models import db, User
21
- from config import Config
22
- from sqlalchemy import text
23
-
24
- print(f'SECRET_KEY set: {bool(Config.SECRET_KEY)}')
25
- print(f'IS_PRODUCTION: {Config.IS_PRODUCTION}')
26
- print(f'SESSION_COOKIE_SECURE: {Config.SESSION_COOKIE_SECURE}')
27
- print(f'Database URI: {Config.SQLALCHEMY_DATABASE_URI[:50]}...')
28
 
29
  app = create_app()
30
  with app.app_context():
31
- try:
32
- # Try to query users table - if this works, DB is fine
33
- user_count = User.query.count()
34
- print(f'✅ Database working ({user_count} users)')
35
- except Exception as check_error:
36
- print(f'Database needs setup: {str(check_error)[:100]}')
37
-
38
- # Nuclear option: drop and recreate entire public schema
39
- try:
40
- print('Performing complete database reset...')
41
- with db.engine.connect() as conn:
42
- conn.execute(text('DROP SCHEMA public CASCADE'))
43
- conn.commit()
44
- print(' Schema dropped')
45
-
46
- conn.execute(text('CREATE SCHEMA public'))
47
- conn.commit()
48
- print(' Schema recreated')
49
-
50
- # Now create all tables
51
- db.create_all()
52
- print('✅ Database schema created successfully!')
53
-
54
- # Verify it works
55
- user_count = User.query.count()
56
- print(f'✅ Verified: Database has {user_count} users')
57
-
58
- except Exception as create_error:
59
- print(f'❌ Database reset failed: {create_error}')
60
- raise
61
  "
62
 
63
  echo "Starting gunicorn server..."
 
17
  echo "Initializing database..."
18
  python -c "
19
  from web_app import create_app
20
+ from web_app.models import db
 
 
 
 
 
 
 
21
 
22
  app = create_app()
23
  with app.app_context():
24
+ db.create_all()
25
+ print('✅ Database initialized')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  "
27
 
28
  echo "Starting gunicorn server..."