WMS_MAIN/database/migrations/20260507100000-create-wms_order_wave_strategy_match.js
liufumingren 9c2b254206 1
Co-authored-by: Copilot <copilot@github.com>
2026-05-11 08:44:27 +08:00

71 lines
2.0 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';
/**
* Migration: 创建 wms_order_wave_strategy_match 表
*
* 记录每个订单命中的全部波次策略 ID,作为快速扫描结果的副表存储。
* 不与分仓主表做物理外键,靠应用层逻辑维护一致性。
*
* 索引:
* idx_warehouse_order (warehouse_id, order_id) — 按订单删除/查询
* idx_warehouse_strategy (warehouse_id, strategy_id) — 按策略聚合统计
*/
module.exports = {
up: async (queryInterface, Sequelize) => {
const tableExists = await queryInterface.showAllTables()
.then(tables => tables.includes('wms_order_wave_strategy_match'));
if (tableExists) {
return;
}
await queryInterface.createTable('wms_order_wave_strategy_match', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键',
},
warehouse_id: {
type: Sequelize.INTEGER(10),
allowNull: false,
comment: '仓库ID',
},
order_id: {
type: Sequelize.BIGINT,
allowNull: false,
comment: '订单ID,逻辑关联分仓主表,不做物理外键',
},
strategy_id: {
type: Sequelize.INTEGER(10),
allowNull: false,
comment: '命中的波次策略ID',
},
create_time: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '写入时间',
},
}, {
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
comment: '订单波次策略命中明细表',
});
await queryInterface.addIndex('wms_order_wave_strategy_match', [ 'warehouse_id', 'order_id' ], {
name: 'idx_warehouse_order',
});
await queryInterface.addIndex('wms_order_wave_strategy_match', [ 'warehouse_id', 'strategy_id' ], {
name: 'idx_warehouse_strategy',
});
},
down: async queryInterface => {
await queryInterface.dropTable('wms_order_wave_strategy_match');
},
};