WMS_MAIN/database/migrations/20260708000000-add-stock-id-to-wms-picking.js
liufumingren 14a5f13ad5 feat(db): wms_store_warehouse 新增 initiator_subject_id,wms_picking 新增 stock_id 及联合索引
- wms_store_warehouse: 新增 initiator_subject_id 记录发起方主体ID

- wms_picking: 新增 stock_id 字段 + idx_wms_picking_warehouse_stock 联合索引 + 历史数据回填

- Model 层同步更新关联定义
2026-07-09 03:36:03 +08:00

35 lines
1.1 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';
/**
* 为 wms_picking 表新增 stock_id 字段及联合索引。
*
* 用途:消除面单打印自定义区对 wms_order_items 明细表的强依赖,
* 使打印链路可通过 wms_picking.stock_id 直读商品信息与条码数据。
*/
module.exports = {
up: async queryInterface => {
await queryInterface.sequelize.query(`
ALTER TABLE wms_picking
ADD COLUMN stock_id BIGINT(20) DEFAULT NULL COMMENT '商品SKU ID' AFTER storage_id,
ADD INDEX idx_wms_picking_warehouse_stock (warehouse_id, stock_id)
`);
// 回填已有 picking 记录的 stock_id(通过 storage 链路补全)
await queryInterface.sequelize.query(`
UPDATE wms_picking p
INNER JOIN wms_storage s ON p.storage_id = s.id
SET p.stock_id = s.stock_id
WHERE p.stock_id IS NULL
AND p.storage_id IS NOT NULL
`);
},
down: async queryInterface => {
await queryInterface.sequelize.query(`
ALTER TABLE wms_picking
DROP INDEX idx_wms_picking_warehouse_stock,
DROP COLUMN stock_id
`);
},
};