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 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('POSTGRES_PASSWORD environment variable is required')
|
||||||
|
|
||||||
if DATABASE_TYPE.lower() == 'postgresql':
|
db = PooledPostgresqlDatabase(
|
||||||
from playhouse.pool import PooledPostgresqlDatabase
|
os.environ.get('POSTGRES_DB', 'sba_master'),
|
||||||
db = PooledPostgresqlDatabase(
|
user=os.environ.get('POSTGRES_USER', 'sba_admin'),
|
||||||
os.environ.get('POSTGRES_DB', 'sba_master'),
|
password=_postgres_password,
|
||||||
user=os.environ.get('POSTGRES_USER', 'sba_admin'),
|
host=os.environ.get('POSTGRES_HOST', 'sba_postgres'),
|
||||||
password=os.environ.get('POSTGRES_PASSWORD', 'sba_dev_password_2024'),
|
port=int(os.environ.get('POSTGRES_PORT', '5432')),
|
||||||
host=os.environ.get('POSTGRES_HOST', 'sba_postgres'),
|
max_connections=20,
|
||||||
port=int(os.environ.get('POSTGRES_PORT', '5432')),
|
stale_timeout=300, # 5 minutes
|
||||||
max_connections=20,
|
timeout=0,
|
||||||
stale_timeout=300, # 5 minutes
|
autoconnect=True,
|
||||||
timeout=0,
|
autorollback=True # Automatically rollback failed transactions
|
||||||
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
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
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