api / app /models /role.py
hanbinsite's picture
chore: initialize FastAPI project scaffold
32ddb29
Raw History Blame Contribute Delete
1.3 kB
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class Role(Base):
__tablename__ = "role"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(30), unique=True, nullable=False, comment="角色名称")
code: Mapped[str] = mapped_column(String(30), unique=True, nullable=False, comment="角色编码")
description: Mapped[str | None] = mapped_column(String(200), comment="角色描述")
is_builtin: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否内置角色")
status: Mapped[int] = mapped_column(Integer, default=1, comment="1=启用 0=禁用")
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
class AdminRole(Base):
__tablename__ = "admin_role"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
admin_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="管理员ID")
role_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="角色ID")