rentease-backend/models/LoginLog.js

59 lines
1.2 KiB
JavaScript

const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const LoginLog = sequelize.define('LoginLog', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '日志ID'
},
userId: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '用户ID'
},
username: {
type: DataTypes.STRING(50),
allowNull: true,
comment: '用户名'
},
loginType: {
type: DataTypes.ENUM('login', 'logout'),
allowNull: false,
comment: '登录类型'
},
ip: {
type: DataTypes.STRING(50),
allowNull: true,
comment: 'IP地址'
},
userAgent: {
type: DataTypes.TEXT,
allowNull: true,
comment: '浏览器信息'
},
status: {
type: DataTypes.ENUM('success', 'fail'),
allowNull: false,
defaultValue: 'success',
comment: '登录状态'
},
message: {
type: DataTypes.STRING(255),
allowNull: true,
comment: '登录信息/失败原因'
},
createTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
comment: '创建时间'
}
}, {
tableName: 'login_logs',
timestamps: false,
comment: '登录日志表'
});
module.exports = LoginLog;