Conversation
Containers upgrading from v0.15.0/v0.16.0 failed to start because the a1b2c3d4e5f6 migration never ran: alembic_version was empty on those DBs, so flask db upgrade replayed migrations from scratch and died on a duplicate odometer_unit column, leaving users.default_vehicle_id missing and create_app() crashing in User.query.count(). - Make the three pre-trip-templates migrations idempotent so they no-op when the column/nullability they add already exists. - Add _bootstrap_alembic_version to stamp the correct revision when the DB has tables but no alembic row, so subsequent upgrades only apply pending migrations. - Extend _run_schema_migrations with default_vehicle_id as a safety net so the app boots even if alembic state cannot be recovered. - Stop silencing flask db upgrade failures in the entrypoint — a real upgrade error should be visible in container logs. Bumps version to 0.18.1.
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
Resolves issues #132 and #136 — containers crashing after upgrade with
sqlite3.OperationalError: no such column: users.default_vehicle_id.Root cause
Databases created on v0.15.0 or earlier predate Flask-Migrate, so their
alembic_versiontable is empty. The entrypoint'sflask db upgradethen tried to replay every migration from the beginning and died on aduplicate column: odometer_uniterror. The failure was silenced by2>/dev/null || true, so thea1b2c3d4e5f6migration that addsusers.default_vehicle_idnever ran, andcreate_app()then crashed inUser.query.count().Changes
998cdb1497c6,613be8af4376, anda1b2c3d4e5f6now no-op when their target column/nullability is already in place, soflask db upgradesucceeds even on a DB that was bootstrapped without Flask-Migrate._bootstrap_alembic_versionstamps the correct prior revision when the database has tables but no alembic row, so future upgrades only apply genuinely pending migrations._run_schema_migrationsnow also addsusers.default_vehicle_id, guaranteeing the app can boot even if alembic state can't be recovered.docker-entrypoint.shno longer swallowsflask db upgradefailures; any remaining error surfaces in container logs.APP_VERSIONto0.18.1.Test plan
flask db upgradecompletes cleanly,alembic_versionlands at head (b2c3d4e5f6a7),users.default_vehicle_idis present, app boots,User.query.count()returns without error