- Fix critical NameError in database.py by restoring Session factory - Refactor payment_service.py and crud.py to use shared constants.py and utils.py - Deduplicate state mapping and input sanitization logic - Move transaction amount calculation logic from CRUD to Router layer - Enforce type safety in schemas using IntEnum for TransactionType/Status - Move capture endpoint from transaction.py to payment.py (now /payments/capture) - Update create_customer_profile signature for clarity
40 lines
1003 B
Python
40 lines
1003 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.engine import URL
|
|
from config import load_config
|
|
|
|
|
|
ApplicationConfig = load_config()
|
|
|
|
|
|
url = URL.create(
|
|
drivername="postgresql",
|
|
username=ApplicationConfig.POSTGRES_USERNAME,
|
|
password=ApplicationConfig.POSTGRES_PW,
|
|
host=ApplicationConfig.POSTGRES_SERVER,
|
|
database=ApplicationConfig.POSTGRES_DBNAME00,
|
|
port=ApplicationConfig.POSTGRES_PORT
|
|
)
|
|
|
|
engine = create_engine(
|
|
url,
|
|
pool_pre_ping=True, # Verify connections before use
|
|
pool_size=5, # Maintain 5 connections in pool
|
|
max_overflow=10, # Allow 10 additional connections when busy
|
|
pool_recycle=3600, # Recycle connections after 1 hour
|
|
)
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_db():
|
|
db = Session()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|