diff --git a/backend/main.py b/backend/main.py index 730665f..ec21ad1 100644 --- a/backend/main.py +++ b/backend/main.py @@ -43,7 +43,11 @@ AVATAR_COLORS = ['#1D9E75','#378ADD','#D85A30','#EF9F27','#7F77DD','#D4537E','#6 @app.on_event("startup") async def startup_event(): """Run migrations and initialization on startup.""" - init_db() + try: + init_db() + except Exception as e: + print(f"⚠️ init_db() failed (non-fatal): {e}") + # Don't crash on startup - pipeline prompt can be created manually def init_db(): """Initialize database - Schema is loaded by startup.sh""" @@ -51,23 +55,39 @@ def init_db(): # This function kept for backwards compatibility # Ensure "pipeline" master prompt exists - with get_db() as conn: - cur = get_cursor(conn) - cur.execute("SELECT COUNT(*) as count FROM ai_prompts WHERE slug='pipeline'") - if cur.fetchone()['count'] == 0: + try: + with get_db() as conn: + cur = get_cursor(conn) + # Check if table exists first cur.execute(""" - INSERT INTO ai_prompts (slug, name, description, template, active, sort_order) - VALUES ( - 'pipeline', - 'Mehrstufige Gesamtanalyse', - 'Master-Schalter für die gesamte Pipeline. Deaktiviere diese Analyse, um die Pipeline komplett zu verstecken.', - 'PIPELINE_MASTER', - true, - -10 - ) + SELECT EXISTS ( + SELECT FROM information_schema.tables + WHERE table_schema = 'public' + AND table_name = 'ai_prompts' + ) as table_exists """) - conn.commit() - print("✓ Pipeline master prompt created") + if not cur.fetchone()['table_exists']: + print("⚠️ ai_prompts table doesn't exist yet - skipping pipeline prompt creation") + return + + cur.execute("SELECT COUNT(*) as count FROM ai_prompts WHERE slug='pipeline'") + if cur.fetchone()['count'] == 0: + cur.execute(""" + INSERT INTO ai_prompts (slug, name, description, template, active, sort_order) + VALUES ( + 'pipeline', + 'Mehrstufige Gesamtanalyse', + 'Master-Schalter für die gesamte Pipeline. Deaktiviere diese Analyse, um die Pipeline komplett zu verstecken.', + 'PIPELINE_MASTER', + true, + -10 + ) + """) + conn.commit() + print("✓ Pipeline master prompt created") + except Exception as e: + print(f"⚠️ Could not create pipeline prompt: {e}") + # Don't fail startup - prompt can be created manually # ── Helper: get profile_id from header ─────────────────────────────────────── def get_pid(x_profile_id: Optional[str] = Header(default=None)) -> str: diff --git a/docker-compose.yml b/docker-compose.yml index 77ef9ed..c83c224 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: postgres: image: postgres:16-alpine - container_name: mitai-db + container_name: mitai-db-prod restart: unless-stopped environment: POSTGRES_DB: mitai_prod @@ -9,8 +9,6 @@ services: POSTGRES_PASSWORD: ${DB_PASSWORD:-change_me_in_production} volumes: - mitai_postgres_data:/var/lib/postgresql/data - ports: - - "127.0.0.1:5432:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U mitai_prod"] interval: 10s