109 lines
2.6 KiB
JavaScript
109 lines
2.6 KiB
JavaScript
'use strict';
|
||
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
const { BIGINT, STRING, DATE, TINYINT } = Sequelize;
|
||
|
||
await queryInterface.createTable('wms_account', {
|
||
id: {
|
||
type: BIGINT(20),
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '账号ID',
|
||
},
|
||
username: {
|
||
type: STRING(50),
|
||
allowNull: false,
|
||
unique: true,
|
||
comment: '用户名',
|
||
},
|
||
phone: {
|
||
type: STRING(20),
|
||
allowNull: false,
|
||
comment: '手机号',
|
||
},
|
||
email: {
|
||
type: STRING(100),
|
||
allowNull: true,
|
||
comment: '邮箱',
|
||
},
|
||
password_hash: {
|
||
type: STRING(255),
|
||
allowNull: false,
|
||
comment: '密码哈希',
|
||
},
|
||
real_name: {
|
||
type: STRING(50),
|
||
allowNull: false,
|
||
comment: '真实姓名',
|
||
},
|
||
user_type: {
|
||
type: TINYINT(4),
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '用户类型:1-平台管理员,2-仓库管理员',
|
||
},
|
||
status: {
|
||
type: TINYINT(4),
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '状态:0-禁用,1-启用,2-离职',
|
||
},
|
||
last_login_at: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '最后登录时间',
|
||
},
|
||
created_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
salt: {
|
||
type: STRING(20),
|
||
allowNull: true,
|
||
comment: '密码盐',
|
||
},
|
||
}, {
|
||
engine: 'InnoDB',
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
comment: 'WMS账户表',
|
||
});
|
||
|
||
// 添加索引
|
||
await queryInterface.addIndex('wms_account', [ 'username' ], {
|
||
name: 'idx_username',
|
||
unique: true,
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_account', [ 'phone' ], {
|
||
name: 'idx_phone',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_account', [ 'email' ], {
|
||
name: 'idx_email',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_account', [ 'user_type' ], {
|
||
name: 'idx_user_type',
|
||
});
|
||
|
||
await queryInterface.addIndex('wms_account', [ 'status' ], {
|
||
name: 'idx_status',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.dropTable('wms_account');
|
||
},
|
||
};
|