Auto-stamp or migrate on startup
On boot, run_migrations() checks the Alembic revision: - no revision + tables exist → stamp head (db.sql was run manually) - no revision + no tables → upgrade head (fresh install) - revision present → upgrade head (no-op if already current) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.db import check_db
|
||||
from app.db import check_db, run_migrations
|
||||
from app.routers import filaments, pricing, print_jobs, printers, todos
|
||||
|
||||
logger = logging.getLogger("pops")
|
||||
@@ -14,6 +14,7 @@ async def lifespan(app: FastAPI):
|
||||
ok, msg = check_db()
|
||||
if ok:
|
||||
logger.info("Database connection OK")
|
||||
run_migrations()
|
||||
else:
|
||||
logger.warning("Database unreachable: %s", msg)
|
||||
yield
|
||||
|
||||
Reference in New Issue
Block a user