Seed kitchens id=1 on startup to satisfy kitchen_settings FK
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 <noreply@anthropic.com>
This commit is contained in:
parent
9905d0e0dd
commit
14903e80a6
1 changed files with 4 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ from contextlib import asynccontextmanager
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
from sqlalchemy import text
|
||||||
from database import engine, Base
|
from database import engine, Base
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|
@ -88,6 +89,9 @@ async def _run(name, coro):
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
async with engine.begin() as conn:
|
async with engine.begin() as conn:
|
||||||
await conn.run_sync(Base.metadata.create_all)
|
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("Invoice features", run_migration)
|
||||||
await _run("Newbook tables", run_newbook_migration)
|
await _run("Newbook tables", run_newbook_migration)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue