Conversation
#166) The hardcoded list in `_run_schema_migrations` only added a handful of User columns, so a pre-Flask-Migrate database upgrading past v0.20.0 still booted into a `no such column: users.default_vehicle_id` worker crash (issue #166). Walk `db.metadata` instead and add every model column the live schema is missing — recovery now stays in lockstep with the models even when new columns land without a hand-written entry. Also add a startup banner ("May <version> starting (alembic_version=...)") so future bug reports identify the running image without needing `docker exec ... cat config.py`. - Bump APP_VERSION to 0.22.1 - Add tests/test_schema_recovery.py covering the regression
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
_run_schema_migrationswith a walk overdb.metadata, so every model column missing from the live DB is added automatically. The old list misseddefault_vehicle_id,show_menu_*,start_page,api_key, etc., which left users on pre-Flask-Migrate databases unable to boot after upgrading past v0.20.0 (issue WORKER_BOOT_ERROR - Docker Image #166).May <version> starting (alembic_version=...)— so future upgrade reports identify the running image immediately.tests/test_schema_recovery.pyexercise the legacy DB → boot path that issue WORKER_BOOT_ERROR - Docker Image #166 surfaced.Why this happened
a1b2c3d4e5f6(default_vehicle_id) had a migration but it ran viaflask db upgrade. For databases predating Flask-Migrate, alembic_version was empty and the upgrade replayed migrations from scratch, hitting a duplicate-column failure onodometer_unitand bailing before addingdefault_vehicle_id. The bootstrap stamp in v0.21.0 fixed that fordefault_vehicle_id, but every column added since (show_menu_*,show_quick_entry, etc.) had to be re-added by hand to_run_schema_migrations. Going model-driven removes the maintenance burden — adding a column to a model is now sufficient.Test plan
pytest tests/test_schema_recovery.py— 4 new tests passpytest tests/— 555 passedUser.query.count()works after recovery (defaults applied, FK column added)