diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 879e685..98fb323 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -54,16 +54,14 @@ def create_app(env=None): # ── Development safety: ensure base tables exist ─────────────────────── # If a local DB is created in a partially migrated state, endpoints like - # login will crash with "no such table". For development only, auto-create - # tables when the critical `users` table is missing. - if env in ("development", "testing"): - with app.app_context(): - from . import models # noqa: F401 - - try: - db.create_all() - except Exception as e: - app.logger.error(f"Auto-migration failed: {str(e)}") + # login will crash with "no such table". Auto-create missing tables. + with app.app_context(): + from . import models # noqa: F401 + + try: + db.create_all() + except Exception as e: + app.logger.error(f"Auto-migration failed: {str(e)}") # ── Blueprints ──────────────────────────────────────────────────────────── from .routes.auth import auth_bp diff --git a/backend/app/config.py b/backend/app/config.py index 5b29382..727291c 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -75,7 +75,12 @@ class ProductionConfig(Config): """Production Configuration.""" DEBUG = False - SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or "sqlite:///production.db" + + db_url = os.environ.get("DATABASE_URL") + if db_url and db_url.startswith("postgres://"): + db_url = db_url.replace("postgres://", "postgresql://", 1) + + SQLALCHEMY_DATABASE_URI = db_url or "sqlite:///production.db" config = { diff --git a/backend/requirements.txt b/backend/requirements.txt index 2ec0f5e..2ccf0f3 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -54,3 +54,4 @@ urllib3==2.6.3 Werkzeug==3.1.5 wsproto==1.3.2 yarg==0.1.10 +psycopg2-binary==2.9.9