Files

30 lines
1.4 KiB
Python

from datetime import datetime
from sqlalchemy import CheckConstraint, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.db.session import Base
from app.models.catalog import Versioned
class KnowledgeItem(Versioned, Base):
__tablename__ = "knowledge_items"
__table_args__ = (
CheckConstraint(
"verification_status IN ('pending', 'verified', 'rejected')",
name="ck_knowledge_verification_status",
),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
title: Mapped[str] = mapped_column(String(250), nullable=False, index=True)
category: Mapped[str] = mapped_column(String(80), nullable=False, default="未分类")
content: Mapped[str] = mapped_column(Text, nullable=False)
source_url: Mapped[str | None] = mapped_column(String(1000), nullable=True)
verification_status: Mapped[str] = mapped_column(String(30), nullable=False, default="pending")
source_id: Mapped[int | None] = mapped_column(ForeignKey("sources.id"), index=True)
document_id: Mapped[int | None] = mapped_column(ForeignKey("documents.id"), index=True)
collected_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
reviewer: Mapped[str | None] = mapped_column(String(100))
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
verification_notes: Mapped[str | None] = mapped_column(Text)