Files
eamco_service/database.py
Edwin Eames 07865480c7 Initial commit: Add EAMCO Service API
- Add FastAPI service for managing oil delivery services
- Implement service scheduling and management endpoints
- Add customer service history tracking
- Include database models for services, customers, and auto-delivery
- Add authentication and authorization middleware
- Configure Docker support for local, dev, and prod environments
- Add comprehensive .gitignore for Python projects
2026-02-01 19:02:13 -05:00

43 lines
921 B
Python

from sqlalchemy import create_engine
from sqlalchemy.engine import URL
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import declarative_base
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_DBNAME,
port=ApplicationConfig.POSTGRES_PORT
)
engine = create_engine(
url,
pool_pre_ping=True,
pool_size=5,
max_overflow=10,
pool_recycle=3600,
)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Keep the global session for backwards compatibility
session = Session()
Base = declarative_base()
Base.metadata.create_all(engine)
def get_db():
db = Session()
try:
yield db
finally:
db.close()