fix/various fixes

This commit is contained in:
Kevin
2026-03-20 15:15:35 +08:00
parent 7f57f96c25
commit 7317bf10cd
112 changed files with 3790 additions and 2242 deletions

View File

@@ -36,15 +36,12 @@ class Chapter(Base):
is_new = Column(Boolean, default=True)
is_active = Column(Boolean, default=True)
source_segments = Column(JSON, nullable=True)
# story-backed 章节story 变更后标 True由 Celery 重组 canonical_markdown
markdown_compose_dirty = Column(Boolean, default=False, nullable=False)
markdown_composed_at = Column(DateTime(timezone=True), nullable=True)
user = relationship("User", back_populates="chapters")
book = relationship("Book", back_populates="chapters")
sections = relationship(
"ChapterSection",
back_populates="chapter",
order_by="ChapterSection.order_index",
cascade="all, delete-orphan",
)
images = relationship(
"MemoirImage",
back_populates="chapter",
@@ -74,31 +71,6 @@ class Chapter(Base):
)
class ChapterSection(Base):
__tablename__ = "chapter_sections"
id = Column(String, primary_key=True)
chapter_id = Column(
String, ForeignKey("chapters.id", ondelete="CASCADE"), nullable=False
)
order_index = Column(Integer, nullable=False)
content = Column(Text, nullable=False)
image_id = Column(
String, ForeignKey("memoir_images.id", ondelete="SET NULL"), nullable=True
)
updated_at = Column(DateTime(timezone=True), default=utc_now, onupdate=utc_now)
chapter = relationship("Chapter", back_populates="sections")
image_record = relationship(
"MemoirImage",
back_populates="section",
uselist=False,
foreign_keys="ChapterSection.image_id",
cascade="all, delete-orphan",
single_parent=True,
)
class MemoirImage(Base):
__tablename__ = "memoir_images"
@@ -106,9 +78,6 @@ class MemoirImage(Base):
chapter_id = Column(
String, ForeignKey("chapters.id", ondelete="CASCADE"), nullable=False
)
section_id = Column(
String, ForeignKey("chapter_sections.id", ondelete="CASCADE"), nullable=True
)
order_index = Column(Integer, nullable=False, default=0)
placeholder = Column(Text, nullable=True)
description = Column(Text, nullable=True)
@@ -125,11 +94,6 @@ class MemoirImage(Base):
updated_at = Column(DateTime(timezone=True), default=utc_now, onupdate=utc_now)
chapter = relationship("Chapter", back_populates="images")
section = relationship(
"ChapterSection",
back_populates="image_record",
foreign_keys="ChapterSection.image_id",
)
class ChapterVersion(Base):