update database
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
import datetime as dt
|
||||
|
||||
from sqlalchemy import (
|
||||
BigInteger,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, declarative_base, mapped_column
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, UniqueConstraint, func
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
||||
|
||||
Base = declarative_base()
|
||||
from .enums import EventUserStatus, UserRole
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
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)
|
||||
tg_id: Mapped[int] = mapped_column(BigInteger, unique=True)
|
||||
fullname: Mapped[str] = mapped_column()
|
||||
role: Mapped[str] = mapped_column(default="user")
|
||||
role: Mapped[str] = mapped_column(default=UserRole.USER.value)
|
||||
phone: Mapped[str] = mapped_column(nullable=True)
|
||||
address: Mapped[str] = mapped_column(nullable=True)
|
||||
|
||||
events = relationship("UserEvent", back_populates="user_rel")
|
||||
certificates = relationship("Certificate", back_populates="user_rel")
|
||||
|
||||
|
||||
class Event(Base):
|
||||
@@ -25,16 +28,45 @@ class Event(Base):
|
||||
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)
|
||||
start_date: Mapped[dt.datetime] = mapped_column(nullable=True)
|
||||
end_date: Mapped[dt.datetime] = mapped_column(nullable=True)
|
||||
created_at: Mapped[dt.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
is_active: Mapped[bool] = mapped_column(default=True)
|
||||
|
||||
user_events = relationship("UserEvent", back_populates="event_rel")
|
||||
|
||||
|
||||
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(
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
event_id: Mapped[int] = mapped_column(ForeignKey("event.id"))
|
||||
date: Mapped[dt.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
status: Mapped[str] = mapped_column(default="not confirmed")
|
||||
status: Mapped[str] = mapped_column(default=EventUserStatus.NOT_CONFIRMED.value)
|
||||
|
||||
user_rel = relationship("User", back_populates="events")
|
||||
event_rel = relationship("Event", back_populates="user_events")
|
||||
|
||||
__table_args__ = (UniqueConstraint("user_id", "event_id", name="uq_user_event"),)
|
||||
|
||||
|
||||
class Course(Base):
|
||||
__tablename__ = "course"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
title: Mapped[str] = mapped_column()
|
||||
description: Mapped[str] = mapped_column(nullable=True)
|
||||
|
||||
certificates = relationship("Certificate", back_populates="course_rel")
|
||||
|
||||
|
||||
class Certificate(Base):
|
||||
__tablename__ = "certificate"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
course_id: Mapped[int] = mapped_column(ForeignKey("course.id"))
|
||||
date: Mapped[dt.datetime] = mapped_column()
|
||||
__table_args__ = (UniqueConstraint("user_id", "course_id", name="uq_user_course"),)
|
||||
|
||||
Reference in New Issue
Block a user