from sqlalchemy import Column, Text, Integer, String, DateTime, ForeignKey from db.models import Base import datetime class MarkdownPatch(Base): """A markdown 'patch card' attached to a parent markdown document. Its content is plain markdown text rendered below the parent's body. Created/updated by admin|creator, deleted by admin; visibility is inherited from the parent markdown (enforced in the API layer). """ __tablename__ = 'markdown_patch' id = Column(Integer, primary_key=True) markdown_id = Column( Integer, ForeignKey('markdown.id'), nullable=False, index=True ) title = Column(String(255), nullable=True) content = Column(Text, nullable=False) order = Column(Integer, default=0) created_at = Column(DateTime, default=lambda: datetime.datetime.now(datetime.UTC)) updated_at = Column( DateTime, default=lambda: datetime.datetime.now(datetime.UTC), onupdate=lambda: datetime.datetime.now(datetime.UTC), ) def to_dict(self): return { 'id': self.id, 'markdown_id': self.markdown_id, 'title': self.title, 'content': self.content, 'order': self.order, 'created_at': self.created_at, 'updated_at': self.updated_at, }