'use strict'; /** * 收件任务表补「标题」字段,并播种系统预设行(幂等)。 * * - addColumn title(标题,NOT NULL 默认空串) * - 幂等插入系统预设:id=1、warehouse_id=0、title='历史收件', * 用于处理历史(旧流程)收货任务;batch_no 同步填 '历史收件',creator_id=0(系统)。 * * 显式插入 id=1 不会影响 AUTO_INCREMENT=10000 的水位(1 < 10000)。 */ const TABLE_NAME = 'wms_receiving_task'; module.exports = { async up(queryInterface, Sequelize) { const { STRING } = Sequelize; const tableInfo = await queryInterface.describeTable(TABLE_NAME); if (!tableInfo.title) { await queryInterface.addColumn(TABLE_NAME, 'title', { type: STRING(100), allowNull: false, defaultValue: '', comment: '标题(任务名称,如系统预设「历史收件」)', }); } const { sequelize } = queryInterface; const [ rows ] = await sequelize.query( 'SELECT id FROM `' + TABLE_NAME + '` WHERE id = 1 LIMIT 1' ); if (!rows || rows.length === 0) { await sequelize.query( 'INSERT INTO `' + TABLE_NAME + '` (id, batch_no, warehouse_id, creator_id, creator_name, title, created_at, updated_at) VALUES (1, :b, 0, 0, :c, :t, NOW(), NOW())', { replacements: { b: '历史收件', c: '系统', t: '历史收件' } } ); } }, async down(queryInterface) { const { sequelize } = queryInterface; await sequelize.query( 'DELETE FROM `' + TABLE_NAME + '` WHERE id = 1 AND warehouse_id = 0' ); await queryInterface.removeColumn(TABLE_NAME, 'title'); }, };