'use strict'; module.exports = { async up(queryInterface) { const [ columns ] = await queryInterface.sequelize.query('SHOW COLUMNS FROM `wms_qimen_log` LIKE \'log_id\''); if (columns.length > 0) { const [ idxs ] = await queryInterface.sequelize.query('SHOW INDEX FROM `wms_qimen_log` WHERE Key_name = \'idx_log_id\''); if (idxs.length === 0) { await queryInterface.sequelize.query('ALTER TABLE `wms_qimen_log` ADD UNIQUE INDEX `idx_log_id` (`log_id`)'); } return; } await queryInterface.sequelize.query('ALTER TABLE `wms_qimen_log` ADD COLUMN `log_id` VARCHAR(32) DEFAULT NULL AFTER `id`'); const [ idxs2 ] = await queryInterface.sequelize.query('SHOW INDEX FROM `wms_qimen_log` WHERE Key_name = \'idx_log_id\''); if (idxs2.length === 0) { await queryInterface.sequelize.query('ALTER TABLE `wms_qimen_log` ADD UNIQUE INDEX `idx_log_id` (`log_id`)'); } }, async down(queryInterface) { const [ indexes ] = await queryInterface.sequelize.query('SHOW INDEX FROM `wms_qimen_log` WHERE Key_name = \'idx_log_id\''); if (indexes.length > 0) { await queryInterface.sequelize.query('ALTER TABLE `wms_qimen_log` DROP INDEX `idx_log_id`'); } const [ columns ] = await queryInterface.sequelize.query('SHOW COLUMNS FROM `wms_qimen_log` LIKE \'log_id\''); if (columns.length > 0) { await queryInterface.sequelize.query('ALTER TABLE `wms_qimen_log` DROP COLUMN `log_id`'); } }, };