const moment = require('moment'); module.exports = (sequelize, DataTypes) => sequelize.define('user', { id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.STRING(64), allowNull: false, unique: 'column' }, password: { type: DataTypes.STRING(512), allowNull: false }, phone: { type: DataTypes.STRING(64), allowNull: false, unique: 'column' }, email: { type: DataTypes.STRING(512), allowNull: false, defaultValue: "xxxxx@xxx.com" }, photo: { type: DataTypes.STRING(512), allowNull: false, defaultValue: "/image/default-photo.jpg" }, role: { type: DataTypes.ENUM, values: ['STUDENT', 'TEACHER', 'ADMIN'], allowNull: false, defaultValue: 'STUDENT' }, signature: { type: DataTypes.STRING(512), allowNull: false, defaultValue: "无" }, createdTime: { type: DataTypes.DATE, allowNull: false, get() { return moment(this.getDataValue('createdTime')).format('YYYY-MM-DD HH:mm:ss'); } }, isValid: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true }, }, { tableName: 'user' });