summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-06-02 14:21:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-06-03 16:19:40 -0400
commit97cd0a5db8bb2e47f38899592740d1bc75ec0412 (patch)
treebea2062f7e2b3e60fd8b87bdba7e368cc8e87724 /test/sql
parentc7c564b57f3ce2fee30b44f22db7baf2f0fa9fe0 (diff)
downloadsqlalchemy-97cd0a5db8bb2e47f38899592740d1bc75ec0412.tar.gz
Default create_constraint to False
The :paramref:`.Enum.create_constraint` and :paramref:`.Boolean.create_constraint` parameters now default to False, indicating when a so-called "non-native" version of these two datatypes is created, a CHECK constraint will not be generated by default. These CHECK constraints present schema-management maintenance complexities that should be opted in to, rather than being turned on by default. Fixes: #5367 Change-Id: I0a3fb608ce32143fa757546cc17ba2013e93272a
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_metadata.py35
-rw-r--r--test/sql/test_types.py79
2 files changed, 93 insertions, 21 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index a75aee6e9..2145e72d0 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -2258,7 +2258,7 @@ class SchemaTypeTest(fixtures.TestBase):
def test_boolean_constraint_type_doesnt_double(self):
m1 = MetaData()
- t1 = Table("x", m1, Column("flag", Boolean()))
+ t1 = Table("x", m1, Column("flag", Boolean(create_constraint=True)))
eq_(
len([c for c in t1.constraints if isinstance(c, CheckConstraint)]),
1,
@@ -2274,7 +2274,11 @@ class SchemaTypeTest(fixtures.TestBase):
def test_enum_constraint_type_doesnt_double(self):
m1 = MetaData()
- t1 = Table("x", m1, Column("flag", Enum("a", "b", "c")))
+ t1 = Table(
+ "x",
+ m1,
+ Column("flag", Enum("a", "b", "c", create_constraint=True)),
+ )
eq_(
len([c for c in t1.constraints if isinstance(c, CheckConstraint)]),
1,
@@ -5031,7 +5035,11 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
)
- u1 = Table("user", m1, Column("x", Boolean(name="foo")))
+ u1 = Table(
+ "user",
+ m1,
+ Column("x", Boolean(name="foo", create_constraint=True)),
+ )
# constraint is not hit
eq_(
[c for c in u1.constraints if isinstance(c, CheckConstraint)][
@@ -5053,7 +5061,7 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
naming_convention={"ck": "ck_%(table_name)s_%(column_0_name)s"}
)
- u1 = Table("user", m1, Column("x", Boolean()))
+ u1 = Table("user", m1, Column("x", Boolean(create_constraint=True)))
# constraint is not hit
is_(
[c for c in u1.constraints if isinstance(c, CheckConstraint)][
@@ -5075,7 +5083,11 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
)
- u1 = Table("user", m1, Column("x", Enum("a", "b", name="foo")))
+ u1 = Table(
+ "user",
+ m1,
+ Column("x", Enum("a", "b", name="foo", create_constraint=True)),
+ )
eq_(
[c for c in u1.constraints if isinstance(c, CheckConstraint)][
0
@@ -5097,7 +5109,14 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
)
u1 = Table(
- "user", m1, Column("x", Enum("a", "b", name=naming.conv("foo")))
+ "user",
+ m1,
+ Column(
+ "x",
+ Enum(
+ "a", "b", name=naming.conv("foo"), create_constraint=True
+ ),
+ ),
)
eq_(
[c for c in u1.constraints if isinstance(c, CheckConstraint)][
@@ -5119,7 +5138,7 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
)
- u1 = Table("user", m1, Column("x", Boolean()))
+ u1 = Table("user", m1, Column("x", Boolean(create_constraint=True)))
# constraint gets special _defer_none_name
is_(
[c for c in u1.constraints if isinstance(c, CheckConstraint)][
@@ -5145,7 +5164,7 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL):
def test_schematype_no_ck_name_boolean_no_name(self):
m1 = MetaData() # no naming convention
- u1 = Table("user", m1, Column("x", Boolean()))
+ u1 = Table("user", m1, Column("x", Boolean(create_constraint=True)))
# constraint gets special _defer_none_name
is_(
[c for c in u1.constraints if isinstance(c, CheckConstraint)][
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index a0c4ee022..30e5d1fca 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -1331,25 +1331,43 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
@classmethod
def define_tables(cls, metadata):
+ # note create_constraint has changed in 1.4 as of #5367
Table(
"enum_table",
metadata,
Column("id", Integer, primary_key=True),
- Column("someenum", Enum("one", "two", "three", name="myenum")),
+ Column(
+ "someenum",
+ Enum(
+ "one",
+ "two",
+ "three",
+ name="myenum",
+ create_constraint=True,
+ ),
+ ),
)
Table(
"non_native_enum_table",
metadata,
Column("id", Integer, primary_key=True, autoincrement=False),
- Column("someenum", Enum("one", "two", "three", native_enum=False)),
+ Column(
+ "someenum",
+ Enum(
+ "one",
+ "two",
+ "three",
+ native_enum=False,
+ create_constraint=True,
+ ),
+ ),
Column(
"someotherenum",
Enum(
"one",
"two",
"three",
- create_constraint=False,
native_enum=False,
validate_strings=True,
),
@@ -1360,7 +1378,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
"stdlib_enum_table",
metadata,
Column("id", Integer, primary_key=True),
- Column("someenum", Enum(cls.SomeEnum)),
+ Column("someenum", Enum(cls.SomeEnum, create_constraint=True)),
)
Table(
@@ -1372,6 +1390,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
Enum(
cls.SomeOtherEnum,
values_callable=EnumTest.get_enum_string_values,
+ create_constraint=True,
),
),
)
@@ -1605,9 +1624,21 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
Column(
"data",
Enum(
- "one", "two", "three", native_enum=False, name="e1"
+ "one",
+ "two",
+ "three",
+ native_enum=False,
+ name="e1",
+ create_constraint=True,
).with_variant(
- Enum("four", "five", "six", native_enum=False, name="e2"),
+ Enum(
+ "four",
+ "five",
+ "six",
+ native_enum=False,
+ name="e2",
+ create_constraint=True,
+ ),
"some_other_db",
),
),
@@ -1638,9 +1669,21 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
Column(
"data",
Enum(
- "one", "two", "three", native_enum=False, name="e1"
+ "one",
+ "two",
+ "three",
+ native_enum=False,
+ name="e1",
+ create_constraint=True,
).with_variant(
- Enum("four", "five", "six", native_enum=False, name="e2"),
+ Enum(
+ "four",
+ "five",
+ "six",
+ native_enum=False,
+ name="e2",
+ create_constraint=True,
+ ),
testing.db.dialect.name,
),
),
@@ -1896,7 +1939,10 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
class MyEnum(TypeDecorator):
def __init__(self, values):
self.impl = Enum(
- *[v.name for v in values], name="myenum", native_enum=False
+ *[v.name for v in values],
+ name="myenum",
+ native_enum=False,
+ create_constraint=True
)
# future method
@@ -1931,7 +1977,11 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
are created with checkfirst=False"""
e = engines.mock_engine()
- t = Table("t1", MetaData(), Column("x", Enum("x", "y", name="pge")))
+ t = Table(
+ "t1",
+ MetaData(),
+ Column("x", Enum("x", "y", name="pge", create_constraint=True)),
+ )
t.create(e, checkfirst=False)
# basically looking for the start of
# the constraint, or the ENUM def itself,
@@ -3038,6 +3088,9 @@ class BooleanTest(
"""test edge cases for booleans. Note that the main boolean test suite
is now in testing/suite/test_types.py
+ the default value of create_constraint was changed to False in
+ version 1.4 with #5367.
+
"""
__backend__ = True
@@ -3048,8 +3101,8 @@ class BooleanTest(
"boolean_table",
metadata,
Column("id", Integer, primary_key=True, autoincrement=False),
- Column("value", Boolean),
- Column("unconstrained_value", Boolean(create_constraint=False)),
+ Column("value", Boolean(create_constraint=True)),
+ Column("unconstrained_value", Boolean()),
)
@testing.fails_on(
@@ -3078,7 +3131,7 @@ class BooleanTest(
self.value = value
class MyBool(TypeDecorator):
- impl = Boolean()
+ impl = Boolean(create_constraint=True)
# future method
def process_literal_param(self, value, dialect):