39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
"""
|
||
角色模型
|
||
"""
|
||
from sqlalchemy import Column, BigInteger, String, DateTime, SmallInteger
|
||
from sqlalchemy.sql import func
|
||
from app.core.database import Base
|
||
|
||
|
||
class Role(Base):
|
||
"""角色表模型"""
|
||
|
||
__tablename__ = "roles"
|
||
|
||
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="角色ID")
|
||
role_name = Column(String(50), nullable=False, unique=True, comment="角色名称")
|
||
role_code = Column(String(50), nullable=False, unique=True, index=True, comment="角色编码")
|
||
description = Column(String(255), comment="角色描述")
|
||
status = Column(SmallInteger, default=1, index=True, comment="状态:0-禁用 1-启用")
|
||
is_system = Column(SmallInteger, default=0, comment="是否系统角色:0-否 1-是")
|
||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
||
|
||
def __repr__(self):
|
||
return f"<Role(id={self.id}, role_code='{self.role_code}')>"
|
||
|
||
|
||
class UserRole(Base):
|
||
"""用户角色关联表模型"""
|
||
|
||
__tablename__ = "user_roles"
|
||
|
||
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="关联ID")
|
||
user_id = Column(BigInteger, nullable=False, index=True, comment="用户ID")
|
||
role_id = Column(BigInteger, nullable=False, index=True, comment="角色ID")
|
||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||
|
||
def __repr__(self):
|
||
return f"<UserRole(user_id={self.user_id}, role_id={self.role_id})>"
|