'use strict'; /** * 清理仓库接口配置项残留键(第四轮):warehouse_apis.extra 中「已不在硬编码清单内」的键 * * 背景(2026-09-14 按用户要求「可以直接清理」):业务设置里同样未被代码读取的 5 项也移除 —— * - `purchase_return_code_type` / `transfer_in_code_type` / `transfer_out_code_type`: * 出库/入库/退货类型编码已硬编码在 `app/lib/wms/orderTypes.js` 的枚举里,不读配置 * - `sku_sync_key` / `barcode_sync_source`:商品同步(singleitem.synchronize)直接取 * `products.barcode` / `goods_code`,不读配置 * * 至此配置项只剩 2 项真正被 `qimenClient` 读取的:`api_version`(请求 v 参数)与 * `item_name_with_spec`(商品同步 itemName 是否拼规格)。 * * 口径:以当前清单的 key 集合为准,删除 extra 中**不在清单内**的所有键; * 无可删键时不写库(幂等),只动 `extra`,不改 `updated_at`。 */ const { listFieldDefs } = require('../../app/lib/warehouseApiFields'); module.exports = { async up(queryInterface) { const sequelize = queryInterface.sequelize; const validKeys = new Set(listFieldDefs().map(field => field.key)); const rows = await sequelize.query('SELECT id, extra FROM warehouse_apis', { type: sequelize.QueryTypes.SELECT }); let prunedKeys = 0; let touchedRows = 0; for (const row of rows) { let extra = row.extra; if (typeof extra === 'string') { try { extra = JSON.parse(extra); } catch { extra = null; } } if (!extra || typeof extra !== 'object' || Array.isArray(extra)) continue; const stale = Object.keys(extra).filter(key => !validKeys.has(key)); if (!stale.length) continue; const next = { ...extra }; for (const key of stale) delete next[key]; await sequelize.query( 'UPDATE warehouse_apis SET extra = ? WHERE id = ?', { replacements: [ JSON.stringify(next), row.id ] } ); prunedKeys += stale.length; touchedRows += 1; } console.log(`[migration] warehouse_apis.extra 清理清单外配置项:${touchedRows} 行 / ${prunedKeys} 个键`); }, /** * 不可逆:被删的键已无任何代码引用(如确需恢复,在页面重新填写即可) */ async down() {}, };