]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Keep the unique flag in `DropIndexOp`
authorIuri de Silvio <iuri.desilvio@channable.com>
Mon, 4 Dec 2023 18:22:22 +0000 (13:22 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 6 Dec 2023 21:13:33 +0000 (16:13 -0500)
Fixed issue where the "unique" flag of an ``Index`` would not be maintained
when generating downgrade migrations.  Pull request courtesy Iuri de
Silvio.

Fixes: #1371
Closes: #1372
Pull-request: https://github.com/sqlalchemy/alembic/pull/1372
Pull-request-sha: 515b4ed049048d4f5d178ed1777018d5e0c34968

Change-Id: Id4ff7212e2738f2b38ba0a9a8f12bccdc1796b55

alembic/operations/ops.py
docs/build/unreleased/1371.rst [new file with mode: 0644]
tests/test_autogen_diffs.py

index 8bedcd87825ce4089fb76866d9b84fa7090babc1..07b3e5749bd2a06d14c40935d5aac152e67b6618 100644 (file)
@@ -1054,6 +1054,7 @@ class DropIndexOp(MigrateOperation):
             table_name=index.table.name,
             schema=index.table.schema,
             _reverse=CreateIndexOp.from_index(index),
+            unique=index.unique,
             **index.kwargs,
         )
 
diff --git a/docs/build/unreleased/1371.rst b/docs/build/unreleased/1371.rst
new file mode 100644 (file)
index 0000000..b0ffdf5
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, autogenerate
+    :tickets: 1370
+
+    Fixed issue where the "unique" flag of an ``Index`` would not be maintained
+    when generating downgrade migrations.  Pull request courtesy Iuri de
+    Silvio.
index 197bf39a240e03105be88db3a52a482159cb418a..b0490f9e76f109cf302f93380656a1f1fb8406b3 100644 (file)
@@ -1783,6 +1783,7 @@ class OrigObjectTest(TestBase):
             Column("x", Integer()),
         )
         self.ix = Index("ix1", t.c.id)
+        self.ix_unique = Index("ix2", t.c.id, unique=True)
         fk = ForeignKeyConstraint(["t_id"], ["t.id"])
         q = Table("q", m, Column("t_id", Integer()), fk)
         self.table = t
@@ -1905,6 +1906,14 @@ class OrigObjectTest(TestBase):
         eq_(op.to_index(), schemacompare.CompareIndex(self.ix))
         eq_(op.reverse().to_index(), schemacompare.CompareIndex(self.ix))
 
+    def test_create_unique_index(self):
+        op = ops.CreateIndexOp.from_index(self.ix_unique)
+        eq_(op.to_index(), schemacompare.CompareIndex(self.ix_unique))
+        eq_(
+            op.reverse().to_index(),
+            schemacompare.CompareIndex(self.ix_unique),
+        )
+
 
 class MultipleMetaDataTest(AutogenFixtureTest, TestBase):
     def test_multiple(self):