Issues

Issue #77 resolved

hard coded 'alembic_version' in _produce_net_changes of autogenerate.py

Christian Blume
created an issue

Can we get rid of hard coded 'alembic_version' table name in _produce_net_changes() of autogenerate.py? This has implications for autogeneration of table migrations. Though, I am not sure how to fix this. Any ideas?

Comments (4)

  1. Mike Bayer repo owner

    it would have to derive from the name given up in the Environment, shouldn't be hard. you can see the "# TODO" comment in _produce_net_changes() to that effect.

    this unfortunately has no unit tests that affirm it either, would have to do that too:

    diff -r 03481917469dde2be467c352232cc38999c50507 alembic/autogenerate.py
    --- a/alembic/autogenerate.py	Mon Oct 01 17:12:03 2012 -0400
    +++ b/alembic/autogenerate.py	Fri Oct 05 10:41:33 2012 -0400
    @@ -139,7 +139,9 @@
             'connection': connection,
             'dialect': connection.dialect,
             'context': context,
    -        'opts': opts
    +        'opts': opts,
    +        'alembic_version': context._version.name,
    +        'alembic_version_schema': context._version.schema
         }, connection
     
     def _indent(text):
    @@ -156,7 +158,7 @@
                                 include_symbol=None,
                                 include_schemas=False):
         inspector = Inspector.from_engine(connection)
    -    # TODO: not hardcode alembic_version here ?
    +
         conn_table_names = set()
         if include_schemas:
             schemas = set(inspector.get_schema_names())
    @@ -169,8 +171,11 @@
             schemas = [None]
     
         for s in schemas:
    -        tables = set(inspector.get_table_names(schema=s)).\
    -                difference(['alembic_version'])
    +        tables = set(inspector.get_table_names(schema=s))
    +
    +        if s == autogen_context.get('alembic_version_schema'):
    +            tables = tables.difference(
    +                [autogen_context.get('alembic_version', 'alembic_version')])
             conn_table_names.update(zip([s] * len(tables), tables))
     
         metadata_table_names = OrderedSet([(table.schema, table.name)
    
  2. Mike Bayer repo owner
    • If the "alembic_version" table is present in the target metadata, autogenerate will skip this also. Pull request courtesy Dj Gilcrease. fixes #28
    • The :paramref:.EnvironmentContext.configure.version_table and :paramref:.EnvironmentContext.configure.version_table_schema arguments are now honored during the autogenerate process, such that these names will be used as the "skip" names on both the database reflection and target metadata sides. fixes #77

    → <<cset 9650ccfb6841>>

  3. Log in to comment