Skip to content
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

Keep the unique flag in DropIndexOp #1372

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions alembic/operations/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ def from_index(cls, index: Index) -> DropIndexOp:
table_name=index.table.name,
schema=index.table.schema,
_reverse=CreateIndexOp.from_index(index),
unique=index.unique,
**index.kwargs,
)

Expand Down
6 changes: 6 additions & 0 deletions docs/build/unreleased/1371.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. change::
:tags: bug, autogenerate
:tickets: 1370

Fixed issue with downgrade migration of unique indexes autogenerating
non-unique indexes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add "pull request courtesy of you" if you like

9 changes: 9 additions & 0 deletions tests/test_autogen_diffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@ def setUp(self):
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
Expand Down Expand Up @@ -1905,6 +1906,14 @@ def test_create_index(self):
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):
Expand Down