user_local_model_permission.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """
  2. 用户本地模型权限ORM定义
  3. 定义用户对本地模型的访问权限关系
  4. """
  5. from datetime import datetime
  6. from sqlalchemy import Boolean, Column, Integer, String, DateTime, ForeignKey, Index
  7. from sqlalchemy.sql import func
  8. from app.database import Base
  9. class UserLocalModelPermission(Base):
  10. """
  11. 用户本地模型权限ORM类
  12. 存储用户对本地模型的访问权限设置
  13. """
  14. __tablename__ = "user_local_model_permission"
  15. # 主键
  16. id = Column(
  17. Integer,
  18. primary_key=True,
  19. autoincrement=True,
  20. comment="主键ID"
  21. )
  22. # 用户ID(外键关联users表)
  23. user_id = Column(
  24. String(50),
  25. ForeignKey("aigcspace.users.id", ondelete="CASCADE"),
  26. nullable=False,
  27. comment="用户ID"
  28. )
  29. # 模型ID(外键关联models表)
  30. model_id = Column(
  31. Integer,
  32. ForeignKey("aigcspace.models_new.id", ondelete="CASCADE"),
  33. nullable=False,
  34. comment="模型ID"
  35. )
  36. # 是否有权限访问
  37. has_access = Column(
  38. Boolean,
  39. nullable=False,
  40. default=False,
  41. comment="是否有权限访问"
  42. )
  43. # 创建时间
  44. created_at = Column(
  45. DateTime,
  46. nullable=False,
  47. server_default=func.now(),
  48. comment="创建时间"
  49. )
  50. # 更新时间
  51. updated_at = Column(
  52. DateTime,
  53. nullable=False,
  54. server_default=func.now(),
  55. onupdate=func.now(),
  56. comment="更新时间"
  57. )
  58. # 表级索引配置
  59. __table_args__ = (
  60. Index('idx_user_local_model_permission_user_id', 'user_id'),
  61. Index('idx_user_local_model_permission_model_id', 'model_id'),
  62. Index('idx_user_local_model_permission_unique', 'user_id', 'model_id', unique=True),
  63. {'schema': 'aigcspace', 'comment': '用户本地模型权限表'}
  64. )
  65. def __repr__(self):
  66. return f"<UserLocalModelPermission(id={self.id}, user_id='{self.user_id}', model_id={self.model_id}, has_access={self.has_access})>"