Repository navigation
fix(migrations): raise on failure, track applied migrations, schema health check (#236) - #239
Merged
Merged
Conversation
…ealth check - Replace silent print+continue with logger.error + raise so backend refuses to start with an inconsistent schema - Add schema_migrations tracking table (PRIMARY KEY) to skip already-applied migrations and prevent multi-worker race conditions (INSERT OR IGNORE) - Fresh-install "no such table" errors are gracefully skipped so init_schema can create tables with the correct current schema - /health endpoint returns 503 with migration counts when schema is incomplete - 16 unit tests covering tracking, idempotency, failure propagation, and concurrent-write safety Closes #236 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ccurate health check On first startup, migrations whose target table doesn't exist yet are skipped-but-not-recorded. init_schema then creates the tables correctly, but the health check's COUNT(*) < len(MIGRATIONS) would return 503 indefinitely. A second run_all_migrations call after init_schema re-runs those skips as no-ops (all migrations guard with PRAGMA table_info) and records them, keeping /health accurate on fresh installs. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
print+continueinrun_all_migrationswithlogger.error + raiseso the backend refuses to start with an inconsistent schemaschema_migrationstracking table (PRIMARY KEY) to skip already-applied migrations and prevent multi-worker race conditions viaINSERT OR IGNOREno such tableerrors are gracefully skipped —init_schemawill create the table with the correct current schemaGET /healthreturns 503 with{applied, expected}counts when migrations are incompleteChanges
src/backend/db/migrations.py— rewrittenrun_all_migrations, addedMIGRATIONSmodule-level constantsrc/backend/main.py— health check schema consistency, module-level loggertests/unit/test_migrations.py— 16 new unit tests (tracking, idempotency, failure propagation, concurrent-write safety)Test Plan
pytest tests/unit/test_migrations.py -vINSERT OR IGNORErace condition test passesno such tableskip test passes/healthreturns{"status": "healthy"}with migrations appliedCloses #236
🤖 Generated with Claude Code