-
-
Save saulin18/28cd2da616c43aa0ba36ecfd2064b830 to your computer and use it in GitHub Desktop.
Alembic database freshness check.
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
| from alembic import config | |
| from alembic import script | |
| from alembic.runtime import migration | |
| import sqlalchemy | |
| import exceptions | |
| engine = sqlalchemy.create_engine(DATABASE_URL) | |
| alembic_cfg = config.Config('alembic.ini') | |
| script_ = script.ScriptDirectory.from_config(alembic_cfg) | |
| with engine.begin() as conn: | |
| context = migration.MigrationContext.configure(conn) | |
| if context.get_current_revision() != script_.get_current_head(): | |
| raise exceptions.DatabaseIsNotUpToDate('Upgrade the database.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment