WMS_MAIN/database/migrations/20260715180000-extend-wms-pack-task.js

161 lines
5.1 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';
const TABLE_NAME = 'wms_pack_task';
module.exports = {
up: async (queryInterface, Sequelize) => {
// 1. 仓库隔离
await queryInterface.addColumn(TABLE_NAME, 'warehouse_id', {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '仓库ID',
after: 'order_id',
});
// 2. 工作台关联
await queryInterface.addColumn(TABLE_NAME, 'workbench_id', {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: true,
comment: '工作台ID,关联 wms_workbench.id',
after: 'warehouse_id',
});
// 3. 波次信息
await queryInterface.addColumn(TABLE_NAME, 'wave_id', {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: true,
defaultValue: 0,
comment: '波次ID',
after: 'workbench_id',
});
await queryInterface.addColumn(TABLE_NAME, 'wave_no', {
type: Sequelize.STRING(50),
allowNull: true,
comment: '波次号',
after: 'wave_id',
});
// 4. 运单号
await queryInterface.addColumn(TABLE_NAME, 'waybill_code', {
type: Sequelize.STRING(50),
allowNull: true,
comment: '运单号',
after: 'wave_no',
});
// 5. 打包数量
await queryInterface.addColumn(TABLE_NAME, 'pack_quantity', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: true,
defaultValue: 0,
comment: '打包数量(件数)',
after: 'waybill_code',
});
// 6. 作业时间
await queryInterface.addColumn(TABLE_NAME, 'start_time', {
type: Sequelize.DATE,
allowNull: true,
comment: '开始打包时间',
after: 'pack_quantity',
});
await queryInterface.addColumn(TABLE_NAME, 'end_time', {
type: Sequelize.DATE,
allowNull: true,
comment: '结束打包时间',
after: 'start_time',
});
// 7. 作业人员(兼容多人的自由文本)
await queryInterface.addColumn(TABLE_NAME, 'operator_text', {
type: Sequelize.TEXT,
allowNull: true,
comment: '作业人员(自由文本,如多人逗号分隔)',
after: 'end_time',
});
// 8. 设备IDS(JSON列表)
await queryInterface.addColumn(TABLE_NAME, 'device_ids', {
type: Sequelize.JSON,
allowNull: true,
comment: '设备ID列表,如 [1,2,3]',
after: 'operator_text',
});
// 9. 包材信息
await queryInterface.addColumn(TABLE_NAME, 'package_material_id', {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: true,
comment: '包材ID,关联 wms_package_material.id',
after: 'device_ids',
});
await queryInterface.addColumn(TABLE_NAME, 'package_material_snapshot', {
type: Sequelize.STRING(200),
allowNull: true,
comment: '包材快照(编码+名称)',
after: 'package_material_id',
});
// 10. 称重
await queryInterface.addColumn(TABLE_NAME, 'weighing_weight', {
type: Sequelize.DECIMAL(10, 3),
allowNull: true,
comment: '打包称重(kg)',
after: 'package_material_snapshot',
});
// 11. 异常
await queryInterface.addColumn(TABLE_NAME, 'abnormal_reason', {
type: Sequelize.STRING(500),
allowNull: true,
comment: '异常原因',
after: 'weighing_weight',
});
// 12. 备注
await queryInterface.addColumn(TABLE_NAME, 'remark', {
type: Sequelize.STRING(500),
allowNull: true,
comment: '备注',
after: 'abnormal_reason',
});
// 13. 修改 status 注释以包含更多状态
await queryInterface.changeColumn(TABLE_NAME, 'status', {
type: Sequelize.TINYINT.UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '任务状态:0=待处理 1=打包中 2=已完成 3=异常',
});
// ======== 索引 ========
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id' ], { name: 'idx_warehouse_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'workbench_id' ], { name: 'idx_workbench_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'wave_id' ], { name: 'idx_wave_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'waybill_code' ], { name: 'idx_waybill_code' });
await queryInterface.addIndex(TABLE_NAME, [ 'start_time' ], { name: 'idx_start_time' });
await queryInterface.addIndex(TABLE_NAME, [ 'status' ], { name: 'idx_status' });
},
down: async queryInterface => {
const cols = [
'remark', 'abnormal_reason', 'weighing_weight',
'package_material_snapshot', 'package_material_id',
'device_ids', 'operator_text', 'end_time', 'start_time',
'pack_quantity', 'waybill_code', 'wave_no', 'wave_id',
'workbench_id', 'warehouse_id',
];
for (const col of cols) {
await queryInterface.removeColumn(TABLE_NAME, col);
}
await queryInterface.removeIndex(TABLE_NAME, 'idx_status');
await queryInterface.removeIndex(TABLE_NAME, 'idx_start_time');
await queryInterface.removeIndex(TABLE_NAME, 'idx_waybill_code');
await queryInterface.removeIndex(TABLE_NAME, 'idx_wave_id');
await queryInterface.removeIndex(TABLE_NAME, 'idx_workbench_id');
await queryInterface.removeIndex(TABLE_NAME, 'idx_warehouse_id');
},
};