summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNicolas CANIART <nicolas.caniart@jobteaser.com>2022-03-13 12:39:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-03-14 15:12:47 -0400
commitce6144efc6648986733fb9bbb981e95a4a739f61 (patch)
tree4caa38f234748b7e8398d10a618b1198cbd784bd /tests
parent721b28ce889e63e49b8be1a1bd62b7d3bb3b7526 (diff)
downloadalembic-ce6144efc6648986733fb9bbb981e95a4a739f61.tar.gz
Fix duplicated constraints when using expressions
Fixed issue where using :meth:`.Operations.create_table` in conjunction with a :class:`.CheckConstraint` that referred to table-bound :class:`.Column` objects rather than string expressions would be added to the parent table twice, resulting in an incorrect DDL sequence. Pull request courtesy Nicolas CANIART. Fixes: #1004 Closes: #1005 Pull-request: https://github.com/sqlalchemy/alembic/pull/1005 Pull-request-sha: 2fe5c5297bcde990096571a047039c451aa876f6 Change-Id: I2bf48701968fe59a6766f8f8879320b1bfd75774
Diffstat (limited to 'tests')
-rw-r--r--tests/test_op.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_op.py b/tests/test_op.py
index 11d2c1b..677b7bc 100644
--- a/tests/test_op.py
+++ b/tests/test_op.py
@@ -882,6 +882,27 @@ class OpTest(TestBase):
ck = [c for c in t1.constraints if isinstance(c, CheckConstraint)]
eq_(ck[0].name, "ck_1")
+ def test_create_table_with_check_constraint_with_expr(self):
+ context = op_fixture()
+ foo_id = Column("foo_id", Integer)
+ t1 = op.create_table(
+ "some_table",
+ Column("id", Integer, primary_key=True),
+ foo_id,
+ CheckConstraint(foo_id > 5, name="ck_1"),
+ )
+ context.assert_(
+ "CREATE TABLE some_table ("
+ "id INTEGER NOT NULL, "
+ "foo_id INTEGER, "
+ "PRIMARY KEY (id), "
+ "CONSTRAINT ck_1 CHECK (foo_id > 5))"
+ )
+
+ ck = [c for c in t1.constraints if isinstance(c, CheckConstraint)]
+ eq_(ck[0].name, "ck_1")
+ eq_(len(ck), 1)
+
def test_create_table_unique_constraint(self):
context = op_fixture()
t1 = op.create_table(