30 lines
1.5 KiB
Python
30 lines
1.5 KiB
Python
from sqlalchemy import String, Integer, SmallInteger, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy import Enum, JSON
|
|
from .base import Base, TimestampMixin, MYSQL_TABLE_ARGS
|
|
from .enums import PermissionTypeEnum, StatusEnum
|
|
|
|
|
|
class Permission(Base, TimestampMixin):
|
|
__tablename__ = "sys_permission"
|
|
__table_args__ = MYSQL_TABLE_ARGS
|
|
|
|
perm_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
parent_id: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
code: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
|
|
perm_type: Mapped[PermissionTypeEnum] = mapped_column(
|
|
Enum(PermissionTypeEnum, native_enum=False, values_callable=lambda x: [e.value for e in x]),
|
|
nullable=False,
|
|
)
|
|
level: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
path: Mapped[str | None] = mapped_column(String(255))
|
|
icon: Mapped[str | None] = mapped_column(String(100))
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
|
is_visible: Mapped[int] = mapped_column(SmallInteger, default=1, nullable=False)
|
|
status: Mapped[int] = mapped_column(Integer, default=StatusEnum.ENABLED, nullable=False)
|
|
description: Mapped[str | None] = mapped_column(Text)
|
|
meta: Mapped[dict | None] = mapped_column(JSON)
|
|
|
|
roles = relationship("RolePermission", back_populates="permission", cascade="all, delete-orphan")
|