add contacts and address to database
This commit is contained in:
@@ -13,14 +13,15 @@ class Base(DeclarativeBase):
|
||||
class User(Base):
|
||||
__tablename__ = "user"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
tg_id: Mapped[int] = mapped_column(BigInteger, unique=True)
|
||||
tg_id: Mapped[int] = mapped_column(BigInteger, nullable=True, unique=True)
|
||||
fullname: Mapped[str] = mapped_column()
|
||||
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")
|
||||
addresses = relationship("Address", back_populates="user_rel")
|
||||
contacts = relationship("Contact", back_populates="user_rel")
|
||||
|
||||
|
||||
class Event(Base):
|
||||
@@ -34,7 +35,6 @@ class Event(Base):
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
is_active: Mapped[bool] = mapped_column(default=True)
|
||||
|
||||
user_events = relationship("UserEvent", back_populates="event_rel")
|
||||
|
||||
|
||||
@@ -69,4 +69,32 @@ class Certificate(Base):
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
course_id: Mapped[int] = mapped_column(ForeignKey("course.id"))
|
||||
date: Mapped[dt.datetime] = mapped_column()
|
||||
|
||||
course_rel = relationship("Course", back_populates="certificates")
|
||||
user_rel = relationship("User", back_populates="certificates")
|
||||
|
||||
__table_args__ = (UniqueConstraint("user_id", "course_id", name="uq_user_course"),)
|
||||
|
||||
|
||||
class Address(Base):
|
||||
__tablename__ = "address"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
country: Mapped[str] = mapped_column()
|
||||
region: Mapped[str] = mapped_column()
|
||||
locality: Mapped[str] = mapped_column()
|
||||
street_address: Mapped[str] = mapped_column()
|
||||
extended_address: Mapped[str] = mapped_column()
|
||||
postal_code: Mapped[str] = mapped_column()
|
||||
|
||||
user_rel = relationship("User", back_populates="addresses")
|
||||
|
||||
|
||||
class Contact(Base):
|
||||
__tablename__ = "contact"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
type: Mapped[str] = mapped_column()
|
||||
value: Mapped[str] = mapped_column()
|
||||
|
||||
user_rel = relationship("User", back_populates="contacts")
|
||||
|
||||
Reference in New Issue
Block a user