Skip to content

fix: model-driven schema recovery for upgrade failures (#166)#167

Merged
dannymcc merged 1 commit intomainfrom
dev
May 3, 2026
Merged

fix: model-driven schema recovery for upgrade failures (#166)#167
dannymcc merged 1 commit intomainfrom
dev

Conversation

@dannymcc
Copy link
Copy Markdown
Owner

@dannymcc dannymcc commented May 3, 2026

Summary

  • Replace hardcoded column list in _run_schema_migrations with a walk over db.metadata, so every model column missing from the live DB is added automatically. The old list missed default_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).
  • Add a startup banner — May <version> starting (alembic_version=...) — so future upgrade reports identify the running image immediately.
  • Bump version to 0.22.1.
  • New regression tests in tests/test_schema_recovery.py exercise 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 via flask db upgrade. For databases predating Flask-Migrate, alembic_version was empty and the upgrade replayed migrations from scratch, hitting a duplicate-column failure on odometer_unit and bailing before adding default_vehicle_id. The bootstrap stamp in v0.21.0 fixed that for default_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 pass
  • Full pytest tests/ — 555 passed
  • Manual: built a v0.18-shaped DB and confirmed User.query.count() works after recovery (defaults applied, FK column added)
  • Manual: fresh-install path still works

#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
@dannymcc dannymcc merged commit bea9374 into main May 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant