'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'); }, };