Saving our work just in case.

This commit is contained in:
Scott Idem
2026-01-06 18:06:45 -05:00
parent 55033d0749
commit a6ec6d1b2b
3 changed files with 439 additions and 0 deletions

28
app/db_connection.py Normal file
View File

@@ -0,0 +1,28 @@
"""
Independent database connection module to prevent circular imports.
"""
import logging
from sqlalchemy import create_engine
from app.config import settings
# Use local logger to avoid importing app.log (which might create cycles)
log = logging.getLogger(__name__)
db_uri = settings.SQLALCHEMY_DB_URI
engine = create_engine(
url = db_uri,
echo = False,
pool_use_lifo = True,
pool_pre_ping = True,
pool_recycle = settings.DB['pool_recycle'],
isolation_level = 'READ COMMITTED',
connect_args = {'connect_timeout': settings.DB['connect_timeout']}
)
log.info('DB Connection initializing...')
db = None
try:
db = engine.connect()
log.info(f'Connected to database: {db_uri}')
except Exception:
log.exception('Could not connect to database.')