attype, is_array = _handle_array_type(attype)
# strip quotes from case sensitive enum or domain names
enum_or_domain_key = tuple(util.quoted_token_parser(attype))
- # A table can't override whether the domain is nullable.
- nullable = domain["nullable"]
+ # A table can't override a not null on the domain,
+ # but can override nullable
+ nullable = nullable and domain["nullable"]
if domain["default"] and not default:
# It can, however, override the default
# value, but can't set it to null.
from sqlalchemy.testing.assertions import assert_raises
from sqlalchemy.testing.assertions import AssertsExecutionResults
from sqlalchemy.testing.assertions import eq_
+from sqlalchemy.testing.assertions import is_
from sqlalchemy.testing.assertions import is_true
"CREATE DOMAIN enumdomain AS testtype",
"CREATE DOMAIN arraydomain AS INTEGER[]",
'CREATE DOMAIN "SomeSchema"."Quoted.Domain" INTEGER DEFAULT 0',
+ "CREATE DOMAIN nullable_domain AS TEXT CHECK "
+ "(VALUE IN('FOO', 'BAR'))",
+ "CREATE DOMAIN not_nullable_domain AS TEXT NOT NULL",
]:
try:
con.exec_driver_sql(ddl)
"CREATE TABLE quote_test "
'(id integer, data "SomeSchema"."Quoted.Domain")'
)
+ con.exec_driver_sql(
+ "CREATE TABLE nullable_domain_test "
+ "(not_nullable_domain_col nullable_domain not null,"
+ "nullable_local not_nullable_domain)"
+ )
@classmethod
def teardown_test_class(cls):
con.exec_driver_sql('DROP DOMAIN "SomeSchema"."Quoted.Domain"')
con.exec_driver_sql('DROP SCHEMA "SomeSchema"')
+ con.exec_driver_sql("DROP TABLE nullable_domain_test")
+ con.exec_driver_sql("DROP DOMAIN nullable_domain")
+ con.exec_driver_sql("DROP DOMAIN not_nullable_domain")
+
def test_table_is_reflected(self, connection):
metadata = MetaData()
table = Table("testtable", metadata, autoload_with=connection)
)
assert isinstance(table.c.answer.type, Integer)
+ def test_nullable_from_domain(self, connection):
+ metadata = MetaData()
+ table = Table(
+ "nullable_domain_test", metadata, autoload_with=connection
+ )
+ is_(table.c.not_nullable_domain_col.nullable, False)
+ is_(table.c.nullable_local.nullable, False)
+
def test_domain_is_reflected(self, connection):
metadata = MetaData()
table = Table("testtable", metadata, autoload_with=connection)