UNPKG

@grouparoo/core

Version:
33 lines (32 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { up: async (queryInterface, DataTypes) => { await queryInterface.addColumn("destinations", "groupGuid", { type: DataTypes.STRING(40), allowNull: true, }); const [destinations] = await queryInterface.sequelize.query('select * from "destinations"'); for (const destination of destinations) { if (destination["trackAllGroups"]) { await queryInterface.sequelize.query(`delete from "destinationGroups" where "destinationGuid" = '${destination["guid"]}'`); } else { const [destinationGroups] = await queryInterface.sequelize.query(`select * from "destinationGroups" where "destinationGuid" = '${destination["guid"]}'`); if (destinationGroups.length === 1) { await queryInterface.sequelize.query(`update destinations set "groupGuid" = '${destinationGroups[0]["groupGuid"]}'`); } } } await queryInterface.removeColumn("destinations", "trackAllGroups"); await queryInterface.dropTable("destinationGroups"); }, down: async (queryInterface, DataTypes) => { await queryInterface.removeColumn("destinations", "groupGuid"); await queryInterface.addColumn("destinations", "trackAllGroups", { type: DataTypes.BOOLEAN, allowNull: false, }); // not rebuilding the destinationGroups table }, };