diff options
author | Michael Gorven <michael@gorven.net> | 2022-11-29 18:36:19 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-30 15:13:22 -0500 |
commit | 07760011b5176be03c7811e9a45933b473b8b80b (patch) | |
tree | fe7c1958ef41ab47604e765cfcdbd35daaff7ef1 /test/dialect/test_sqlite.py | |
parent | 7857a1de32169858367446d11089c34f8daee957 (diff) | |
download | sqlalchemy-07760011b5176be03c7811e9a45933b473b8b80b.tar.gz |
[sqlite] Reflect DEFERRABLE and INITIALLY options for foreign keys
Added support for the SQLite backend to reflect the "DEFERRABLE" and
"INITIALLY" keywords which may be present on a foreign key construct. Pull
request courtesy Michael Gorven.
Fixes: #8903
Closes: #8904
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8904
Pull-request-sha: 52aa4cf77482c4051899e21bea75b9830e4c3efa
Change-Id: I713906db1a458d8f1be39625841ca3bbc03ec835
Diffstat (limited to 'test/dialect/test_sqlite.py')
-rw-r--r-- | test/dialect/test_sqlite.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index d460ef64e..c5147e37f 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -1879,6 +1879,20 @@ class ConstraintReflectionTest(fixtures.TestBase): ) conn.exec_driver_sql( + "CREATE TABLE deferrable_test (id INTEGER PRIMARY KEY, " + "c1 INTEGER, c2 INTEGER, c3 INTEGER, c4 INTEGER, " + "CONSTRAINT fk1 FOREIGN KEY (c1) REFERENCES a1(id) " + "DEFERRABLE," + "CONSTRAINT fk2 FOREIGN KEY (c2) REFERENCES a1(id) " + "NOT DEFERRABLE," + "CONSTRAINT fk3 FOREIGN KEY (c3) REFERENCES a2(id) " + "ON UPDATE CASCADE " + "DEFERRABLE INITIALLY DEFERRED," + "CONSTRAINT fk4 FOREIGN KEY (c4) REFERENCES a2(id) " + "NOT DEFERRABLE INITIALLY IMMEDIATE)" + ) + + conn.exec_driver_sql( "CREATE TABLE cp (" "q INTEGER check (q > 1 AND q < 6),\n" "CONSTRAINT cq CHECK (q == 1 OR (q > 2 AND q < 5))\n" @@ -2248,6 +2262,51 @@ class ConstraintReflectionTest(fixtures.TestBase): ], ) + def test_foreign_key_deferrable_initially(self): + inspector = inspect(testing.db) + fks = inspector.get_foreign_keys("deferrable_test") + eq_( + fks, + [ + { + "referred_table": "a1", + "referred_columns": ["id"], + "referred_schema": None, + "name": "fk1", + "constrained_columns": ["c1"], + "options": {"deferrable": True}, + }, + { + "referred_table": "a1", + "referred_columns": ["id"], + "referred_schema": None, + "name": "fk2", + "constrained_columns": ["c2"], + "options": {"deferrable": False}, + }, + { + "referred_table": "a2", + "referred_columns": ["id"], + "referred_schema": None, + "name": "fk3", + "constrained_columns": ["c3"], + "options": { + "deferrable": True, + "initially": "DEFERRED", + "onupdate": "CASCADE", + }, + }, + { + "referred_table": "a2", + "referred_columns": ["id"], + "referred_schema": None, + "name": "fk4", + "constrained_columns": ["c4"], + "options": {"deferrable": False, "initially": "IMMEDIATE"}, + }, + ], + ) + def test_foreign_key_options_unnamed_inline(self): with testing.db.begin() as conn: conn.exec_driver_sql( |