oms/backend/database/migrations/20260915000200-order-deliveries-legacy-source.js
liufumingren 11e7b26ced feat(backend): 发货单模块与 WMS 定时推送队列
- 发货单主表/明细表(order_deliveries / order_delivery_items)控制器与模型
- 表头金额与明细派生字段重算(utils/recalcOrderDelivery.js)
- 状态流转:审核/驳回/取消/恢复/作废、批量审核、批量切换仓库
- 审核入队 + 定时推送:service/orderDeliveryPush.js(乐观锁 CAS 防重、失败重试上限 3 次、业务失败退回待审核)+ schedule/orderDeliveryPush.js
- 收件人 AI 智能识别(service/ai.js,DeepSeek)
- 相关迁移:建表、站内字段、明细表、订单类型默认值、快递字典、菜单种子、历史数据搬迁
2026-09-13 02:23:47 +08:00

58 lines
2.4 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';
/**
* 发货单表补充「历史数据来源」列:
* - order_deliveries.legacy_order_id 来源 orders.id(仅历史搬迁数据有值,正常新建为 NULL)
* - order_delivery_items.legacy_order_item_id 来源 order_items.id
*
* 用途:
* 1) 数据搬迁幂等:INSERT ... WHERE NOT EXISTS (legacy_*_id = ...) 可重复执行不产生重复数据;
* 2) 可精确回滚:迁移 down() 只删 legacy_* 非空的行,不误删迁移后新建的单据;
* 3) 可追溯:历史单据仍能反查原 orders / order_items 记录(原表保留启用,不删除)。
*/
module.exports = {
async up(queryInterface, Sequelize) {
const headerCols = await queryInterface.describeTable('order_deliveries');
if (!headerCols.legacy_order_id) {
await queryInterface.addColumn('order_deliveries', 'legacy_order_id', {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '历史数据来源:orders.id(非搬迁数据为 NULL)',
});
await queryInterface.addIndex('order_deliveries', {
fields: [ 'legacy_order_id' ],
unique: true,
name: 'uk_order_deliveries_legacy',
});
}
const itemCols = await queryInterface.describeTable('order_delivery_items');
if (!itemCols.legacy_order_item_id) {
await queryInterface.addColumn('order_delivery_items', 'legacy_order_item_id', {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '历史数据来源:order_items.id(非搬迁数据为 NULL)',
});
await queryInterface.addIndex('order_delivery_items', {
fields: [ 'legacy_order_item_id' ],
unique: true,
name: 'uk_od_items_legacy',
});
}
},
async down(queryInterface) {
const itemCols = await queryInterface.describeTable('order_delivery_items');
if (itemCols.legacy_order_item_id) {
await queryInterface.removeIndex('order_delivery_items', 'uk_od_items_legacy').catch(() => {});
await queryInterface.removeColumn('order_delivery_items', 'legacy_order_item_id');
}
const headerCols = await queryInterface.describeTable('order_deliveries');
if (headerCols.legacy_order_id) {
await queryInterface.removeIndex('order_deliveries', 'uk_order_deliveries_legacy').catch(() => {});
await queryInterface.removeColumn('order_deliveries', 'legacy_order_id');
}
},
};