'use strict'; /** * 为波次表 wms_wave_batch 增加复核开始时间字段。 * * 背景: * 复核扫描接口 order.recheckOrder.scanOrder 首次成功加载某波次的复核视图时, * 需要记录该波次的复核开始时间用于统计与审计;此前波次表仅有复核完成时间 * (check_time,校验时间),缺少复核开始时间,二者语义不同不可复用。 * * 变更: * 1. wms_wave_batch 新增 recheck_start_time:DATETIME,可空、无默认值,复核开始时间。 * 2. 不回填任何历史数据(对既有数据零影响,仅后续首次扫描时写入)。 * 3. 模型定义同步更新(app/model/wave_batch.js)。 * * 幂等:字段已存在则跳过;回滚时字段不存在则跳过。 */ const TABLE_NAME = 'wms_wave_batch'; const COLUMN_NAME = 'recheck_start_time'; const FILE_TAG = '[20260908120000-add-recheck-start-time-to-wms-wave-batch]'; /** * 获取表字段定义。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {string} tableName 表名。 * @return {Promise} 字段定义对象。 */ const getTableColumns = async (queryInterface, tableName) => { return queryInterface.describeTable(tableName); }; module.exports = { /** * 正向迁移:为波次表补充复核开始时间字段(字段已存在则跳过)。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。 * @return {Promise} 无返回值。 */ up: async (queryInterface, Sequelize) => { const columnsBefore = await getTableColumns(queryInterface, TABLE_NAME); if (!columnsBefore[COLUMN_NAME]) { await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, { type: Sequelize.DATE, allowNull: true, comment: '复核开始时间', after: 'check_result', }); console.log(`${FILE_TAG} up: added column ${COLUMN_NAME} on ${TABLE_NAME}`); } else { console.log(`${FILE_TAG} up: skip, column ${COLUMN_NAME} already exists on ${TABLE_NAME}`); } }, /** * 回滚迁移:若复核开始时间字段存在则删除。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @return {Promise} 无返回值。 */ down: async queryInterface => { const columnsBefore = await getTableColumns(queryInterface, TABLE_NAME); if (columnsBefore[COLUMN_NAME]) { await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME); console.log(`${FILE_TAG} down: removed column ${COLUMN_NAME} on ${TABLE_NAME}`); } else { console.log(`${FILE_TAG} down: skip, column ${COLUMN_NAME} not exists on ${TABLE_NAME}`); } }, };