]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Fixed bug where the ``include_object()`` filter would not receive
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Apr 2014 22:28:49 +0000 (18:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Apr 2014 22:28:49 +0000 (18:28 -0400)
the original :class:`.Column` object when evaluating a database-only
column to be dropped; the object would not include the parent
:class:`.Table` nor other aspects of the column that are important
for generating the "downgrade" case where the column is recreated.
fixes #200

alembic/autogenerate/compare.py
docs/build/changelog.rst
tests/test_autogenerate.py

index cfa110ac93a31d8c4be58d48f0ade1358c3cc144..ec077fdd3b98cff3b694f6cf78b236cdfbfa7de1 100644 (file)
@@ -127,16 +127,10 @@ def _compare_columns(schema, tname, object_filters, conn_table, metadata_table,
             log.info("Detected added column '%s.%s'", name, cname)
 
     for cname in set(conn_col_names).difference(metadata_col_names):
-        rem_col = sa_schema.Column(
-                    cname,
-                    conn_table.c[cname].type,
-                    nullable=conn_table.c[cname].nullable,
-                    server_default=conn_table.c[cname].server_default
-                )
-        if _run_filters(rem_col, cname,
+        if _run_filters(conn_table.c[cname], cname,
                                 "column", True, None, object_filters):
             diffs.append(
-                ("remove_column", schema, tname, rem_col)
+                ("remove_column", schema, tname, conn_table.c[cname])
             )
             log.info("Detected removed column '%s.%s'", name, cname)
 
index a6cefc6fcb13df4fa6edbd7f1bbd1cbe3f9ded9d..d4ccb33b758a531efa85aa3ec76603c67a97f870 100644 (file)
@@ -5,6 +5,16 @@ Changelog
 .. changelog::
     :version: 0.6.5
 
+    .. change::
+      :tags: bug, autogenerate
+      :tickets: 200
+
+      Fixed bug where the ``include_object()`` filter would not receive
+      the original :class:`.Column` object when evaluating a database-only
+      column to be dropped; the object would not include the parent
+      :class:`.Table` nor other aspects of the column that are important
+      for generating the "downgrade" case where the column is recreated.
+
     .. change::
       :tags: bug, environment
       :tickets: 195
index 34875db68029416d6a226db82930904bdf9985da..5e9b1e7b5335c75f15eb0d87736833e3c13f2e86 100644 (file)
@@ -519,7 +519,7 @@ class AutogenerateDiffTest(ModelOne, AutogenTest, TestCase):
                     assert obj.metadata is not self.m2
                 else:
                     assert obj.metadata is self.m2
-                return name in ("address", "order")
+                return name in ("address", "order", "user")
             elif type_ == "column":
                 if reflected:
                     assert obj.table.metadata is not self.m2
@@ -529,7 +529,6 @@ class AutogenerateDiffTest(ModelOne, AutogenTest, TestCase):
             else:
                 return True
 
-
         context = MigrationContext.configure(
             connection=self.bind.connect(),
             opts={
@@ -545,12 +544,15 @@ class AutogenerateDiffTest(ModelOne, AutogenTest, TestCase):
         )
         template_args = {}
         autogenerate._produce_migration_diffs(context, template_args, set())
+
         template_args['upgrades'] = template_args['upgrades'].replace("u'", "'")
         template_args['downgrades'] = template_args['downgrades'].\
                                         replace("u'", "'")
+        assert "op.create_table('item'" not in template_args['upgrades']
+        assert "op.create_table('item'" not in template_args['downgrades']
 
-        assert "alter_column('user'" not in template_args['upgrades']
-        assert "alter_column('user'" not in template_args['downgrades']
+        assert "alter_column('user'" in template_args['upgrades']
+        assert "alter_column('user'" in template_args['downgrades']
         assert "'street'" not in template_args['upgrades']
         assert "'street'" not in template_args['downgrades']
         assert "alter_column('order'" in template_args['upgrades']
@@ -743,7 +745,7 @@ class AutogenerateDiffTestWSchema(ModelOne, AutogenTest, TestCase):
                server_default=None,
                existing_nullable=True,
                schema='%(schema)s')
-    op.add_column('user', sa.Column('pw', sa.VARCHAR(length=50), nullable=True), schema='%(schema)s')
+    op.add_column('user', sa.Column('pw', sa.VARCHAR(length=50), autoincrement=False, nullable=True), schema='%(schema)s')
     op.alter_column('order', 'amount',
                existing_type=sa.Numeric(precision=10, scale=2),
                type_=sa.NUMERIC(precision=8, scale=2),