fix: remove SQLite fallback code from db_engine.py (#70) #89
@ -8,35 +8,25 @@ from typing import Literal, List, Optional
|
||||
from pandas import DataFrame
|
||||
from peewee import *
|
||||
from peewee import ModelSelect
|
||||
from playhouse.pool import PooledPostgresqlDatabase
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
|
||||
# Database configuration - supports both SQLite and PostgreSQL
|
||||
DATABASE_TYPE = os.environ.get('DATABASE_TYPE', 'sqlite')
|
||||
_postgres_password = os.environ.get('POSTGRES_PASSWORD')
|
||||
if _postgres_password is None:
|
||||
raise RuntimeError('POSTGRES_PASSWORD environment variable is required')
|
||||
|
||||
if DATABASE_TYPE.lower() == 'postgresql':
|
||||
from playhouse.pool import PooledPostgresqlDatabase
|
||||
db = PooledPostgresqlDatabase(
|
||||
os.environ.get('POSTGRES_DB', 'sba_master'),
|
||||
user=os.environ.get('POSTGRES_USER', 'sba_admin'),
|
||||
password=os.environ.get('POSTGRES_PASSWORD', 'sba_dev_password_2024'),
|
||||
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=0,
|
||||
autoconnect=True,
|
||||
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=0,
|
||||
autoconnect=True,
|
||||
autorollback=True # Automatically rollback failed transactions
|
||||
)
|
||||
|
||||
date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}'
|
||||
logger = logging.getLogger('discord_app')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user