]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14542 Migration 4208 fails if the PK constraint name is unexpected
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 2 Mar 2021 21:30:34 +0000 (15:30 -0600)
committersonartech <sonartech@sonarsource.com>
Mon, 8 Mar 2021 20:07:54 +0000 (20:07 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTable.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v87/DropOrganizationsTableTest.java

index e6c38a4eb87d0d376e28a3cd3644f3f6ec0365c7..cb57286c7b94c2223b238c8bc930978d78c54d96 100644 (file)
@@ -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());
   }
index 82093e1bb5bf1a5032a233ad67c225a73e7503e2..e86acbd1fd36e95b6df2de162003cb1c692f0ab2 100644 (file)
@@ -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 {