'use strict'; /** * 管理员模型 - Admin * * 存储后台管理员账号信息,管理员通过用户名和密码进行登录。 */ module.exports = app => { const { STRING, INTEGER, DATE } = app.Sequelize; const Admin = app.model.define('admin', { // 主键 ID,自增 id: { type: INTEGER, primaryKey: true, autoIncrement: true, comment: '管理员唯一标识', }, // 管理员用户名,唯一 username: { type: STRING(50), allowNull: false, unique: true, comment: '管理员用户名', }, // 管理员密码(明文存储,生产环境应使用 bcrypt 加密) password: { type: STRING(100), allowNull: false, comment: '管理员密码', }, // 记录创建时间 created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, // 记录更新时间 updated_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '更新时间', }, }, { // 表名 tableName: 'admins', // 时间戳字段 timestamps: false, // 下划线命名 underscored: true, }); return Admin; };