from typing import Optional from datetime import datetime, timezone from sqlalchemy import Column, String, Text, Integer, Float, DateTime, Boolean, ForeignKey, JSON, func from sqlalchemy.orm import Mapped, mapped_column from app.models.user import Base class KnowledgePoint(Base): __tablename__ = "knowledge_points" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) point_id: Mapped[str] = mapped_column(String(64), unique=True, nullable=False, index=True) subject: Mapped[str] = mapped_column(String(64), nullable=False, index=True) chapter_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True) chapter_name: Mapped[str] = mapped_column(String(256)) title: Mapped[str] = mapped_column(String(512), nullable=False) content: Mapped[str] = mapped_column(Text, nullable=False) difficulty: Mapped[int] = mapped_column(default=1) # 1-5 frequency: Mapped[Optional[str]] = mapped_column(String(16)) # 高频/中频/低频/未考 related_drugs: Mapped[Optional[list]] = mapped_column(JSON) source: Mapped[Optional[str]] = mapped_column(Text) vector_id: Mapped[Optional[str]] = mapped_column(String(128), index=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now() ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now() )