From ebd3493459ab72db01e8727ba7aa0bb80f6b141b Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 1 Jul 2026 12:22:14 +0530 Subject: [PATCH 1/2] Fix deployment startup issues (psycopg2, postgres:// URI, and auto migration) --- backend/app/__init__.py | 17 +++++++---------- backend/app/config.py | 7 ++++++- backend/requirements.txt | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 879e685..2e2b307 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -54,16 +54,13 @@ 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..02f868c 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 From d0763d234fce59b8539e1327f86f85182b09203d Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 1 Jul 2026 12:30:54 +0530 Subject: [PATCH 2/2] Fix python formatting for black/flake8 checks --- backend/app/__init__.py | 1 + backend/app/config.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 2e2b307..98fb323 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -57,6 +57,7 @@ def create_app(env=None): # 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: diff --git a/backend/app/config.py b/backend/app/config.py index 02f868c..727291c 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -75,11 +75,11 @@ class ProductionConfig(Config): """Production Configuration.""" DEBUG = False - + 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"