summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-06-02 13:52:27 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-02 13:54:07 -0400
commitafb466fb8bd9c2f8709e79fd0fce422b83ff1d6b (patch)
tree651408218157fb0ef6e75af278b4f0d1135eb177 /test/sql
parent7a4aa46ae49f3ddcdadd4f3f10ef9cbce1fbf9aa (diff)
downloadsqlalchemy-afb466fb8bd9c2f8709e79fd0fce422b83ff1d6b.tar.gz
Skip UniqueConstraint marked by unique=True in tometadata
Fixes an issue where a Column would be copied with unique=True and at the same time the UniqueConstraint would also be copied, leading to duplicate UniqueConstraints in the target table, when tometadata() is used. Imitates the same logic used by index=True/Index to avoid duplicates. For some reason a fix was implemented for Index long ago but never for UniqueConstraint. Change-Id: Ie622ee912a6fb8bf0ea900a8b09d78c7ebc79fc0 Fixes: #3721
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_metadata.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 449956fcd..344cfefa5 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -1113,6 +1113,34 @@ class ToMetaDataTest(fixtures.TestBase, ComparesTables):
eq_(str(table_c.join(table2_c).onclause),
'mytable.myid = othertable.myid')
+ def test_unique_true_flag(self):
+ meta = MetaData()
+
+ table = Table('mytable', meta, Column('x', Integer, unique=True))
+
+ m2 = MetaData()
+
+ t2 = table.tometadata(m2)
+
+ eq_(
+ len([
+ const for const
+ in t2.constraints
+ if isinstance(const, UniqueConstraint)]),
+ 1
+ )
+
+ def test_index_true_flag(self):
+ meta = MetaData()
+
+ table = Table('mytable', meta, Column('x', Integer, index=True))
+
+ m2 = MetaData()
+
+ t2 = table.tometadata(m2)
+
+ eq_(len(t2.indexes), 1)
+
class InfoTest(fixtures.TestBase):
def test_metadata_info(self):