UNPKG

@tomei/live-price

Version:

Tomei live-price Package

86 lines (73 loc) 2.83 kB
'use strict'; module.exports = { async up(queryInterface, Sequelize) { const tableDescription = await queryInterface.describeTable('price_CompanyFeedAccess'); // Check if IsActiveYN column exists if (tableDescription.IsActiveYN) { // Add the new Status column await queryInterface.addColumn('price_CompanyFeedAccess', 'Status', { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'Active', after: 'FeedName' }); // Update existing data: convert Y/N to Active/Inactive await queryInterface.sequelize.query(` UPDATE price_CompanyFeedAccess SET Status = CASE WHEN IsActiveYN = 'Y' THEN 'Active' WHEN IsActiveYN = 'N' THEN 'Inactive' ELSE 'Active' END `); // Remove the old IsActiveYN column await queryInterface.removeColumn('price_CompanyFeedAccess', 'IsActiveYN'); // Update the index: remove old index if it exists and create new one try { await queryInterface.removeIndex('price_CompanyFeedAccess', 'idx_is_active_yn'); } catch (error) { // Index might not exist, continue console.log('Index idx_is_active_yn does not exist, skipping removal'); } await queryInterface.addIndex('price_CompanyFeedAccess', { fields: ['Status'], name: 'idx_status' }); } }, async down(queryInterface, Sequelize) { const tableDescription = await queryInterface.describeTable('price_CompanyFeedAccess'); // Check if Status column exists if (tableDescription.Status) { // Add back the IsActiveYN column await queryInterface.addColumn('price_CompanyFeedAccess', 'IsActiveYN', { type: Sequelize.CHAR(1), allowNull: false, defaultValue: 'Y', after: 'FeedName' }); // Update existing data: convert Active/Inactive to Y/N await queryInterface.sequelize.query(` UPDATE price_CompanyFeedAccess SET IsActiveYN = CASE WHEN Status = 'Active' THEN 'Y' WHEN Status = 'Inactive' THEN 'N' ELSE 'Y' END `); // Remove the Status column await queryInterface.removeColumn('price_CompanyFeedAccess', 'Status'); // Update the index: remove new index and create old one try { await queryInterface.removeIndex('price_CompanyFeedAccess', 'idx_status'); } catch (error) { // Index might not exist, continue console.log('Index idx_status does not exist, skipping removal'); } await queryInterface.addIndex('price_CompanyFeedAccess', { fields: ['IsActiveYN'], name: 'idx_is_active_yn' }); } } };