Skip to content

Instantly share code, notes, and snippets.

@saulin18
Forked from m-aciek/check.py
Created March 9, 2026 16:40
Show Gist options
  • Select an option

  • Save saulin18/28cd2da616c43aa0ba36ecfd2064b830 to your computer and use it in GitHub Desktop.

Select an option

Save saulin18/28cd2da616c43aa0ba36ecfd2064b830 to your computer and use it in GitHub Desktop.
Alembic database freshness check.
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