add database

This commit is contained in:
2025-09-18 17:09:08 +03:00
parent 8ec1f88615
commit aafa91fb43
5 changed files with 20 additions and 23 deletions

39
app/db/models.py Normal file
View File

@@ -0,0 +1,39 @@
import datetime as dt
from sqlalchemy import (
BigInteger,
DateTime,
ForeignKey,
func,
)
from sqlalchemy.orm import Mapped, mapped_column
from app.db.database import Base
class User(Base):
__tablename__ = "user"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
fullname: Mapped[str] = mapped_column()
tg_id: Mapped[int] = mapped_column(BigInteger)
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")