Initial commit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Todd
2026-03-29 22:42:55 -04:00
commit 0d7b2b1aab
389 changed files with 280296 additions and 0 deletions

27
modules/db_bootstrap.py Normal file
View File

@@ -0,0 +1,27 @@
"""
Database Backend Bootstrap
Import this module before any other imports that use sqlite3.
When DATABASE_BACKEND=postgresql, it monkey-patches sys.modules['sqlite3']
with pg_adapter so every subsequent `import sqlite3` gets the PostgreSQL adapter.
Default is 'sqlite' (no change — original behavior preserved).
"""
import os
from pathlib import Path
# Load .env BEFORE checking DATABASE_BACKEND — systemd services don't set
# this env var, so .env is the primary source of truth.
try:
from dotenv import load_dotenv
_env_path = Path(__file__).resolve().parent.parent / '.env'
if _env_path.exists():
load_dotenv(_env_path)
except ImportError:
pass # rely on system env vars
if os.getenv('DATABASE_BACKEND', 'sqlite').lower() == 'postgresql':
import sys
from modules import pg_adapter
sys.modules['sqlite3'] = pg_adapter