diff --git a/services/api/database/migrations/20240114000000_environment_services.js b/services/api/database/migrations/20240114000000_environment_services.js index 92986b7b36..e50713d6a0 100644 --- a/services/api/database/migrations/20240114000000_environment_services.js +++ b/services/api/database/migrations/20240114000000_environment_services.js @@ -8,8 +8,10 @@ exports.up = async function(knex) { table.string('type', 300); table.timestamp('updated').notNullable().defaultTo(knex.fn.now()); table.timestamp('created').notNullable().defaultTo(knex.fn.now()); - table.unique(['name', 'environment'], {indexName: 'service_environment'}); }) + // create a unique index but drop any duplicates when the unique is added + // the deprecated setEnvironmentServices resolver will remove duplicates before adding them now too + .raw(`ALTER IGNORE TABLE environment_service ADD UNIQUE INDEX service_environment (name, environment);`) .createTable('environment_service_container', function (table) { table.integer('service_id'); table.string('name', 300); @@ -27,7 +29,7 @@ exports.down = async function(knex) { table.dropColumn('type'); table.dropColumn('updated'); table.dropColumn('created'); - table.dropUnique(['name', 'environment'], 'service_environment'); }) + .raw(`ALTER TABLE environment_service DROP INDEX service_environment;`) .dropTable('environment_service_container') };