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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014w1Z6Nxy6XTRgkFXqPr9Zh
This commit is contained in:
Estrella Pan
2026-07-02 14:35:31 +02:00
parent 1cd740657a
commit 939ba5b6ab

View File

@@ -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.