"""ORM model for custom skill ownership + publish state. Note: skill content lives on disk under ``skills/custom/{name}/``; this table only stores the metadata (owner, published flag, timestamps). The skill ``name`` doubles as the primary key because the filesystem path is already keyed by name, and we require global name uniqueness across all owners. """ from __future__ import annotations from datetime import UTC, datetime from sqlalchemy import Boolean, DateTime, String, Text from sqlalchemy.orm import Mapped, mapped_column from deerflow.persistence.base import Base class SkillRow(Base): __tablename__ = "skills" # Global unique name — must match the on-disk folder name under skills/custom/. # Hyphen-case or snake_case allowed; see deerflow.skills.validation. name: Mapped[str] = mapped_column(String(64), primary_key=True) owner_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True) published: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, index=True) # Human-authored long-form detail/introduction, editable by the skill owner # or an admin. Distinct from the skill ``description`` parsed from SKILL.md; # kept in the DB so admins can annotate built-in skills without rewriting # the shared on-disk SKILL.md file. detail: Mapped[str | None] = mapped_column(Text, nullable=True, default=None) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(UTC)) updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC))