tests-passed
This commit is contained in:
84
orm/draft.py
84
orm/draft.py
@@ -1,7 +1,8 @@
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy import JSON, Boolean, ForeignKey, Index, Integer, PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from auth.orm import Author
|
||||
from orm.base import BaseModel as Base
|
||||
@@ -11,45 +12,68 @@ from orm.topic import Topic
|
||||
class DraftTopic(Base):
|
||||
__tablename__ = "draft_topic"
|
||||
|
||||
id = None # type: ignore[misc]
|
||||
shout = Column(ForeignKey("draft.id"), primary_key=True, index=True)
|
||||
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
|
||||
main = Column(Boolean, nullable=True)
|
||||
draft: Mapped[int] = mapped_column(ForeignKey("draft.id"), index=True)
|
||||
topic: Mapped[int] = mapped_column(ForeignKey("topic.id"), index=True)
|
||||
main: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint(draft, topic),
|
||||
Index("idx_draft_topic_topic", "topic"),
|
||||
Index("idx_draft_topic_draft", "draft"),
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
||||
|
||||
class DraftAuthor(Base):
|
||||
__tablename__ = "draft_author"
|
||||
|
||||
id = None # type: ignore[misc]
|
||||
shout = Column(ForeignKey("draft.id"), primary_key=True, index=True)
|
||||
author = Column(ForeignKey("author.id"), primary_key=True, index=True)
|
||||
caption = Column(String, nullable=True, default="")
|
||||
draft: Mapped[int] = mapped_column(ForeignKey("draft.id"), index=True)
|
||||
author: Mapped[int] = mapped_column(ForeignKey(Author.id), index=True)
|
||||
caption: Mapped[str | None] = mapped_column(String, nullable=True, default="")
|
||||
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint(draft, author),
|
||||
Index("idx_draft_author_author", "author"),
|
||||
Index("idx_draft_author_draft", "draft"),
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
||||
|
||||
class Draft(Base):
|
||||
__tablename__ = "draft"
|
||||
# required
|
||||
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
|
||||
created_by = Column(ForeignKey("author.id"), nullable=False)
|
||||
community = Column(ForeignKey("community.id"), nullable=False, default=1)
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
created_at: Mapped[int] = mapped_column(Integer, nullable=False, default=lambda: int(time.time()))
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey(Author.id), nullable=False)
|
||||
community: Mapped[int] = mapped_column(ForeignKey("community.id"), nullable=False, default=1)
|
||||
|
||||
# optional
|
||||
layout = Column(String, nullable=True, default="article")
|
||||
slug = Column(String, unique=True)
|
||||
title = Column(String, nullable=True)
|
||||
subtitle = Column(String, nullable=True)
|
||||
lead = Column(String, nullable=True)
|
||||
body = Column(String, nullable=False, comment="Body")
|
||||
media = Column(JSON, nullable=True)
|
||||
cover = Column(String, nullable=True, comment="Cover image url")
|
||||
cover_caption = Column(String, nullable=True, comment="Cover image alt caption")
|
||||
lang = Column(String, nullable=False, default="ru", comment="Language")
|
||||
seo = Column(String, nullable=True) # JSON
|
||||
layout: Mapped[str | None] = mapped_column(String, nullable=True, default="article")
|
||||
slug: Mapped[str | None] = mapped_column(String, unique=True)
|
||||
title: Mapped[str | None] = mapped_column(String, nullable=True)
|
||||
subtitle: Mapped[str | None] = mapped_column(String, nullable=True)
|
||||
lead: Mapped[str | None] = mapped_column(String, nullable=True)
|
||||
body: Mapped[str] = mapped_column(String, nullable=False, comment="Body")
|
||||
media: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
|
||||
cover: Mapped[str | None] = mapped_column(String, nullable=True, comment="Cover image url")
|
||||
cover_caption: Mapped[str | None] = mapped_column(String, nullable=True, comment="Cover image alt caption")
|
||||
lang: Mapped[str] = mapped_column(String, nullable=False, default="ru", comment="Language")
|
||||
seo: Mapped[str | None] = mapped_column(String, nullable=True) # JSON
|
||||
|
||||
# auto
|
||||
updated_at = Column(Integer, nullable=True, index=True)
|
||||
deleted_at = Column(Integer, nullable=True, index=True)
|
||||
updated_by = Column(ForeignKey("author.id"), nullable=True)
|
||||
deleted_by = Column(ForeignKey("author.id"), nullable=True)
|
||||
authors = relationship(Author, secondary="draft_author")
|
||||
topics = relationship(Topic, secondary="draft_topic")
|
||||
updated_at: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
|
||||
deleted_at: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
|
||||
updated_by: Mapped[int | None] = mapped_column(ForeignKey(Author.id), nullable=True)
|
||||
deleted_by: Mapped[int | None] = mapped_column(ForeignKey(Author.id), nullable=True)
|
||||
authors = relationship(Author, secondary=DraftAuthor.__table__)
|
||||
topics = relationship(Topic, secondary=DraftTopic.__table__)
|
||||
|
||||
# shout/publication
|
||||
# Временно закомментировано для совместимости с тестами
|
||||
# shout: Mapped[int | None] = mapped_column(ForeignKey("shout.id"), nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_draft_created_by", "created_by"),
|
||||
Index("idx_draft_community", "community"),
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
Reference in New Issue
Block a user