From 939ba5b6abf49c8edaea93dfb0b2a01779baf261 Mon Sep 17 00:00:00 2001 From: Estrella Pan Date: Thu, 2 Jul 2026 14:35:31 +0200 Subject: [PATCH] refactor(database): drop the now-unused sync engine No production code imports the sync `engine` after the async flip. Remove it and its foreign_keys connect listener; the migration tests build their own throwaway sync engine via create_engine and the sync create_tables/ run_migrations helpers in migrations.py, which are kept for that purpose. DATA_PATH stays only to derive ASYNC_DATA_PATH. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_014w1Z6Nxy6XTRgkFXqPr9Zh --- backend/src/module/database/engine.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/backend/src/module/database/engine.py b/backend/src/module/database/engine.py index 6ae8bb09..602f16f2 100644 --- a/backend/src/module/database/engine.py +++ b/backend/src/module/database/engine.py @@ -1,14 +1,12 @@ from sqlalchemy import event from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker -from sqlmodel import create_engine from module.conf import DATA_PATH -# Sync engine (used by Database, which owns a Session) -engine = create_engine(DATA_PATH) - -# Async engine (for passkey operations) +# The whole application runs on the async engine now. DATA_PATH (the sync +# sqlite URL) is kept only to derive the async URL and for the migration tests, +# which build their own throwaway sync engine. ASYNC_DATA_PATH = DATA_PATH.replace("sqlite:///", "sqlite+aiosqlite:///") async_engine = create_async_engine(ASYNC_DATA_PATH) async_session_factory = sessionmaker( @@ -16,13 +14,6 @@ async_session_factory = sessionmaker( ) -@event.listens_for(engine, "connect") -def _set_sqlite_fk_sync(dbapi_conn, connection_record): - cursor = dbapi_conn.cursor() - cursor.execute("PRAGMA foreign_keys=ON") - cursor.close() - - def _set_sqlite_pragmas_async(dbapi_conn, connection_record): """Per-connection SQLite pragmas for the async engine.