fix: remove SQLite fallback code from db_engine.py (#70)
Removes DATABASE_TYPE conditional entirely. PostgreSQL is now the only supported backend. Moves PooledPostgresqlDatabase import to top-level and raises RuntimeError at startup if POSTGRES_PASSWORD is unset, preventing silent misconnection with misleading errors. Closes #70 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0ee7367bc0
commit
eb886a4690
@ -8,39 +8,29 @@ from typing import Literal, List, Optional
|
|||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from peewee import *
|
from peewee import *
|
||||||
from peewee import ModelSelect
|
from peewee import ModelSelect
|
||||||
|
from playhouse.pool import PooledPostgresqlDatabase
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
|
|
||||||
# Database configuration - supports both SQLite and PostgreSQL
|
_postgres_password = os.environ.get("POSTGRES_PASSWORD")
|
||||||
DATABASE_TYPE = os.environ.get("DATABASE_TYPE", "sqlite")
|
if _postgres_password is None:
|
||||||
|
raise RuntimeError(
|
||||||
if DATABASE_TYPE.lower() == "postgresql":
|
"POSTGRES_PASSWORD environment variable is not set. "
|
||||||
from playhouse.pool import PooledPostgresqlDatabase
|
"This variable is required when DATABASE_TYPE=postgresql."
|
||||||
|
|
||||||
_postgres_password = os.environ.get("POSTGRES_PASSWORD")
|
|
||||||
if _postgres_password is None:
|
|
||||||
raise RuntimeError(
|
|
||||||
"POSTGRES_PASSWORD environment variable is not set. "
|
|
||||||
"This variable is required when DATABASE_TYPE=postgresql."
|
|
||||||
)
|
|
||||||
db = PooledPostgresqlDatabase(
|
|
||||||
os.environ.get("POSTGRES_DB", "sba_master"),
|
|
||||||
user=os.environ.get("POSTGRES_USER", "sba_admin"),
|
|
||||||
password=_postgres_password,
|
|
||||||
host=os.environ.get("POSTGRES_HOST", "sba_postgres"),
|
|
||||||
port=int(os.environ.get("POSTGRES_PORT", "5432")),
|
|
||||||
max_connections=20,
|
|
||||||
stale_timeout=300, # 5 minutes
|
|
||||||
timeout=5,
|
|
||||||
autoconnect=False,
|
|
||||||
autorollback=True, # Automatically rollback failed transactions
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Default SQLite configuration
|
|
||||||
db = SqliteDatabase(
|
|
||||||
"storage/sba_master.db",
|
|
||||||
pragmas={"journal_mode": "wal", "cache_size": -1 * 64000, "synchronous": 0},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
db = PooledPostgresqlDatabase(
|
||||||
|
os.environ.get("POSTGRES_DB", "sba_master"),
|
||||||
|
user=os.environ.get("POSTGRES_USER", "sba_admin"),
|
||||||
|
password=_postgres_password,
|
||||||
|
host=os.environ.get("POSTGRES_HOST", "sba_postgres"),
|
||||||
|
port=int(os.environ.get("POSTGRES_PORT", "5432")),
|
||||||
|
max_connections=20,
|
||||||
|
stale_timeout=300, # 5 minutes
|
||||||
|
timeout=5,
|
||||||
|
autoconnect=False,
|
||||||
|
autorollback=True, # Automatically rollback failed transactions
|
||||||
|
)
|
||||||
|
|
||||||
date = f"{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}"
|
date = f"{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}"
|
||||||
logger = logging.getLogger("discord_app")
|
logger = logging.getLogger("discord_app")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user