oms/backend/database/migrations/20260909000100-create-users.js

45 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/** 1. 用户表(密码加盐存储) */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(
'users',
{
id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
username: { type: Sequelize.STRING(50), allowNull: false, comment: '登录账号' },
password: { type: Sequelize.STRING(255), allowNull: false, comment: '加盐哈希后的密码' },
salt: { type: Sequelize.STRING(32), allowNull: false, comment: '密码盐值' },
nickname: { type: Sequelize.STRING(50), allowNull: true, comment: '昵称' },
avatar: { type: Sequelize.STRING(255), allowNull: true, comment: '头像' },
email: { type: Sequelize.STRING(100), allowNull: true, comment: '邮箱' },
phone: { type: Sequelize.STRING(20), allowNull: true, comment: '手机号' },
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
last_login_at: { type: Sequelize.DATE, allowNull: true, comment: '最后登录时间' },
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
},
},
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '用户表' }
);
await queryInterface.addIndex('users', { fields: [ 'username' ], unique: true, name: 'uk_users_username' });
},
async down(queryInterface) {
await queryInterface.dropTable('users');
},
};