WMS_MAIN/database/migrations/20260729140000-add-waybill-list-indexes.js
liufumingren edc164298d feat(waybill): 新增面单/运单管理模块
- 新增 systems/waybill.js 业务层:运单列表查询/详情/导出
- 新增 systemMethods/waybill/warehouse.js 入口层
- 新增 6 个迁移脚本:面单列表索引、store_id 列、物流编码/名称回填、发货单号列、货主ID回填、发货字段回填
- 更新 waybill-module-design.md 设计文档
2026-08-01 03:43:47 +08:00

85 lines
2.9 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';
const TABLE_NAME = 'wms_order_express';
/**
* 获取指定表的索引名集合。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {string} tableName 表名。
* @return {Promise<Set<string>>} 索引名集合。
*/
const getIndexNameSet = async (queryInterface, tableName) => {
const indexes = await queryInterface.showIndex(tableName);
return new Set(indexes.map(index => String(index && index.name ? index.name : '').trim()).filter(Boolean));
};
module.exports = {
/**
* 执行迁移:为运单表新增运单列表高频查询索引(幂等)。
*
* 新增索引:
* - idx_warehouse_id_status:仓库+状态筛选(最常见查询组合)
* - idx_logistics_code:物流公司筛选
* - idx_logistics_interface_id:快递接口ID筛选
* - idx_warehouse_id_create_at:仓库+时间范围排序分页
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 实例。
* @return {Promise<void>} 无返回值。
*/
async up(queryInterface, Sequelize) {
const indexNameSet = await getIndexNameSet(queryInterface, TABLE_NAME);
if (!indexNameSet.has('idx_warehouse_id_status')) {
await queryInterface.addIndex(TABLE_NAME, {
name: 'idx_warehouse_id_status',
fields: ['warehouse_id', 'status'],
});
}
if (!indexNameSet.has('idx_logistics_code')) {
await queryInterface.addIndex(TABLE_NAME, {
name: 'idx_logistics_code',
fields: ['logistics_code'],
});
}
if (!indexNameSet.has('idx_logistics_interface_id')) {
await queryInterface.addIndex(TABLE_NAME, {
name: 'idx_logistics_interface_id',
fields: ['logistics_interface_id'],
});
}
if (!indexNameSet.has('idx_warehouse_id_create_at')) {
await queryInterface.addIndex(TABLE_NAME, {
name: 'idx_warehouse_id_create_at',
fields: ['warehouse_id', 'create_at'],
});
}
},
/**
* 回滚迁移:移除运单列表查询索引。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 实例。
* @return {Promise<void>} 无返回值。
*/
async down(queryInterface, Sequelize) {
const indexNameSet = await getIndexNameSet(queryInterface, TABLE_NAME);
if (indexNameSet.has('idx_warehouse_id_status')) {
await queryInterface.removeIndex(TABLE_NAME, 'idx_warehouse_id_status');
}
if (indexNameSet.has('idx_logistics_code')) {
await queryInterface.removeIndex(TABLE_NAME, 'idx_logistics_code');
}
if (indexNameSet.has('idx_logistics_interface_id')) {
await queryInterface.removeIndex(TABLE_NAME, 'idx_logistics_interface_id');
}
if (indexNameSet.has('idx_warehouse_id_create_at')) {
await queryInterface.removeIndex(TABLE_NAME, 'idx_warehouse_id_create_at');
}
},
};