Files
duty-teller/db/__init__.py
Nikolay Tatarinov 4e6756025d Enhance database initialization and improve command handling
- Added `__all__` declaration in `db/__init__.py` for better module export management.
- Simplified command text formatting in `handlers/commands.py` for improved readability.
- Refactored error handler function signature in `handlers/errors.py` for better code style.
- Introduced comprehensive tests for API duties and Telegram authentication in new test files.
2026-02-17 20:05:49 +03:00

31 lines
826 B
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
from db.repository import get_or_create_user, get_duties, insert_duty
__all__ = [
"Base",
"User",
"Duty",
"UserCreate",
"UserInDb",
"DutyCreate",
"DutyInDb",
"DutyWithUser",
"get_engine",
"get_session_factory",
"get_session",
"get_or_create_user",
"get_duties",
"insert_duty",
"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)