]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Set create_constraint=True for Enum / Boolean tests
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jun 2020 23:37:25 +0000 (19:37 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jun 2020 23:37:25 +0000 (19:37 -0400)
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

tests/test_batch.py
tests/test_op.py
tests/test_op_naming_convention.py

index c88ec53787c9e2133ad21b1ff6d6d9d3ef9d8da7..dbcd9b56858173009f4b744ba0447ed933f52a4d 100644 (file)
@@ -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)
 
index 98daa5fee2022ae7f1e48634269bd3b8b6c1f7f8..1406dbdcdc8cca9324572428c74daa1028cd1e29 100644 (file)
@@ -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_(
index b83b3af464f5471925df2c756f5e2179ba9ac609..0cc22afaa1554db7a8bf2182eb4c8fe3f47fa80b 100644 (file)
@@ -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",