This commit is contained in:
@@ -6,6 +6,21 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from orm.base import BaseModel as Base
|
||||
|
||||
|
||||
class Collection(Base):
|
||||
__tablename__ = "collection"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
slug: Mapped[str] = mapped_column(String, unique=True)
|
||||
title: Mapped[str] = mapped_column(String, nullable=False, comment="Title")
|
||||
body: Mapped[str | None] = mapped_column(String, nullable=True, comment="Body")
|
||||
pic: Mapped[str | None] = mapped_column(String, nullable=True, comment="Picture")
|
||||
created_at: Mapped[int] = mapped_column(Integer, default=lambda: int(time.time()))
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("author.id"), comment="Created By")
|
||||
published_at: Mapped[int] = mapped_column(Integer, default=lambda: int(time.time()))
|
||||
|
||||
created_by_author = relationship("Author", foreign_keys=[created_by])
|
||||
|
||||
|
||||
class ShoutCollection(Base):
|
||||
__tablename__ = "shout_collection"
|
||||
|
||||
@@ -20,18 +35,3 @@ class ShoutCollection(Base):
|
||||
Index("idx_shout_collection_collection", "collection"),
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
||||
|
||||
class Collection(Base):
|
||||
__tablename__ = "collection"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
slug: Mapped[str] = mapped_column(String, unique=True)
|
||||
title: Mapped[str] = mapped_column(String, nullable=False, comment="Title")
|
||||
body: Mapped[str | None] = mapped_column(String, nullable=True, comment="Body")
|
||||
pic: Mapped[str | None] = mapped_column(String, nullable=True, comment="Picture")
|
||||
created_at: Mapped[int] = mapped_column(Integer, default=lambda: int(time.time()))
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("author.id"), comment="Created By")
|
||||
published_at: Mapped[int] = mapped_column(Integer, default=lambda: int(time.time()))
|
||||
|
||||
created_by_author = relationship("Author", foreign_keys=[created_by])
|
||||
|
||||
@@ -64,8 +64,8 @@ def create_all_tables() -> None:
|
||||
notification.Notification, # Зависит от Author
|
||||
notification.NotificationSeen, # Зависит от Notification
|
||||
collection.Collection, # Зависит от Author
|
||||
collection.ShoutCollection, # Зависит от Collection и Shout
|
||||
invite.Invite, # Зависит от Author и Shout
|
||||
collection.ShoutCollection, # Зависит от Collection и Shout
|
||||
]
|
||||
|
||||
with local_session() as session:
|
||||
|
||||
Reference in New Issue
Block a user