We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a128dac commit 715d10aCopy full SHA for 715d10a
tests/common.py
@@ -1,6 +1,9 @@
1
from os import getenv
2
from pathlib import Path
3
4
+from sqlalchemy import event
5
+from sqlalchemy.engine import Engine
6
+
7
8
def sqla_uri():
9
testing_db_url = getenv("TESTING_DB_URL")
@@ -12,3 +15,18 @@ def sqla_uri():
12
15
13
16
def is_postgres_tests() -> bool:
14
17
return "postgres" in sqla_uri()
18
19
20
+def is_sqlite_tests() -> bool:
21
+ return "sqlite" in sqla_uri()
22
23
24
+@event.listens_for(Engine, "connect")
25
+def set_sqlite_pragma(dbapi_connection, connection_record):
26
+ """
27
+ https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#foreign-key-support
28
29
+ if is_sqlite_tests():
30
+ cursor = dbapi_connection.cursor()
31
+ cursor.execute("PRAGMA foreign_keys=ON")
32
+ cursor.close()
0 commit comments