From 1a987882370a26f9fbf93f35f7558514549dfab3 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 2 Mar 2021 15:30:34 -0600 Subject: [PATCH] SONAR-14542 Migration 4208 fails if the PK constraint name is unexpected --- .../db/migration/version/v87/DropOrganizationsTable.java | 8 +++++--- .../migration/version/v87/DropOrganizationsTableTest.java | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTable.java index e6c38a4eb87..cb57286c7b9 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTable.java @@ -21,21 +21,23 @@ package org.sonar.server.platform.db.migration.version.v87; import java.sql.SQLException; import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder; import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; +import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.sql.DropTableBuilder; import org.sonar.server.platform.db.migration.step.DdlChange; public class DropOrganizationsTable extends DdlChange { private static final String TABLE_NAME = "organizations"; + private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator; - public DropOrganizationsTable(Database db) { + public DropOrganizationsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { super(db); + this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator; } @Override public void execute(Context context) throws SQLException { - context.execute(new DropConstraintBuilder(getDialect()).setTable(TABLE_NAME).setName("pk_organizations").build()); + context.execute(dropPrimaryKeySqlGenerator.generate(TABLE_NAME, "uuid", false)); context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("organization_key").build()); context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTableTest.java index 82093e1bb5b..e86acbd1fd3 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTableTest.java @@ -23,6 +23,8 @@ import java.sql.SQLException; import org.junit.Rule; import org.junit.Test; import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder; +import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator; import org.sonar.server.platform.db.migration.step.MigrationStep; public class DropOrganizationsTableTest { @@ -30,8 +32,9 @@ public class DropOrganizationsTableTest { @Rule public CoreDbTester db = CoreDbTester.createForSchema(DropOrganizationsTableTest.class, "schema.sql"); + private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())); - private MigrationStep underTest = new DropOrganizationsTable(db.database()); + private MigrationStep underTest = new DropOrganizationsTable(db.database(), dropPrimaryKeySqlGenerator); @Test public void execute() throws SQLException { -- 2.39.5