'use strict'; /** * 创建退回查询记录表 wms_return_query_log。 * * 用途:登记「货主未退回、但做过查询退回」的运单号,仓库 + 货主隔离。 * 创建拆包单未命中原单时,据此反查运单号对应的货主并回写 store_id(限最近 3 个月内登记)。 * is_back / is_notified 供定时任务扫描拆包通知;拆包单提交确认时更新 is_back=1。 * * 索引: * idx_warehouse_store_waybill(仓库+货主+运单号,核心) * idx_warehouse_store(仓库+货主隔离查询) * idx_waybill_code(按运单号查询) */ const TABLE_NAME = 'wms_return_query_log'; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, STRING, DATE, TINYINT } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID(隔离维度)', }, store_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '货主ID(隔离维度)', }, waybill_code: { type: STRING(50), allowNull: false, comment: '查询过的运单号', }, remark: { type: STRING(500), allowNull: true, comment: '备注', }, is_notified: { type: TINYINT(1), allowNull: false, defaultValue: 0, comment: '是否已通知:0=未通知,1=已通知', }, is_back: { type: TINYINT(1), allowNull: false, defaultValue: 0, comment: '是否退回:0=未退回,1=已退回', }, created_at: { type: DATE, allowNull: false }, updated_at: { type: DATE, allowNull: false }, }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'store_id', 'waybill_code' ], { name: 'idx_warehouse_store_waybill' }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'store_id' ], { name: 'idx_warehouse_store' }); await queryInterface.addIndex(TABLE_NAME, [ 'waybill_code' ], { name: 'idx_waybill_code' }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };