import datetime as dt from sqlalchemy import ( BigInteger, DateTime, ForeignKey, func, ) from sqlalchemy.orm import Mapped, declarative_base, mapped_column Base = declarative_base() class User(Base): __tablename__ = "user" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) tg_id: Mapped[int] = mapped_column(BigInteger, unique=True, nullable=False) fullname: Mapped[str] = mapped_column() role: Mapped[str] = mapped_column(default="user") phone: Mapped[str] = mapped_column(nullable=True) class Event(Base): __tablename__ = "event" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) title: Mapped[str] = mapped_column() description: Mapped[str] = mapped_column(default="") start_date: Mapped[dt.date] = mapped_column(nullable=True) end_date: Mapped[dt.date] = mapped_column(nullable=True) class UserEvent(Base): __tablename__ = "user_event" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) user: Mapped[int] = mapped_column(ForeignKey("user.id")) event: Mapped[int] = mapped_column(ForeignKey("event.id")) date: Mapped[dt.date] = mapped_column( DateTime(timezone=True), server_default=func.now() ) status: Mapped[str] = mapped_column(default="not confirmed")