From 14903e80a68de64f2494ca5f83a1ea14186536f5 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Sun, 12 Jul 2026 16:38:47 +0000 Subject: [PATCH] Seed kitchens id=1 on startup to satisfy kitchen_settings FK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kitchen_settings has a FK to kitchens.id — on a fresh kitchen_db the kitchens table is empty, so any restore attempt fails with a FK violation. Idempotent INSERT ON CONFLICT DO NOTHING runs after create_all on every boot. Co-Authored-By: Claude Sonnet 4.6 --- backend/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/main.py b/backend/main.py index 7c02262..f682081 100644 --- a/backend/main.py +++ b/backend/main.py @@ -3,6 +3,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI +from sqlalchemy import text from database import engine, Base logging.basicConfig( @@ -88,6 +89,9 @@ async def _run(name, coro): async def lifespan(app: FastAPI): async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) + await conn.execute( + text("INSERT INTO kitchens (id, name, created_at) VALUES (1, 'Hotel Number Four', NOW()) ON CONFLICT DO NOTHING") + ) await _run("Invoice features", run_migration) await _run("Newbook tables", run_newbook_migration)