rentease-backend-new/models/User.js

98 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2026-04-20 06:43:09 +00:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const User = sequelize.define('User', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '用户ID'
},
username: {
type: DataTypes.STRING(50),
allowNull: false,
unique: true,
comment: '用户名'
},
password: {
type: DataTypes.STRING(255),
allowNull: false,
comment: '密码(加密存储)'
},
nickname: {
type: DataTypes.STRING(50),
allowNull: true,
comment: '昵称'
},
avatar: {
type: DataTypes.STRING(255),
allowNull: true,
comment: '头像URL'
},
roleId: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '角色ID'
},
tenantId: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '租户ID'
},
userType: {
type: DataTypes.ENUM('super_admin', 'tenant_admin', 'user'),
allowNull: false,
defaultValue: 'user',
comment: '用户类型super_admin-系统管理员tenant_admin-租户管理员user-普通用户'
},
status: {
type: DataTypes.ENUM('active', 'inactive'),
defaultValue: 'active',
comment: '状态active-启用inactive-禁用'
},
lastLoginTime: {
type: DataTypes.DATE,
allowNull: true,
comment: '最后登录时间'
},
lastLoginIp: {
type: DataTypes.STRING(50),
allowNull: true,
comment: '最后登录IP'
},
createBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '创建人ID'
},
updateBy: {
type: DataTypes.INTEGER,
allowNull: true,
comment: '修改人ID'
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '删除状态0未删除1已删除'
},
createTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '创建时间'
},
updateTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '更新时间'
}
}, {
tableName: 'users',
timestamps: false,
comment: '用户表'
});
module.exports = User;