from app.models.database import db
from datetime import datetime

# 这是权限表 model
class Permission(db.Model):
    __tablename__ = 'permissions'

    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(64), unique=True, nullable=False, comment='权限代码，用于系统识别')
    name = db.Column(db.String(64), nullable=False, comment='权限名称，用于界面显示')
    description = db.Column(db.String(255), comment='权限描述，说明权限用途')

# 角色-权限 关联表（辅助对象模式，方便ORM关系管理）
class RolePermission(db.Model):
    __tablename__ = 'role_permissions'

    role_id = db.Column(db.Integer, db.ForeignKey('roles.id', ondelete='CASCADE'), primary_key=True, comment='角色ID，关联roles表')
    permission_id = db.Column(db.Integer, db.ForeignKey('permissions.id', ondelete='CASCADE'), primary_key=True, comment='权限ID，关联permissions表')
    created_at = db.Column(db.DateTime, default=datetime.now, comment='权限分配时间')

