diff options
author | Gilbert Gilb's <gilbsgilbert@gmail.com> | 2022-01-23 13:00:35 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-26 22:22:14 -0500 |
commit | 77dd6808f250e0431f9bce824f46f6e1ef63eef3 (patch) | |
tree | 2e2eb137c18994d707ff27cd9d3dfb4163bdea8a /test/dialect/postgresql/test_compiler.py | |
parent | 321f64f71e7ecc7404da9b95e2e0aa1d692ac181 (diff) | |
download | sqlalchemy-77dd6808f250e0431f9bce824f46f6e1ef63eef3.tar.gz |
Add compiler support for PostgreSQL "NOT VALID" constraints.
Added compiler support for the PostgreSQL ``NOT VALID`` phrase when rendering
DDL for the :class:`.CheckConstraint`, :class:`.ForeignKeyConstraint`
and :class:`.ForeignKey` schema constructs. Pull request courtesy
Gilbert Gilb's.
Fixes: #7600
Closes: #7601
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7601
Pull-request-sha: 78eecd55fd9fad07030d963f5fd6713c4af60e80
Change-Id: I84bfe84596856eeea2bcca45c04ad23d980a75ec
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 0e04ccb95..b98d0fac6 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -3,6 +3,7 @@ from sqlalchemy import and_ from sqlalchemy import BigInteger from sqlalchemy import bindparam from sqlalchemy import cast +from sqlalchemy import CheckConstraint from sqlalchemy import Column from sqlalchemy import Computed from sqlalchemy import Date @@ -10,6 +11,8 @@ from sqlalchemy import delete from sqlalchemy import Enum from sqlalchemy import exc from sqlalchemy import Float +from sqlalchemy import ForeignKey +from sqlalchemy import ForeignKeyConstraint from sqlalchemy import func from sqlalchemy import Identity from sqlalchemy import Index @@ -828,6 +831,62 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): schema.DropIndex(idx1), "DROP INDEX test_idx1", dialect=dialect_9_1 ) + def test_create_check_constraint_not_valid(self): + m = MetaData() + + tbl = Table( + "testtbl", + m, + Column("data", Integer), + CheckConstraint("data = 0", postgresql_not_valid=True), + ) + + self.assert_compile( + schema.CreateTable(tbl), + "CREATE TABLE testtbl (data INTEGER, CHECK (data = 0) NOT VALID)", + ) + + def test_create_foreign_key_constraint_not_valid(self): + m = MetaData() + + tbl = Table( + "testtbl", + m, + Column("a", Integer), + Column("b", Integer), + ForeignKeyConstraint( + "b", ["testtbl.a"], postgresql_not_valid=True + ), + ) + + self.assert_compile( + schema.CreateTable(tbl), + "CREATE TABLE testtbl (" + "a INTEGER, " + "b INTEGER, " + "FOREIGN KEY(b) REFERENCES testtbl (a) NOT VALID" + ")", + ) + + def test_create_foreign_key_column_not_valid(self): + m = MetaData() + + tbl = Table( + "testtbl", + m, + Column("a", Integer), + Column("b", ForeignKey("testtbl.a", postgresql_not_valid=True)), + ) + + self.assert_compile( + schema.CreateTable(tbl), + "CREATE TABLE testtbl (" + "a INTEGER, " + "b INTEGER, " + "FOREIGN KEY(b) REFERENCES testtbl (a) NOT VALID" + ")", + ) + def test_exclude_constraint_min(self): m = MetaData() tbl = Table("testtbl", m, Column("room", Integer, primary_key=True)) |