event listens for sqlalchemy
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import engine_from_config, event
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
from src.core.database import Base
|
||||
@@ -67,6 +66,14 @@ def run_migrations_online() -> None:
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
# Enable foreign keys for SQLite in migrations
|
||||
@event.listens_for(connectable, "connect")
|
||||
def set_sqlite_pragma(dbapi_connection, connection_record):
|
||||
print("⚙️ Enabling PRAGMA foreign_keys=ON for Alembic")
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute("PRAGMA foreign_keys=ON")
|
||||
cursor.close()
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user