7e7ec67e58
- fix: imap folder names with spaces (RFC3501 quoting in move/create/select) - fix: move only deletes source after COPY + Message-ID verification in target - fix: backup endpoint hung on sqlite write locks — enable WAL + busy_timeout - perf: indexes on filter_logs(created_at, level, account_id+created_at) for fast log queries on millions of rows - feat: optional "logs mit sichern" checkbox in backup export, restore on import - UI: backup download uses fetch+blob with error display instead of location.href Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
989 B
Python
35 lines
989 B
Python
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
|
|
|
from app.config import settings
|
|
|
|
engine = create_engine(settings.database_url, connect_args={"check_same_thread": False})
|
|
|
|
|
|
# SQLite: WAL-Modus, damit Reader (z.B. Backup-Export) nicht von gleichzeitigen
|
|
# Writern (Scheduler/Log) blockiert werden. busy_timeout sorgt dafür, dass kurze
|
|
# Lock-Konflikte automatisch retryen statt sofort zu failen.
|
|
if settings.database_url.startswith("sqlite"):
|
|
@event.listens_for(engine, "connect")
|
|
def _set_sqlite_pragmas(dbapi_connection, _):
|
|
cursor = dbapi_connection.cursor()
|
|
cursor.execute("PRAGMA journal_mode=WAL")
|
|
cursor.execute("PRAGMA busy_timeout=10000")
|
|
cursor.execute("PRAGMA synchronous=NORMAL")
|
|
cursor.close()
|
|
|
|
|
|
SessionLocal = sessionmaker(bind=engine)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|