diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-06 13:34:40 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-06 14:09:04 -0500 |
commit | 3cf19f16631e54108e5f519348cba14521b7433e (patch) | |
tree | 2097dc67dfdd0dec3fb94317dde1fcf2b812f751 /tests | |
parent | cd7b1a94cc90ca533a84b47332900888151e22d0 (diff) | |
download | alembic-3cf19f16631e54108e5f519348cba14521b7433e.tar.gz |
distinguish between string contraint name and defined
Take _NONE_NAME into account as a valid constraint name
and don't skip these constraints or consider them to be unnamed.
Thanks to typing this also revealed that previous batch versions
were also keying "_NONE_NAME" constraints as though they were named.
Fixed regression for 1.10.0 where :class:`.Constraint` objects were
suddenly required to have non-None name fields when using batch mode, which
was not previously a requirement.
Change-Id: If4a7191a00848b19cb124bc6da362f3bc6ce1472
Fixes: #1195
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_batch.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_batch.py b/tests/test_batch.py index e0289aa..3b67895 100644 --- a/tests/test_batch.py +++ b/tests/test_batch.py @@ -49,6 +49,7 @@ from alembic.testing.fixtures import capture_context_buffer from alembic.testing.fixtures import op_fixture from alembic.util import CommandError from alembic.util import exc as alembic_exc +from alembic.util.sqla_compat import _NONE_NAME from alembic.util.sqla_compat import _safe_commit_connection_transaction from alembic.util.sqla_compat import _select from alembic.util.sqla_compat import has_computed @@ -819,6 +820,18 @@ class BatchApplyTest(TestBase): ddl_not_contains="CONSTRAINT uq1 UNIQUE", ) + def test_add_ck_unnamed(self): + """test for #1195""" + impl = self._simple_fixture() + ck = self.op.schema_obj.check_constraint(_NONE_NAME, "tname", "y > 5") + + impl.add_constraint(ck) + self._assert_impl( + impl, + colnames=["id", "x", "y"], + ddl_contains="CHECK (y > 5)", + ) + def test_add_ck(self): impl = self._simple_fixture() ck = self.op.schema_obj.check_constraint("ck1", "tname", "y > 5") @@ -1444,6 +1457,19 @@ class BatchRoundTripTest(TestBase): t = Table("hasbool", self.metadata, Column("x", Integer)) t.create(self.conn) + def test_add_constraint_type(self): + """test for #1195.""" + + with self.op.batch_alter_table("foo") as batch_op: + batch_op.add_column(Column("q", Boolean(create_constraint=True))) + insp = inspect(self.conn) + + assert { + c["type"]._type_affinity + for c in insp.get_columns("foo") + if c["name"] == "q" + }.intersection([Boolean, Integer]) + def test_change_type_boolean_to_int(self): self._boolean_fixture() with self.op.batch_alter_table("hasbool") as batch_op: |