创建用户类和告警消息类

用户类 > 一对多 > 告警消息类

class User(Base):
    __tablename__ = 'user'
    __table_args__ = {
        'comment': '用户表',
        'mysql_collate': 'utf8_general_ci',
        'mysql_engine': 'InnoDB',
        'mysql_charset': 'utf8',
    }
    id = Column(INTEGER(11), primary_key=True)
    name = Column(VARCHAR(255), comment='用户名')
    account = Column(VARCHAR(255), comment='账号')
    passwd = Column(VARCHAR(255), comment='密码')
    phone = Column(VARCHAR(255), comment='联系方式')
    email = Column(VARCHAR(100), server_default=text("''"), comment='email')
    authority = Column(TINYINT(2), nullable=False, server_default=text("'0'"), comment='权限:0普通用户,1管理员')
    status = Column(TINYINT(2), nullable=False, server_default=text("'0'"), comment='启用:0开启,1关闭')
    notice = Column(TINYINT(2), server_default=text("'0'"), comment='通知:0开启,1关闭)')

class CaveatMess(Base):
    __tablename__ = 'caveat_mess'
    __table_args__ = {
        'comment': '告警消息表',
        'mysql_collate': 'utf8_general_ci',
        'mysql_engine': 'InnoDB',
        'mysql_charset': 'utf8',
    }
    id = Column(INTEGER(11), primary_key=True)
    user_id = Column(ForeignKey('user.id'))
    caveat_type = Column(TINYINT(2), nullable=False, server_default=text("'0'"), comment='告警类型: 0任务故障,1节点故障,2引擎故障')
    caveat_title = Column(VARCHAR(255), comment='告警标题')
    caveat_text = Column(VARCHAR(255), comment='告警内容')
    caveat_time = Column(DateTime, comment='告警时间(Y-m-d H:i:s)')
    send_status = Column(TINYINT(2), server_default=text("'0'"), comment='发送状态: 0未发送,1已发送,2待发送)')
    send_time = Column(DateTime, comment='发送时间(Y-m-d H:i:s)')

主要代码

user_id = Column(ForeignKey('user.id'))