'use strict'; /** * 订单明细增加「平台原样快照」列。 * * 背景:绑定系统商品/组合商品时,明细的编码/名称/规格/图片会被系统商品信息覆盖; * 解绑后需要还原为平台原始快照,而 raw 列是平台各异的原始报文,无法通用还原, * 因此在拉单时把统一结构下的平台快照单独留存在 platform_snapshot。 */ const SNAPSHOT_COLUMN = { type: 'JSON', allowNull: true, comment: '平台明细快照(绑定前的编码/名称/规格/图片,用于解绑还原)', }; module.exports = { async up(queryInterface, Sequelize) { // 幂等:上一次执行可能因数据库异常中断,列已加上但迁移未记录 for (const table of [ 'order_items', 'order_status_items' ]) { const columns = await queryInterface.describeTable(table); if (!columns.platform_snapshot) { await queryInterface.addColumn(table, 'platform_snapshot', { ...SNAPSHOT_COLUMN, type: Sequelize.JSON }); } } }, async down(queryInterface) { for (const table of [ 'order_items', 'order_status_items' ]) { const columns = await queryInterface.describeTable(table); if (columns.platform_snapshot) { await queryInterface.removeColumn(table, 'platform_snapshot'); } } }, };