]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Fixed bug whereby create_index()
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 16 Feb 2013 01:20:50 +0000 (20:20 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 16 Feb 2013 01:20:50 +0000 (20:20 -0500)
would include in the constraint columns that
are added to all Table objects using events,
externally to the generation of the constraint.
This is the same issue that was fixed for unique
constraints in version 0.3.2.

alembic/operations.py
docs/build/changelog.rst
tests/test_op.py

index f5640c5b38e56ed85d6b946c61be3e9aa7115b95..f97ec6e67a3f2a21e2f5df9c6a4e58543b29085e 100644 (file)
@@ -113,7 +113,7 @@ class Operations(object):
             *[sa_schema.Column(n, NULLTYPE) for n in columns],
             schema=schema
         )
-        return sa_schema.Index(name, *list(t.c), **kw)
+        return sa_schema.Index(name, *[t.c[n] for n in columns], **kw)
 
     def _parse_table_key(self, table_key):
         if '.' in table_key:
index f092c50e42fc9860d688433770270a9de83c7c54..f3ee4a6dd1e20d590530b285ee010a9932bf6233 100644 (file)
@@ -6,6 +6,16 @@ Changelog
 .. changelog::
     :version: 0.5.0
 
+    .. change::
+        :tags: bug
+
+      Fixed bug whereby create_index()
+      would include in the constraint columns that
+      are added to all Table objects using events,
+      externally to the generation of the constraint.
+      This is the same issue that was fixed for unique
+      constraints in version 0.3.2.
+
     .. change::
         :tags: bug
         :pullreq: 27
index 438a54763b69fe72c70df65c7463782cf8bee53a..d5a6abe9696133df54cf2320212788bf16f39d70 100644 (file)
@@ -6,6 +6,12 @@ from sqlalchemy import Integer, Column, ForeignKey, \
             Table, String, Boolean
 from sqlalchemy.sql import column, func
 
+from sqlalchemy import event
+@event.listens_for(Table, "after_parent_attach")
+def _add_cols(table, metadata):
+    if table.name == "tbl_with_auto_appended_column":
+        table.append_column(Column('bat', Integer))
+
 
 def test_rename_table():
     context = op_fixture()
@@ -405,21 +411,6 @@ def test_add_unique_constraint_schema():
         "ALTER TABLE foo.t1 ADD CONSTRAINT uk_test UNIQUE (foo, bar)"
     )
 
-def test_add_unique_constraint_auto_cols():
-    context = op_fixture()
-    from sqlalchemy import event, DateTime
-
-    @event.listens_for(Table, "after_parent_attach")
-    def _table_standard_cols(table, metadata):
-        table.append_column(Column('created_at', DateTime))
-
-    try:
-        op.create_unique_constraint('uk_test', 't1', ['foo', 'bar'])
-        context.assert_(
-            "ALTER TABLE t1 ADD CONSTRAINT uk_test UNIQUE (foo, bar)"
-        )
-    finally:
-        Table.dispatch._clear()
 
 def test_drop_constraint():
     context = op_fixture()
@@ -442,6 +433,25 @@ def test_create_index():
         "CREATE INDEX ik_test ON t1 (foo, bar)"
     )
 
+
+def test_create_index_table_col_event():
+    context = op_fixture()
+
+    op.create_index('ik_test', 'tbl_with_auto_appended_column', ['foo', 'bar'])
+    context.assert_(
+        "CREATE INDEX ik_test ON tbl_with_auto_appended_column (foo, bar)"
+    )
+
+def test_add_unique_constraint_col_event():
+    context = op_fixture()
+    op.create_unique_constraint('ik_test',
+            'tbl_with_auto_appended_column', ['foo', 'bar'])
+    context.assert_(
+        "ALTER TABLE tbl_with_auto_appended_column "
+        "ADD CONSTRAINT ik_test UNIQUE (foo, bar)"
+    )
+
+
 def test_create_index_schema():
     context = op_fixture()
     op.create_index('ik_test', 't1', ['foo', 'bar'], schema='foo')