90 lines
2.4 KiB
JavaScript
90 lines
2.4 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_NAME = 'wms_workbench';
|
||
|
||
module.exports = {
|
||
up: async (queryInterface, Sequelize) => {
|
||
const tables = await queryInterface.showAllTables();
|
||
const exists = tables.some(t => (typeof t === 'string' ? t : t.tableName) === TABLE_NAME);
|
||
if (exists) return;
|
||
|
||
await queryInterface.createTable(TABLE_NAME, {
|
||
id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
},
|
||
name: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: false,
|
||
comment: '工作台名称(用户自定义)',
|
||
},
|
||
barcode: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: true,
|
||
comment: '工作台条码(用户自定义,仓库内唯一)',
|
||
},
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '状态:0-禁用 1-启用',
|
||
},
|
||
remark: {
|
||
type: Sequelize.STRING(500),
|
||
allowNull: true,
|
||
comment: '备注',
|
||
},
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
deleted_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '软删除时间',
|
||
},
|
||
});
|
||
|
||
// 仓库隔离查询
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id' ], {
|
||
name: 'idx_warehouse_id',
|
||
});
|
||
|
||
// 条码检索
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'barcode' ], {
|
||
name: 'idx_barcode',
|
||
});
|
||
|
||
// 仓库级别唯一条码(含软删除,遵循 location_space 同款模式)
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'barcode', 'deleted_at' ], {
|
||
unique: true,
|
||
name: 'uk_warehouse_barcode',
|
||
});
|
||
|
||
// 软删除查询优化
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'deleted_at' ], {
|
||
name: 'idx_deleted_at',
|
||
});
|
||
},
|
||
|
||
down: async queryInterface => {
|
||
await queryInterface.dropTable(TABLE_NAME);
|
||
},
|
||
};
|