'use strict'; /** * 下线运单物流轨迹本地存储:删除 wms_order_express_trace。 * * 背景(2026-11-11 业务调整): * - 轨迹查询改为「全部回源」,`waybill.warehouse.getTrace` 实时调用外部 waybill.getTrace 返回, * 不再落库;批量同步方法 `waybill.warehouse.updateTrace` / `updateTraceTaskProgress` 一并下线; * - 因此轨迹表不再需要,删除以免产生无用数据与维护成本。 * - 揽收联动保留:查询命中轨迹时仍会把 wms_order_express.is_galaxy_receive 置为 Y。 * * 说明:本迁移不可逆(数据不再保留),down 仅重建空表结构以便回滚版本时可启动。 */ const TABLE_NAME = 'wms_order_express_trace'; module.exports = { async up(queryInterface) { const tables = await queryInterface.showAllTables(); const exists = (tables || []).some(t => { const name = typeof t === 'string' ? t : (t && (t.tableName || t.name)) || ''; return String(name).toLowerCase() === TABLE_NAME; }); if (!exists) { console.log(`[${TABLE_NAME}] skip: 表不存在`); return; } await queryInterface.dropTable(TABLE_NAME); console.log(`[${TABLE_NAME}] dropped`); }, async down(queryInterface, Sequelize) { const { BIGINT, STRING, DATE, JSON: JSON_TYPE, DECIMAL } = Sequelize; const tables = await queryInterface.showAllTables(); const exists = (tables || []).some(t => { const name = typeof t === 'string' ? t : (t && (t.tableName || t.name)) || ''; return String(name).toLowerCase() === TABLE_NAME; }); if (exists) { console.log(`[${TABLE_NAME}] skip: 表已存在`); return; } await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID' }, express_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '运单ID(wms_order_express.id)' }, waybill_code: { type: STRING(50), allowNull: false, comment: '运单号' }, order_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '订单ID' }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID' }, op_time: { type: DATE, allowNull: true, comment: '操作时间' }, out_biz_code: { type: STRING(191), allowNull: true, comment: '外部业务码' }, memo: { type: STRING(500), allowNull: true, comment: '轨迹描述' }, op_org_city_name: { type: STRING(100), allowNull: true, comment: '操作机构城市' }, weight: { type: DECIMAL(10, 3), allowNull: true, defaultValue: 0, comment: '重量(来源原值)' }, scan_type: { type: STRING(50), allowNull: true, comment: '扫描类型' }, raw_data: { type: JSON_TYPE, allowNull: true, comment: '原始轨迹报文' }, created_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间' }, updated_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), comment: '更新时间' }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间' }, }, { charset: 'utf8mb4', collate: 'utf8mb4_general_ci', comment: '运单物流轨迹表(已下线本地存储)', }); await queryInterface.addIndex(TABLE_NAME, [ 'express_id', 'op_time', 'scan_type' ], { unique: true, name: 'uk_express_op_scan' }); await queryInterface.addIndex(TABLE_NAME, [ 'waybill_code', 'op_time' ], { name: 'idx_waybill_code' }); await queryInterface.addIndex(TABLE_NAME, [ 'order_id' ], { name: 'idx_order_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'op_time' ], { name: 'idx_warehouse_op_time' }); console.log(`[${TABLE_NAME}] recreated (empty)`); }, };