fix(startup): stop re-migrating on every container restart
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 48s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m13s
Build and Push Docker Images / Build Integrator (push) Successful in 58s
Build and Push Docker Images / Build Kestra Init (push) Successful in 35s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 48s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m13s
Build and Push Docker Images / Build Integrator (push) Successful in 58s
Build and Push Docker Images / Build Kestra Init (push) Successful in 35s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
Two issues caused the backend to drop and reimport school data on restart: 1. schema_version table was in the drop list inside run_full_migration(), so after any migration the breadcrumb was destroyed and the next restart would see no version → re-trigger migration 2. Schema version was set after migration, so a crash mid-migration left no version → infinite re-migration loop Fix: remove schema_version from the drop list, and set the version before running migration so crashes don't cause loops. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -128,17 +128,17 @@ def check_and_migrate_if_needed():
|
||||
print("Running full migration...")
|
||||
|
||||
try:
|
||||
# Set schema version BEFORE migration so a crash mid-migration
|
||||
# doesn't cause an infinite re-migration loop on every restart.
|
||||
init_db()
|
||||
set_db_schema_version(SCHEMA_VERSION)
|
||||
|
||||
success = run_full_migration(geocode=False)
|
||||
|
||||
if success:
|
||||
# Ensure schema_version table exists before writing
|
||||
init_db()
|
||||
set_db_schema_version(SCHEMA_VERSION)
|
||||
print(f"Migration complete. Schema version set to {SCHEMA_VERSION}")
|
||||
print(f"Migration complete. Schema version {SCHEMA_VERSION}.")
|
||||
else:
|
||||
print("Warning: Migration completed but no data was imported.")
|
||||
init_db()
|
||||
set_db_schema_version(SCHEMA_VERSION)
|
||||
|
||||
except Exception as e:
|
||||
print(f"FATAL: Migration failed: {e}")
|
||||
|
||||
Reference in New Issue
Block a user