"""Persistent organization and constrained executable skill catalog.""" from sqlalchemy import String, Integer, JSON, Text, ForeignKeyConstraint from sqlalchemy.orm import Mapped, mapped_column from KnowledgeService.models import Base class Employee(Base): __tablename__='org_employee' tenant:Mapped[str]=mapped_column(String(80),primary_key=True) user_id:Mapped[str]=mapped_column(String(80),primary_key=True) name:Mapped[str]=mapped_column(String(120)) status:Mapped[str]=mapped_column(String(24),default='enabled') class Group(Base): __tablename__='org_group' tenant:Mapped[str]=mapped_column(String(80),primary_key=True) id:Mapped[str]=mapped_column(String(80),primary_key=True) name:Mapped[str]=mapped_column(String(120)) description:Mapped[str]=mapped_column(Text,default='') revision:Mapped[int]=mapped_column(Integer,default=1) class Membership(Base): __tablename__='org_membership' tenant:Mapped[str]=mapped_column(String(80),primary_key=True) group_id:Mapped[str]=mapped_column(String(80),primary_key=True) user_id:Mapped[str]=mapped_column(String(80),primary_key=True) role:Mapped[str]=mapped_column(String(24),default='member') __table_args__=(ForeignKeyConstraint(['tenant','group_id'],['org_group.tenant','org_group.id']), ForeignKeyConstraint(['tenant','user_id'],['org_employee.tenant','org_employee.user_id'])) class GroupGrant(Base): __tablename__='org_group_kb_grant' tenant:Mapped[str]=mapped_column(String(80),primary_key=True) group_id:Mapped[str]=mapped_column(String(80),primary_key=True) base_id:Mapped[str]=mapped_column(String(80),primary_key=True) __table_args__=(ForeignKeyConstraint(['tenant','group_id'],['org_group.tenant','org_group.id']), ForeignKeyConstraint(['tenant','base_id'],['kb_base.tenant','kb_base.id'])) class OrganizationAudit(Base): __tablename__='org_audit' id:Mapped[str]=mapped_column(String(80),primary_key=True) tenant:Mapped[str]=mapped_column(String(80),index=True) actor:Mapped[str]=mapped_column(String(80)) group_id:Mapped[str]=mapped_column(String(80)) action:Mapped[str]=mapped_column(String(40)) detail:Mapped[dict]=mapped_column(JSON) created_at:Mapped[str]=mapped_column(String(40)) class Program(Base): __tablename__='skill_program' id:Mapped[str]=mapped_column(String(80),primary_key=True) tenant:Mapped[str]=mapped_column(String(80),index=True) owner:Mapped[str]=mapped_column(String(80),index=True) workspace:Mapped[str]=mapped_column(String(80),index=True) request_key:Mapped[str]=mapped_column(String(128)) fingerprint:Mapped[str]=mapped_column(String(64)) name:Mapped[str]=mapped_column(String(120)) description:Mapped[str]=mapped_column(Text) code:Mapped[str]=mapped_column(Text) tests:Mapped[list]=mapped_column(JSON) report:Mapped[dict]=mapped_column(JSON) status:Mapped[str]=mapped_column(String(24),default='draft') revision:Mapped[int]=mapped_column(Integer,default=1) operation_id:Mapped[str|None]=mapped_column(String(80)) created_at:Mapped[str]=mapped_column(String(40)) class PromptSkill(Base): __tablename__='skill_prompt' tenant:Mapped[str]=mapped_column(String(80),primary_key=True) id:Mapped[str]=mapped_column(String(80),primary_key=True) owner:Mapped[str]=mapped_column(String(80)) revision:Mapped[int]=mapped_column(Integer) body:Mapped[dict]=mapped_column(JSON) class PromptSkillVersion(Base): __tablename__='skill_prompt_version' tenant:Mapped[str]=mapped_column(String(80),primary_key=True) skill_id:Mapped[str]=mapped_column(String(80),primary_key=True) version:Mapped[int]=mapped_column(Integer,primary_key=True) body:Mapped[dict]=mapped_column(JSON) __table_args__=(ForeignKeyConstraint(['tenant','skill_id'],['skill_prompt.tenant','skill_prompt.id']),)