role.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. from sqlalchemy import Integer, Column, String, DateTime, Text, UniqueConstraint, Enum
  5. from core.config import settings
  6. from db import BaseORMModel
  7. from common.enums import PlatformEnum, MethodEnum
  8. class Role(BaseORMModel):
  9. """
  10. 角色表
  11. """
  12. __tablename__ = "roles"
  13. __table_args__ = (UniqueConstraint("name", name="uix_roles_name"),)
  14. id = Column(Integer, primary_key=True, autoincrement=True, comment="角色ID")
  15. name = Column(String(128), nullable=False, comment="角色名称")
  16. remark = Column(String(255), default="", comment="备注")
  17. platform = Column(Enum(PlatformEnum), comment="平台类型")
  18. permission_codes = Column(Text, default="", comment="权限集合")
  19. permission_names = Column(Text, default="", comment="权限集合名称")
  20. creator_id = Column(Integer, default=1, comment="创建人ID")
  21. creator_name = Column(String(32), default=settings.ADMIN_USERNAME, comment="创建人名称")
  22. created_at = Column(DateTime, default=datetime.datetime.now)
  23. editor_id = Column(Integer, default=1, comment="最后编辑人ID")
  24. editor_name = Column(String(32), default=settings.ADMIN_USERNAME, comment="最后编辑人名称")
  25. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  26. class Permission(BaseORMModel):
  27. """权限表
  28. """
  29. __tablename__ = "permissions"
  30. __table_args__ = (UniqueConstraint("name", name="uix_permissions_name"),)
  31. id = Column(Integer, primary_key=True, autoincrement=True)
  32. name = Column(String(128), nullable=False, comment="权限名称")
  33. codename = Column(String(255), default="", comment="权限代码")
  34. module = Column(String(255), default="", comment="主模块")
  35. remark = Column(String(255), default="", comment="备注")
  36. api = Column(String(255), default="", comment="API接口")
  37. method = Column(Enum(MethodEnum), default=MethodEnum.GET, comment="接口方法")
  38. platform = Column(Enum(PlatformEnum), nullable=False, comment="平台类型")
  39. order = Column(Integer, default=0, comment="排序字段")