'use strict'; /** * 清理仓库接口配置项残留键(第三轮):warehouse_apis.extra 中「已不在硬编码清单内」的键 * * 背景(2026-09-14 按用户要求核实后精简): * - 「递交设置」(submit)22 项、「回传设置」(callback)13 项整体移除 —— 逐项核对源码后, * 35 项里只有 `item_name_with_spec`(`qimenClient._buildItem` 拼 itemName 时读取)在用, * 其余 34 项无任何引用;该字段已归入「业务设置」分组 * - 至此配置项清单只剩 7 项:purchase_return_code_type / transfer_in_code_type / transfer_out_code_type / * sku_sync_key / barcode_sync_source / api_version / item_name_with_spec * * 口径:以当前清单的 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() {}, };