From: Mike Bayer Date: Tue, 2 Jun 2020 23:37:25 +0000 (-0400) Subject: Set create_constraint=True for Enum / Boolean tests X-Git-Tag: rel_1_4_3~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=474088e9403fcfc444f114e3948aa77f6f262caf;p=thirdparty%2Fsqlalchemy%2Falembic.git Set create_constraint=True for Enum / Boolean tests In SQLAlchemy [1] [2] we are changing the default for Enum / Boolean create_constraint to False. ensure tests that rely upon this setting being True set it explicitly. [1] I0a3fb608ce32143fa757546cc17ba2013e93272a [2] https://github.com/sqlalchemy/sqlalchemy/issues/5367 Change-Id: Ic823124446607c2f245663350632382bd1ca10ba --- diff --git a/tests/test_batch.py b/tests/test_batch.py index c88ec537..dbcd9b56 100644 --- a/tests/test_batch.py +++ b/tests/test_batch.py @@ -188,7 +188,7 @@ class BatchApplyTest(TestBase): "tname", m, Column("id", Integer, primary_key=True), - Column("flag", Boolean), + Column("flag", Boolean(create_constraint=True)), ) return ApplyBatchImpl(self.impl, t, table_args, table_kwargs, False) @@ -208,7 +208,7 @@ class BatchApplyTest(TestBase): "tname", m, Column("id", Integer, primary_key=True), - Column("thing", Enum("a", "b", "c")), + Column("thing", Enum("a", "b", "c", create_constraint=True)), ) return ApplyBatchImpl(self.impl, t, table_args, table_kwargs, False) diff --git a/tests/test_op.py b/tests/test_op.py index 98daa5fe..1406dbdc 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -181,7 +181,9 @@ class OpTest(TestBase): def test_add_column_schema_type(self): """Test that a schema type generates its constraints....""" context = op_fixture() - op.add_column("t1", Column("c1", Boolean, nullable=False)) + op.add_column( + "t1", Column("c1", Boolean(create_constraint=True), nullable=False) + ) context.assert_( "ALTER TABLE t1 ADD COLUMN c1 BOOLEAN NOT NULL", "ALTER TABLE t1 ADD CHECK (c1 IN (0, 1))", @@ -191,7 +193,9 @@ class OpTest(TestBase): """Test that a schema type generates its constraints....""" context = op_fixture() op.add_column( - "t1", Column("c1", Boolean, nullable=False), schema="foo" + "t1", + Column("c1", Boolean(create_constraint=True), nullable=False), + schema="foo", ) context.assert_( "ALTER TABLE foo.t1 ADD COLUMN c1 BOOLEAN NOT NULL", @@ -202,7 +206,9 @@ class OpTest(TestBase): """Test that a schema type doesn't generate a constraint based on check rule.""" context = op_fixture("postgresql") - op.add_column("t1", Column("c1", Boolean, nullable=False)) + op.add_column( + "t1", Column("c1", Boolean(create_constraint=True), nullable=False) + ) context.assert_("ALTER TABLE t1 ADD COLUMN c1 BOOLEAN NOT NULL") def test_add_column_fk_self_referential(self): @@ -390,7 +396,7 @@ class OpTest(TestBase): def test_alter_column_schema_type_unnamed(self): context = op_fixture("mssql", native_boolean=False) - op.alter_column("t", "c", type_=Boolean()) + op.alter_column("t", "c", type_=Boolean(create_constraint=True)) context.assert_( "ALTER TABLE t ALTER COLUMN c BIT", "ALTER TABLE t ADD CHECK (c IN (0, 1))", @@ -398,7 +404,9 @@ class OpTest(TestBase): def test_alter_column_schema_schema_type_unnamed(self): context = op_fixture("mssql", native_boolean=False) - op.alter_column("t", "c", type_=Boolean(), schema="foo") + op.alter_column( + "t", "c", type_=Boolean(create_constraint=True), schema="foo" + ) context.assert_( "ALTER TABLE foo.t ALTER COLUMN c BIT", "ALTER TABLE foo.t ADD CHECK (c IN (0, 1))", @@ -406,7 +414,9 @@ class OpTest(TestBase): def test_alter_column_schema_type_named(self): context = op_fixture("mssql", native_boolean=False) - op.alter_column("t", "c", type_=Boolean(name="xyz")) + op.alter_column( + "t", "c", type_=Boolean(name="xyz", create_constraint=True) + ) context.assert_( "ALTER TABLE t ALTER COLUMN c BIT", "ALTER TABLE t ADD CONSTRAINT xyz CHECK (c IN (0, 1))", @@ -414,7 +424,12 @@ class OpTest(TestBase): def test_alter_column_schema_schema_type_named(self): context = op_fixture("mssql", native_boolean=False) - op.alter_column("t", "c", type_=Boolean(name="xyz"), schema="foo") + op.alter_column( + "t", + "c", + type_=Boolean(name="xyz", create_constraint=True), + schema="foo", + ) context.assert_( "ALTER TABLE foo.t ALTER COLUMN c BIT", "ALTER TABLE foo.t ADD CONSTRAINT xyz CHECK (c IN (0, 1))", @@ -423,7 +438,10 @@ class OpTest(TestBase): def test_alter_column_schema_type_existing_type(self): context = op_fixture("mssql", native_boolean=False) op.alter_column( - "t", "c", type_=String(10), existing_type=Boolean(name="xyz") + "t", + "c", + type_=String(10), + existing_type=Boolean(name="xyz", create_constraint=True), ) context.assert_( "ALTER TABLE t DROP CONSTRAINT xyz", @@ -436,7 +454,7 @@ class OpTest(TestBase): "t", "c", type_=String(10), - existing_type=Boolean(name="xyz"), + existing_type=Boolean(name="xyz", create_constraint=True), schema="foo", ) context.assert_( diff --git a/tests/test_op_naming_convention.py b/tests/test_op_naming_convention.py index b83b3af4..0cc22afa 100644 --- a/tests/test_op_naming_convention.py +++ b/tests/test_op_naming_convention.py @@ -129,7 +129,14 @@ class AutoNamingConventionTest(TestBase): context = op_fixture( naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"} ) - op.add_column("t1", Column("c1", Boolean(name="foo"), nullable=False)) + op.add_column( + "t1", + Column( + "c1", + Boolean(name="foo", create_constraint=True), + nullable=False, + ), + ) context.assert_( "ALTER TABLE t1 ADD COLUMN c1 BOOLEAN NOT NULL", "ALTER TABLE t1 ADD CONSTRAINT ck_t1_foo CHECK (c1 IN (0, 1))", @@ -140,7 +147,12 @@ class AutoNamingConventionTest(TestBase): naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"} ) op.add_column( - "t1", Column("c1", Boolean(name=op.f("foo")), nullable=False) + "t1", + Column( + "c1", + Boolean(name=op.f("foo"), create_constraint=True), + nullable=False, + ), ) context.assert_( "ALTER TABLE t1 ADD COLUMN c1 BOOLEAN NOT NULL",