| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- """
- 用户本地模型权限ORM定义
- 定义用户对本地模型的访问权限关系
- """
- from datetime import datetime
- from sqlalchemy import Boolean, Column, Integer, String, DateTime, ForeignKey, Index
- from sqlalchemy.sql import func
- from app.database import Base
- class UserLocalModelPermission(Base):
- """
- 用户本地模型权限ORM类
- 存储用户对本地模型的访问权限设置
- """
- __tablename__ = "user_local_model_permission"
- # 主键
- id = Column(
- Integer,
- primary_key=True,
- autoincrement=True,
- comment="主键ID"
- )
- # 用户ID(外键关联users表)
- user_id = Column(
- String(50),
- ForeignKey("aigcspace.users.id", ondelete="CASCADE"),
- nullable=False,
- comment="用户ID"
- )
- # 模型ID(外键关联models表)
- model_id = Column(
- Integer,
- ForeignKey("aigcspace.models_new.id", ondelete="CASCADE"),
- nullable=False,
- comment="模型ID"
- )
- # 是否有权限访问
- has_access = Column(
- Boolean,
- nullable=False,
- default=False,
- comment="是否有权限访问"
- )
- # 创建时间
- created_at = Column(
- DateTime,
- nullable=False,
- server_default=func.now(),
- comment="创建时间"
- )
- # 更新时间
- updated_at = Column(
- DateTime,
- nullable=False,
- server_default=func.now(),
- onupdate=func.now(),
- comment="更新时间"
- )
- # 表级索引配置
- __table_args__ = (
- Index('idx_user_local_model_permission_user_id', 'user_id'),
- Index('idx_user_local_model_permission_model_id', 'model_id'),
- Index('idx_user_local_model_permission_unique', 'user_id', 'model_id', unique=True),
- {'schema': 'aigcspace', 'comment': '用户本地模型权限表'}
- )
- def __repr__(self):
- return f"<UserLocalModelPermission(id={self.id}, user_id='{self.user_id}', model_id={self.model_id}, has_access={self.has_access})>"
|