From: Duarte Meneses Date: Tue, 2 Mar 2021 21:30:34 +0000 (-0600) Subject: SONAR-14542 Migration 4208 fails if the PK constraint name is unexpected X-Git-Tag: 8.7.1.42226~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=00d529671da7a6669eab432a164197837088755e;p=sonarqube.git SONAR-14542 Migration 4208 fails if the PK constraint name is unexpected --- 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 {