1. Michael Bayer
  2. alembic
  3. Issues

Issues

Issue #80 resolved

autogenerate should have an option to skip file creation when no changes are detected

Robert Kopaczewski
created an issue

Currently, even if no changes are detected, migration file is created.

This shouldn't be default behavior for autogenerate or at least it should be possible to change it as a environemnt setting.

Comments (7)

  1. Michael Bayer repo owner

    This is the default behavior because autogenerate only generates candidate migrations that have been detected. It is always necessary for the user to edit the file in order to add other migrations that cannot be auto-detected and to correct those migrations that were rendered incorrectly.

    autogenerate is only a code generation helper, not an encapsulated auto-upgrade tool.

  2. Robert Kopaczewski reporter

    I do get it but in some cases it is good enough for auto-upgrade tool.

    I just with there could be a flag or a callback so that one can do this "if no changes detected, skip generation" scenario.

    Currently no such way exists.

  3. Michael Bayer repo owner

    put this in your env.py:

    def process_revision_directives(context, revision, directives):
        script = directives[0]
        if script.upgrade_ops.is_empty():
            directives[:] = []
    

    then in run_migrations_online:

        with connectable.connect() as connection:
            context.configure(
                connection=connection,
                target_metadata=target_metadata,
                process_revision_directives=process_revision_directives
            )
    
            with context.begin_transaction():
                context.run_migrations()
    

    docs:

    http://alembic.readthedocs.org/en/latest/api/autogenerate.html#customizing-revision-generation

  4. Log in to comment