File size: 1,640 Bytes
32ddb29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from datetime import datetime

from sqlalchemy import DateTime, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column

from app.database import Base


class Permission(Base):
    __tablename__ = "permission"

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    code: Mapped[str] = mapped_column(String(60), unique=True, nullable=False, comment="权限码")
    name: Mapped[str] = mapped_column(String(50), nullable=False, comment="权限名称")
    type: Mapped[str] = mapped_column(String(10), nullable=False, comment="menu/page/btn")
    parent_id: Mapped[int | None] = mapped_column(Integer, comment="父权限ID")
    path: Mapped[str | None] = mapped_column(String(200), comment="路由路径(仅menu)")
    component: Mapped[str | None] = mapped_column(String(200), comment="前端组件路径(仅menu)")
    redirect: Mapped[str | None] = mapped_column(String(200), comment="重定向路径(仅menu)")
    icon: Mapped[str | None] = mapped_column(String(50), comment="菜单图标(仅menu)")
    sort_order: Mapped[int] = mapped_column(Integer, default=0, comment="排序")
    status: Mapped[int] = mapped_column(Integer, default=1, comment="1=启用 0=禁用")
    created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())


class RolePermission(Base):
    __tablename__ = "role_permission"

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    role_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="角色ID")
    permission_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="权限ID")