from __future__ import annotations import uuid from datetime import datetime from sqlalchemy import DateTime, String, UniqueConstraint, func from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import Mapped, mapped_column from app.db.base_class import Base class ApiEndpointRegistry(Base): """API端点注册表 存储系统中所有已注册的API端点及其元数据。 用于权限管理、文档生成和权限初始化。 """ __tablename__ = "api_endpoint_registries" __table_args__ = ( UniqueConstraint("endpoint_key", name="uq_api_endpoint_registry_key"), ) id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) endpoint_key: Mapped[str] = mapped_column(String(100), nullable=False, unique=True) method: Mapped[str] = mapped_column(String(10), nullable=False) path: Mapped[str] = mapped_column(String(200), nullable=False) module: Mapped[str] = mapped_column(String(80), nullable=False) action: Mapped[str] = mapped_column(String(20), nullable=False) description: Mapped[str] = mapped_column(String(500), nullable=True) default_roles: Mapped[str] = mapped_column(String(200), nullable=False) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())