New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hard coded 'alembic_version' in _produce_net_changes of autogenerate.py #77

Closed
sqlalchemy-bot opened this Issue Oct 5, 2012 · 5 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Oct 5, 2012

Migrated issue, originally created by Christian Blume (@cblume)

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?

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 5, 2012

Michael Bayer (@zzzeek) wrote:

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

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)
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jun 7, 2013

Changes by Michael Bayer (@zzzeek):

  • added labels: autogenerate - detection
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Aug 3, 2014

Michael Bayer (@zzzeek) wrote:

Issue #220 was marked as a duplicate of this issue.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2014

Michael Bayer (@zzzeek) wrote:

  • 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

9650ccf

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2014

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment