- Introduced a new configuration file `.cursorrules` to define coding standards, error handling, testing requirements, and project-specific guidelines. - Refactored `config.py` to implement a `Settings` dataclass for better management of environment variables, improving testability and maintainability. - Updated the import duty schedule handler to utilize session management with `session_scope`, ensuring proper database session handling. - Enhanced the import service to streamline the duty schedule import process, improving code organization and readability. - Added new service layer functions to encapsulate business logic related to group duty pinning and duty schedule imports. - Updated README documentation to reflect the new configuration structure and improved import functionality.
42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
"""Database layer: SQLAlchemy models, Pydantic schemas, repository, init."""
|
|
|
|
from db.models import Base, User, Duty
|
|
from db.schemas import UserCreate, UserInDb, DutyCreate, DutyInDb, DutyWithUser
|
|
from db.session import get_engine, get_session_factory, get_session, session_scope
|
|
from db.repository import (
|
|
delete_duties_in_range,
|
|
get_or_create_user,
|
|
get_or_create_user_by_full_name,
|
|
get_duties,
|
|
insert_duty,
|
|
set_user_phone,
|
|
)
|
|
|
|
__all__ = [
|
|
"Base",
|
|
"User",
|
|
"Duty",
|
|
"UserCreate",
|
|
"UserInDb",
|
|
"DutyCreate",
|
|
"DutyInDb",
|
|
"DutyWithUser",
|
|
"get_engine",
|
|
"get_session_factory",
|
|
"get_session",
|
|
"session_scope",
|
|
"delete_duties_in_range",
|
|
"get_or_create_user",
|
|
"get_or_create_user_by_full_name",
|
|
"get_duties",
|
|
"insert_duty",
|
|
"set_user_phone",
|
|
"init_db",
|
|
]
|
|
|
|
|
|
def init_db(database_url: str) -> None:
|
|
"""Create tables from metadata (Alembic migrations handle schema in production)."""
|
|
engine = get_engine(database_url)
|
|
Base.metadata.create_all(bind=engine)
|