"""代码符号引用关系模型。""" from __future__ import annotations from typing import Any, Optional from sqlalchemy import ForeignKey, Integer, VARCHAR, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from .base import Base from .types import JSONB class SymbolReference(Base): __tablename__ = "symbol_references" __table_args__ = ( UniqueConstraint( "tenant_id", "file_path", "relation_type", "target_symbol_name", "start_line", "source_symbol_id", name="uq_symbol_references_tenant_file_relation_target_line_source", ), ) id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) source_symbol_id: Mapped[Optional[int]] = mapped_column( Integer, ForeignKey("symbol_definitions.id", ondelete="CASCADE"), nullable=True, index=True, ) file_path: Mapped[str] = mapped_column(VARCHAR(600), nullable=False, index=True) relation_type: Mapped[str] = mapped_column(VARCHAR(32), nullable=False, index=True) target_symbol_name: Mapped[str] = mapped_column(VARCHAR(255), nullable=False, index=True) target_qualified_name: Mapped[Optional[str]] = mapped_column(VARCHAR(700), nullable=True, index=True) start_line: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, index=True) end_line: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) payload: Mapped[Optional[Any]] = mapped_column(JSONB, nullable=True)