Jesse
Jesse

Reputation: 2208

How to detect changes with alembic without creating a revision?

I'm trying to abstract some functionality from my models into a Mixin, and I don't actually want to change any tables — I just want to check to make sure I've done this correctly.

How can I see what changes alembic detects without creating a revisions file? Or is my only option to run alembic revision --autogenerate -m "...", then delete the file?

Upvotes: 3

Views: 2965

Answers (2)

huie81
huie81

Reputation: 1

In my case

def run_migrations():
    alembic_cfg = Config("alembic.ini")
    try:
        command.check(alembic_cfg)
        print("No changes detected.")
        return
    except AutogenerateDiffsDetected as e:
        command.revision(alembic_cfg, "head", autogenerate=True)
        command.upgrade(alembic_cfg, "head")

Upvotes: 0

bmakan
bmakan

Reputation: 441

Alembic v1.9.0 (https://alembic.sqlalchemy.org/en/latest/changelog.html#change-1.9.0) introduced a new check command:

Added new Alembic command alembic check. This performs the widely requested feature of running an “autogenerate” comparison between the current database and the MetaData that’s currently set up for autogenerate, returning an error code if the two do not match, based on current autogenerate settings. Pull request courtesy Nathan Louie.

Upvotes: 7

Related Questions