UNPKG

@grouparoo/core

Version:
42 lines (41 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { up: async (queryInterface, DataTypes) => { await queryInterface.addColumn("profileProperties", "unique", { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: true, }); const [properties] = await queryInterface.sequelize.query("SELECT * FROM \"properties\" WHERE state = 'ready'"); const uniqueProperties = properties.filter((p) => p["unique"] === 1 || p["unique"] === "1" || p["unique"] === true); if (uniqueProperties.length > 0) { await queryInterface.sequelize.query(`UPDATE "profileProperties" SET "unique"=true WHERE "propertyId" IN (${uniqueProperties .map((p) => `'${p["id"]}'`) .join(", ")})`); await queryInterface.sequelize.query(`UPDATE "profileProperties" SET "unique"=false WHERE "propertyId" NOT IN (${uniqueProperties .map((p) => `'${p["id"]}'`) .join(", ")})`); } else { await queryInterface.sequelize.query(`UPDATE "profileProperties" SET "unique"=false`); } await queryInterface.changeColumn("profileProperties", "unique", { type: DataTypes.BOOLEAN, allowNull: false, }); await queryInterface.addIndex("profileProperties", ["propertyId", "rawValue", "position", "unique"], { unique: true, fields: ["propertyId", "rawValue", "position", "unique"], where: { unique: true }, }); }, down: async (queryInterface) => { await queryInterface.removeIndex("profileProperties", ["propertyId", "rawValue", "position", "unique"], { unique: true, fields: ["propertyId", "rawValue", "position", "unique"], where: { unique: true }, }); await queryInterface.removeColumn("profileProperties", "unique"); }, };