- Added SQLite database support with Alembic for migrations. - Implemented FastAPI for HTTP API to manage duties. - Updated configuration to include database URL and HTTP port. - Created entrypoint script for Docker to handle migrations and permissions. - Expanded command handlers to register users and display duties. - Developed a web application for calendar display of duties. - Included necessary Pydantic schemas and SQLAlchemy models for data handling. - Updated requirements.txt to include new dependencies for FastAPI and SQLAlchemy.
32 lines
853 B
Python
32 lines
853 B
Python
"""SQLAlchemy engine and session factory."""
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import Session, sessionmaker
|
|
|
|
from db.models import Base
|
|
|
|
_engine = None
|
|
_SessionLocal = None
|
|
|
|
|
|
def get_engine(database_url: str):
|
|
global _engine
|
|
if _engine is None:
|
|
_engine = create_engine(
|
|
database_url,
|
|
connect_args={"check_same_thread": False} if "sqlite" in database_url else {},
|
|
echo=False,
|
|
)
|
|
return _engine
|
|
|
|
|
|
def get_session_factory(database_url: str) -> sessionmaker[Session]:
|
|
global _SessionLocal
|
|
if _SessionLocal is None:
|
|
engine = get_engine(database_url)
|
|
_SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
return _SessionLocal
|
|
|
|
|
|
def get_session(database_url: str) -> Session:
|
|
return get_session_factory(database_url)()
|