from __future__ import annotations import uuid from sqlalchemy import ForeignKey, Index, Text from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import Mapped, mapped_column from . import Base class NoteLink(Base): """A [[wiki-link]] from a source note to a target title (normalized). Resolved to a target note by matching target_norm against lower(trim(note.title)).""" __tablename__ = "note_links" __table_args__ = (Index("ix_note_links_target", "target_norm"),) id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) source_id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), ForeignKey("notes.id", ondelete="CASCADE"), nullable=False ) target_norm: Mapped[str] = mapped_column(Text(), nullable=False)