UNPKG

@grouparoo/core

Version:
97 lines (96 loc) 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const migration_1 = require("../utils/migration"); const renames = { exports: [ ["profileId", "recordId"], ["oldProfileProperties", "oldRecordProperties"], ["newProfileProperties", "newRecordProperties"], ], groupMembers: [["profileId", "recordId"]], groupRules: [["profileColumn", "recordColumn"]], imports: [ ["profileId", "recordId"], ["oldProfileProperties", "oldRecordProperties"], ["newProfileProperties", "newRecordProperties"], ["profileAssociatedAt", "recordAssociatedAt"], ["profileUpdatedAt", "recordUpdatedAt"], ["createdProfile", "createdRecord"], ], profileProperties: [["profileId", "recordId"]], runs: [ ["profilesCreated", "recordsCreated"], ["profilesImported", "recordsImported"], ], schedules: [["confirmProfiles", "confirmRecords"]], }; exports.default = { up: async (queryInterface, DataTypes) => { const dialect = migration_1.MigrationUtils.getDialect(queryInterface); if (dialect === "sqlite") { // All previous SQLite indexes had been removed (migration 000053), but we need to manually remove and re-add those special indexes for the recordProperties table. // Continued below at end of migration // See https://github.com/sequelize/sequelize/issues/12823 await migration_1.MigrationUtils.ensureSQLiteTableEmpty(queryInterface, "profileProperties"); await queryInterface.removeIndex("profileProperties", ["profileId", "propertyId", "position"], { unique: true, fields: ["profileId", "propertyId", "position"], }); await queryInterface.removeIndex("profileProperties", ["propertyId", "rawValue", "position", "unique"], { unique: true, fields: ["propertyId", "rawValue", "position", "unique"], where: { unique: true }, }); } await queryInterface.createTable("models", { id: { type: DataTypes.STRING(191), primaryKey: true, }, name: { type: DataTypes.STRING(191), allowNull: false, }, type: { type: DataTypes.STRING(191), allowNull: false, }, createdAt: { type: DataTypes.DATE, allowNull: false, }, updatedAt: { type: DataTypes.DATE, allowNull: false, }, }); await queryInterface.addIndex("models", ["name"], { unique: true, fields: ["name"], }); await queryInterface.renameTable("profiles", "records"); for (const [table, collection] of Object.entries(renames)) { for (const batch of collection) { const [oldName, newName] = batch; await queryInterface.renameColumn(table, oldName, newName); } } await queryInterface.renameTable("profileProperties", "recordProperties"); await queryInterface.sequelize.query(`UPDATE "logs" SET "topic"='grouparooRecord' WHERE "topic"='profile'`); await queryInterface.sequelize.query(`UPDATE "logs" SET "topic"='recordProperty' WHERE "topic"='profileProperty'`); if (dialect === "sqlite") { await queryInterface.addIndex("recordProperties", ["propertyId", "rawValue", "position", "unique"], { unique: true, fields: ["propertyId", "rawValue", "position", "unique"], where: { unique: true }, }); await queryInterface.addIndex("recordProperties", ["recordId", "propertyId", "position"], { unique: true, fields: ["recordId", "propertyId", "position"], }); } }, down: async function () { throw new Error("irreversible migration"); }, };