58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from datetime import datetime
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from sqlalchemy import String, Text, Integer, DateTime, Index, func
|
|
from models.base import Base
|
|
|
|
|
|
class SourceContent(Base):
|
|
__tablename__ = "t_source_content"
|
|
|
|
id: Mapped[int] = mapped_column(
|
|
Integer,
|
|
primary_key=True,
|
|
autoincrement=True,
|
|
comment="自动递增的唯一内容ID"
|
|
)
|
|
|
|
link: Mapped[str] = mapped_column(
|
|
String(2048),
|
|
nullable=False,
|
|
index=True,
|
|
comment="链接"
|
|
)
|
|
|
|
platform: Mapped[str] = mapped_column(
|
|
String(32),
|
|
nullable=False,
|
|
comment="平台"
|
|
)
|
|
|
|
content: Mapped[str | None] = mapped_column(
|
|
Text,
|
|
nullable=True,
|
|
comment="内容"
|
|
)
|
|
|
|
create_time: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
comment="创建时间"
|
|
)
|
|
|
|
update_time: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
onupdate=func.now(),
|
|
nullable=False,
|
|
comment="更新时间"
|
|
)
|
|
|
|
# ——可选优化:添加 项目 + 主题 联合唯一索引——
|
|
__table_args__ = (
|
|
Index("link", "link", unique=True),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<SourceContent id={self.id} link={self.link!r} platform={self.platform!r}>"
|