@@ -1661,19 +1661,21 @@ def test_drop_pk_col_readd_col_also_pk_const(self):
1661
1661
pk_const = inspect (self .conn ).get_pk_constraint ("foo" )
1662
1662
eq_ (pk_const ["constrained_columns" ], ["id" ])
1663
1663
1664
- def test_add_pk_constraint (self ):
1664
+ @testing .combinations (("always" ,), ("auto" ,), argnames = "recreate" )
1665
+ def test_add_pk_constraint (self , recreate ):
1665
1666
self ._no_pk_fixture ()
1666
- with self .op .batch_alter_table ("nopk" , recreate = "always" ) as batch_op :
1667
+ with self .op .batch_alter_table ("nopk" , recreate = recreate ) as batch_op :
1667
1668
batch_op .create_primary_key ("newpk" , ["a" , "b" ])
1668
1669
1669
1670
pk_const = inspect (self .conn ).get_pk_constraint ("nopk" )
1670
1671
with config .requirements .reflects_pk_names .fail_if ():
1671
1672
eq_ (pk_const ["name" ], "newpk" )
1672
1673
eq_ (pk_const ["constrained_columns" ], ["a" , "b" ])
1673
1674
1675
+ @testing .combinations (("always" ,), ("auto" ,), argnames = "recreate" )
1674
1676
@config .requirements .check_constraint_reflection
1675
- def test_add_ck_constraint (self ):
1676
- with self .op .batch_alter_table ("foo" , recreate = "always" ) as batch_op :
1677
+ def test_add_ck_constraint (self , recreate ):
1678
+ with self .op .batch_alter_table ("foo" , recreate = recreate ) as batch_op :
1677
1679
batch_op .create_check_constraint ("newck" , text ("x > 0" ))
1678
1680
1679
1681
ck_consts = inspect (self .conn ).get_check_constraints ("foo" )
@@ -1682,12 +1684,13 @@ def test_add_ck_constraint(self):
1682
1684
)
1683
1685
eq_ (ck_consts , [{"sqltext" : "x > 0" , "name" : "newck" }])
1684
1686
1687
+ @testing .combinations (("always" ,), ("auto" ,), argnames = "recreate" )
1685
1688
@config .requirements .check_constraint_reflection
1686
- def test_drop_ck_constraint (self ):
1689
+ def test_drop_ck_constraint (self , recreate ):
1687
1690
self ._ck_constraint_fixture ()
1688
1691
1689
1692
with self .op .batch_alter_table (
1690
- "ck_table" , recreate = "always"
1693
+ "ck_table" , recreate = recreate
1691
1694
) as batch_op :
1692
1695
batch_op .drop_constraint ("ck" , "check" )
1693
1696
@@ -1736,6 +1739,36 @@ def _assert_table_comment(self, tname, comment):
1736
1739
tcomment = insp .get_table_comment (tname )
1737
1740
eq_ (tcomment , {"text" : comment })
1738
1741
1742
+ @testing .combinations (("always" ,), ("auto" ,), argnames = "recreate" )
1743
+ def test_add_uq (self , recreate ):
1744
+ with self .op .batch_alter_table ("foo" , recreate = recreate ) as batch_op :
1745
+ batch_op .create_unique_constraint ("newuk" , ["x" ])
1746
+
1747
+ uq_consts = inspect (self .conn ).get_unique_constraints ("foo" )
1748
+ eq_ (
1749
+ [
1750
+ {"name" : uc ["name" ], "column_names" : uc ["column_names" ]}
1751
+ for uc in uq_consts
1752
+ ],
1753
+ [{"name" : "newuk" , "column_names" : ["x" ]}],
1754
+ )
1755
+
1756
+ @testing .combinations (("always" ,), ("auto" ,), argnames = "recreate" )
1757
+ def test_add_uq_plus_col (self , recreate ):
1758
+ with self .op .batch_alter_table ("foo" , recreate = recreate ) as batch_op :
1759
+ batch_op .add_column (Column ("y" , Integer ))
1760
+ batch_op .create_unique_constraint ("newuk" , ["x" , "y" ])
1761
+
1762
+ uq_consts = inspect (self .conn ).get_unique_constraints ("foo" )
1763
+
1764
+ eq_ (
1765
+ [
1766
+ {"name" : uc ["name" ], "column_names" : uc ["column_names" ]}
1767
+ for uc in uq_consts
1768
+ ],
1769
+ [{"name" : "newuk" , "column_names" : ["x" , "y" ]}],
1770
+ )
1771
+
1739
1772
@config .requirements .comments
1740
1773
def test_add_table_comment (self ):
1741
1774
with self .op .batch_alter_table ("foo" ) as batch_op :
0 commit comments