]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14335 Drop PK constraint by using select instead hardcoded name
authorJacek <jacek.poreda@sonarsource.com>
Mon, 18 Jan 2021 13:25:26 +0000 (14:25 +0100)
committerMalena Ebert <63863184+malena-ebert-sonarsource@users.noreply.github.com>
Tue, 26 Jan 2021 12:31:41 +0000 (13:31 +0100)
- Move DropPrimaryKeySqlGenerator, AddPrimaryKeyBuilder and DbConstraintFinder to 'org.sonar.server.platform.db.migration.sql' package

(cherry picked from commit fdfd28395271746cff870a45f8d2968709ed738a)

115 files changed:
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/AddPrimaryKeyBuilder.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/AddPrimaryKeyOnUuidColumnOfActiveRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/AddPrimaryKeyOnUuidColumnOfCeActivityTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/DropPrimaryKeyOnIdColumnOfCeActivityTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropPrimaryKeyOnIdColumn.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/events/AddPrimaryKeyOnUuidColumnOfEventsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/events/DropPrimaryKeyOnIdColumnOfEventsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/filesources/AddPrimaryKeyOnUuidColumnOfFileSourcesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/filesources/DropPrimaryKeyOnIdColumnOfFileSourcesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/AddPrimaryKeyOnUuidColumnOfGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/groups/DropPrimaryKeyOnIdColumnOfGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddPrimaryKeyOnUuidColumnOfIssueChangesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/AddPrimaryKeyOnUuidColumnOfManualMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/DropPrimaryKeyOnIdColumnOfManualMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/DropPrimaryKeyOnIdColumnOfMetricsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddPKeyOnUuidOfLiveMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/notifications/AddPrimaryKeyOnUuidColumnOfNotificationTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/notifications/DropPrimaryKeyOnIdColumnOfNotificationTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/AddPrimaryKeyOnUuidColumnOfPermissionTemplatesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/AddPrimaryKeyOnUuidColumnOfProjectQProfilesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/DropPrimaryKeyOnIdColumnOfProjectQProfilesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/properties/AddPrimaryKeyOnUuidColumnOfPropertiesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/properties/DropPrimaryKeyOnIdColumnOfPropertiesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/AddPrimaryKeyOnUuidColumnOfRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/DropPrimaryKeyOnIdColumnOfRulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/AddPrimaryKeyOnUuidColumnOfRulesParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/AddPrimaryKeyOnUuidColumnOfRulesProfilesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/snapshots/issues/AddPrimaryKeyOnUuidColumnOfSnapshotsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/snapshots/issues/DropPrimaryKeyOnIdColumnOfSnapshotsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/userroles/AddPrimaryKeyOnUuidColumnOfUserRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/userroles/DropPrimaryKeyOnIdColumnOfUserRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/AddPrimaryKeyOnUuidColumnOfUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/DropPrimaryKeyOnIdColumnOfUsersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/usertokens/AddPrimaryKeyOnUuidColumnOfUserTokensTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/usertokens/DropPrimaryKeyOnIdColumnOfUserTokensTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/util/AddPrimaryKeyBuilder.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/util/DropPrimaryKeySqlGenerator.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v86/AddPkToApplicationBranchProjs.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v86/AddPkToApplicationProjects.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v86/AddPrimaryKeyToDefaultQProfiles.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v86/DropDefaultQProfilesPk.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v86/DropOrganizationInRulesMetadata.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/AddPrimaryKeyBuilderTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdFromComponentsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activeruleparameters/DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/activerules/DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/ceactivity/DropPrimaryKeyOnIdColumnOfCeActivityTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/filesources/DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/groups/DropPrimaryKeyOnIdColumnOfGroupsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/manualmeasures/DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/notifications/DropPrimaryKeyOnIdColumnOfNotificationTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permissiontemplates/DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesgroups/DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtemplatesusers/DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/permtplcharacteristics/DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectmeasures/DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/projectqprofiles/DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/properties/DropPrimaryKeyOnIdColumnOfPropertiesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygateconditions/DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/DropPrimaryKeyOnIdColumnOfRulesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/rulesmetadata/DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesparameters/DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rulesprofiles/DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/snapshots/DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/DropPrimaryKeyOnIdColumnOfUsersTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/users/fk/organizationmembers/DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/usertokens/DropPrimaryKeyOnIdColumnOfUserTokensTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/util/AddPrimaryKeyBuilderTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/util/DropPrimaryKeySqlGeneratorTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v86/DropDefaultQProfilesPkTest.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql [new file with mode: 0644]

index 373250ca965a4f76e8bbac8d4f69f5fc452eaefb..4c0c32e8080238b682157fd9626bc005ab80f5bd 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.server.platform.db.migration;
 import org.sonar.core.platform.Module;
 import org.sonar.server.platform.db.migration.history.MigrationHistoryImpl;
 import org.sonar.server.platform.db.migration.history.MigrationHistoryMeddler;
+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.MigrationStepRegistryImpl;
 import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
 import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
@@ -30,8 +32,6 @@ import org.sonar.server.platform.db.migration.version.v81.DbVersion81;
 import org.sonar.server.platform.db.migration.version.v82.DbVersion82;
 import org.sonar.server.platform.db.migration.version.v83.DbVersion83;
 import org.sonar.server.platform.db.migration.version.v84.DbVersion84;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 import org.sonar.server.platform.db.migration.version.v85.DbVersion85;
 import org.sonar.server.platform.db.migration.version.v86.DbVersion86;
 
@@ -57,8 +57,8 @@ public class MigrationConfigurationModule extends Module {
       MigrationHistoryImpl.class,
       MigrationHistoryMeddler.class,
 
-      // Only needed for 8.3
-      SqlHelper.class,
+      // Utility classes
+      DbPrimaryKeyConstraintFinder.class,
       DropPrimaryKeySqlGenerator.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/AddPrimaryKeyBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/AddPrimaryKeyBuilder.java
new file mode 100644 (file)
index 0000000..c803080
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
+import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.PRIMARY_KEY_PREFIX;
+
+public class AddPrimaryKeyBuilder {
+
+  private final String tableName;
+  private final List<String> primaryKey;
+
+  public AddPrimaryKeyBuilder(String tableName, String column, String... moreColumns) {
+    this.tableName = validateTableName(tableName);
+    this.primaryKey = Lists.asList(column, moreColumns).stream().filter(Objects::nonNull).collect(Collectors.toList());
+  }
+
+  public String build() {
+    checkState(!primaryKey.isEmpty(), "Primary key is missing");
+    return format("ALTER TABLE %s ADD CONSTRAINT %s%s PRIMARY KEY (%s)", tableName, PRIMARY_KEY_PREFIX, tableName,
+      String.join(",", this.primaryKey));
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinder.java
new file mode 100644 (file)
index 0000000..7736588
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Locale;
+import java.util.Optional;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static java.lang.String.format;
+
+public class DbPrimaryKeyConstraintFinder {
+
+  private final Database db;
+
+  public DbPrimaryKeyConstraintFinder(Database db) {
+    this.db = db;
+  }
+
+  public String findConstraintName(String tableName) throws SQLException {
+    String constraintQuery = getDbVendorSpecificQuery(tableName);
+    return executeQuery(constraintQuery)
+      .orElseThrow(() -> constraintNotFoundException(tableName));
+  }
+
+  String getDbVendorSpecificQuery(String tableName) {
+    Dialect dialect = db.getDialect();
+    String constraintQuery;
+    switch (dialect.getId()) {
+      case PostgreSql.ID:
+        constraintQuery = getPostgresSqlConstraintQuery(tableName);
+        break;
+      case MsSql.ID:
+        constraintQuery = getMssqlConstraintQuery(tableName);
+        break;
+      case Oracle.ID:
+        constraintQuery = getOracleConstraintQuery(tableName);
+        break;
+      case H2.ID:
+        constraintQuery = getH2ConstraintQuery(tableName);
+        break;
+      default:
+        throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
+    }
+    return constraintQuery;
+  }
+
+  private Optional<String> executeQuery(String query) throws SQLException {
+    try (Connection connection = db.getDataSource().getConnection();
+      PreparedStatement pstmt = connection
+        .prepareStatement(query);
+      ResultSet rs = pstmt.executeQuery()) {
+      if (rs.next()) {
+        return Optional.ofNullable(rs.getString(1));
+      }
+      return Optional.empty();
+    }
+  }
+
+  private static String getPostgresSqlConstraintQuery(String tableName) {
+    return format("SELECT conname " +
+      "FROM pg_constraint " +
+      "WHERE conrelid = " +
+      "    (SELECT oid " +
+      "    FROM pg_class " +
+      "    WHERE relname LIKE '%s')", tableName);
+  }
+
+  private static String getMssqlConstraintQuery(String tableName) {
+    return format("SELECT name " +
+      "FROM sys.key_constraints " +
+      "WHERE type = 'PK' " +
+      "AND OBJECT_NAME(parent_object_id) = '%s'", tableName);
+  }
+
+  private static String getOracleConstraintQuery(String tableName) {
+    return format("SELECT constraint_name " +
+      "FROM user_constraints " +
+      "WHERE table_name = UPPER('%s') " +
+      "AND constraint_type='P'", tableName);
+  }
+
+  private static String getH2ConstraintQuery(String tableName) {
+    return format("SELECT constraint_name "
+      + "FROM information_schema.constraints "
+      + "WHERE table_name = '%s' and constraint_type = 'PRIMARY KEY'", tableName.toUpperCase(Locale.ENGLISH));
+  }
+
+  static IllegalStateException constraintNotFoundException(String tableName) {
+    return new IllegalStateException(format("Cannot find constraint for table '%s'", tableName));
+  }
+
+  // FIXME:: this method should be moved somewhere else
+  String getPostgresSqlSequence(String tableName, String columnName) throws SQLException {
+    try (Connection connection = db.getDataSource().getConnection();
+      PreparedStatement pstmt = connection.prepareStatement(format("SELECT pg_get_serial_sequence('%s', '%s')", tableName, columnName));
+      ResultSet rs = pstmt.executeQuery()) {
+      if (rs.next()) {
+        return rs.getString(1);
+      }
+      throw new IllegalStateException(format("Cannot find sequence for table '%s' on column '%s'", tableName, columnName));
+    }
+  }
+
+}
index f61fc97eb7d21d855891063f1b26ccd1e80a30b7..c4dbd3dbac5bc18ce808f3d7079d15cc2905037f 100644 (file)
@@ -30,6 +30,11 @@ import static java.util.Collections.singletonList;
 import static org.sonar.server.platform.db.migration.def.Validations.validateIndexName;
 import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
 
+/**
+ * This builder have the main goal to drop constraint of a column.
+ * <p>
+ * It shouldn't be used to drop primary keys constraint, use {@link DropPrimaryKeySqlGenerator}
+ */
 public class DropConstraintBuilder {
 
   private final Dialect dialect;
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java
new file mode 100644 (file)
index 0000000..cd965df
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static java.lang.String.format;
+import static java.util.Collections.singletonList;
+
+public class DropPrimaryKeySqlGenerator {
+  private static final String GENERIC_DROP_CONSTRAINT_STATEMENT = "ALTER TABLE %s DROP CONSTRAINT %s";
+
+  private final Database db;
+  private final DbPrimaryKeyConstraintFinder dbConstraintFinder;
+
+  public DropPrimaryKeySqlGenerator(Database db, DbPrimaryKeyConstraintFinder dbConstraintFinder) {
+    this.db = db;
+    this.dbConstraintFinder = dbConstraintFinder;
+  }
+
+  public List<String> generate(String tableName, String columnName, boolean isAutoGenerated) throws SQLException {
+    Dialect dialect = db.getDialect();
+    String constraintName = dbConstraintFinder.findConstraintName(tableName);
+    switch (dialect.getId()) {
+      case PostgreSql.ID:
+        return generateForPostgresSql(tableName, columnName, constraintName);
+      case MsSql.ID:
+        return generateForMsSql(tableName, constraintName);
+      case Oracle.ID:
+        return generateForOracle(tableName, constraintName, isAutoGenerated);
+      case H2.ID:
+        return generateForH2(tableName, constraintName);
+      default:
+        throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
+    }
+  }
+
+  private List<String> generateForPostgresSql(String tableName, String column, String constraintName) throws SQLException {
+    List<String> statements = new ArrayList<>();
+    statements.add(format("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT", tableName, column));
+
+    String sequence = dbConstraintFinder.getPostgresSqlSequence(tableName, column);
+    if (sequence != null) {
+      statements.add(format("DROP SEQUENCE %s", sequence));
+    }
+
+    statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
+
+    return statements;
+  }
+
+  private static List<String> generateForOracle(String tableName, String constraintName, boolean isAutoGenerated) {
+    List<String> statements = new ArrayList<>();
+    if (isAutoGenerated) {
+      statements.add(format("DROP TRIGGER %s_IDT", tableName));
+      statements.add(format("DROP SEQUENCE %s_SEQ", tableName));
+    }
+
+    // 'drop index' at the end ensures that associated index with primary key will be deleted
+    statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT + " DROP INDEX", tableName, constraintName));
+    return statements;
+  }
+
+  private static List<String> generateForMsSql(String tableName, String constraintName) {
+    return singletonList(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
+  }
+
+  private static List<String> generateForH2(String tableName, String constraintName) {
+    return singletonList(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
+  }
+
+}
index c38a8c66368a85f617519da756bdbd931818a918..9b6b6845583345b7113aea1091287430e07e5f34 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.server.platform.db.migration.version.v83;
 import java.sql.SQLException;
 import org.sonar.db.Database;
 import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropIdFromComponentsTable extends DdlChange {
 
index eecba7ac96c82b8fc6a7e5ec6fefd8e8e4ae9b9e..e17439e5332055c76f4e86c496041f320c20d639 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.activeruleparameters;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable extends DdlChange {
 
index 8d03f0e69d9150cc514aa3f783eeacd90d74f536..46072388afe5b3799db71f915240fedbe98bf110 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.activeruleparameters;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "active_rule_parameters";
index 533804ceca5594ce841de70e3ddc2de279b9d82f..b8e4b80ec4fd62ded2624a60295e0321dc12513a 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.activerules;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfActiveRulesTable extends DdlChange {
 
index 325a330cc9711ed787b44bdda44acf333576e02d..b5b43d8d32584296726bb1f4abdbcecf3fc9340e 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.activerules;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfActiveRulesTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "active_rules";
index e76cd130ac840af8e817d31406d27af86b917587..45ee47c8675e176017166ba9c0d705e27396043e 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.ceactivity;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfCeActivityTable extends DdlChange {
 
index 6e8050569db78d44b9cdeb720000e067eabf1a6e..73901ff43e6266e770fc30aff298755372f3da63 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.ceactivity;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfCeActivityTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "ce_activity";
index cee57f12796cd2cbdd39395394a5b7e58ceb55da..5b76b820d2bebe1c61b84f5ce8e2ac4c4d826974 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.cequeue;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfCeQueueTable extends DdlChange {
 
index d893f90acf4d7024bd8c26c4ca365385ee6daa36..2687e49174aab5aca0290494cde814a9865da5fa 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.cequeue;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfCeQueueTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "ce_queue";
index ccb17dba7dcc439b8588bfa8522f30f91ec686e3..c9a67edb082b856a5e76045ba4036ded2deb93a1 100644 (file)
@@ -21,12 +21,12 @@ package org.sonar.server.platform.db.migration.version.v84.common;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public abstract class DropPrimaryKeyOnIdColumn extends DdlChange {
   private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
-  private String tableName;
+  private final String tableName;
 
   protected DropPrimaryKeyOnIdColumn(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator, String tableName) {
     super(db);
index 8cc709820f927a3753b41b849c140c8a1c378263..cbf21d0b8c181ccfc53a3865b44d8b3f5abbd860 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.duplicationsindex;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable extends DdlChange {
 
index 1899060853409890fa9c30be6795741a340f9c78..cce9473f58288c0096244e35224a518a779f7370 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.duplicationsindex;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "duplications_index";
index be9c8545a3b6d7f1041d2395ff7689916a6679de..1c4360b7184b5999cf87357e0af5def9b857d83d 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.events;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfEventsTable extends DdlChange {
 
index f2dc33dd0707f53c6f0f133ece493407238bead2..20ed85bafadffedde0d4337093e9c65b53b35573 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.events;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfEventsTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "events";
index 0a0c67869fd1f5f9b92aaf1c1cb89c6b3c0087c5..e7600955d1efe46e82a0815a9b0850fe0ebb0568 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.filesources;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfFileSourcesTable extends DdlChange {
 
index 954e562f1ac681b0f079dfd19115598ebefade7f..a3b77edee5f8c589f53e6083e66df00ca3fbe99d 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.filesources;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfFileSourcesTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "file_sources";
index d7d62af77a77ec0a162914a47cd3066bd6808edc..6676218cd50ed81f6d70a03237ca2c92a8b2a7fe 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.grouproles;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfGroupRolesTable extends DdlChange {
 
index af8fa265219cbc5d3721d0a64ec94a6a618436af..41a97a8d4ae5ae0ece4c0a7b0233bc6b5b048c2e 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.grouproles;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfGroupRolesTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "group_roles";
index c3bc655bc8193691638aea280c8cfa35cefa1f0d..47318814bb42f42016a082ce89262b3b7d30bf09 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.groups;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfGroupsTable extends DdlChange {
 
index 6759868372bb3247836a90144723dec4fd07d2c0..cee530a8c77cc59d03fdf1154115ec7cd3325a17 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.groups;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfGroupsTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "groups";
index d8515339139e73d36972476810413fafcdb73ee2..42974da5ebc3d2b48ffa179e75ed2f69a297baea 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.issuechanges;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfIssueChangesTable extends DdlChange {
 
index 9210d878ee283d22545d7b8f9f5708faf82068b6..c44c514a497c5e1736842e607e1ce008f8a12644 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.issues;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnKeeColumnOfIssuesTable extends DdlChange {
   private static final String TABLE_NAME = "issues";
index cbcc2fca86b2a41fce65ac0a774bf4a309e95608..8727da65182b156035987a6a7396694da63ae314 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.manualmeasures;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfManualMeasuresTable extends DdlChange {
 
index 72c50f74b6872ac1f700055e26298b91e586dd4f..5b0028e8aeddf6b0762111f2c1da32c9d18c4ba5 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.manualmeasures;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfManualMeasuresTable extends DdlChange {
 
index 708d91ad4df7a905b0e3f9df6a99a2394b282133..40185a52fd2bc5cd0d928a45bd535ea074cd641e 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.metrics;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfMetricsTable extends DdlChange {
 
index 7b648ae092e1d9231d4765308028d59ffe5c5395..148c416a050a5f8acffd239e3a5e9dc9ecc759d6 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.metrics;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfMetricsTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "metrics";
index b1fefefb1456c8d78f09664a72b2e3f3766e518b..b98d91123ab8d54f513a075fd4ca623592ea13a3 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPKeyOnUuidOfLiveMeasuresTable extends DdlChange {
   private static final String TABLE_NAME = "live_measures";
index 3b543820aaf0e2e60529d8735c73dbfc562a7c0c..ea2f30d87b10e8f087aed6de37e0befbab5e7d71 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.notifications;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfNotificationTable extends DdlChange {
 
index f103794e537aee152de7209b9ab1af1c7615bf00..4cfc4b317b46fcd969d845c1beccab5c20f0f2dc 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.notifications;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfNotificationTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "notifications";
index 02546b6fa3bffb3ed803d35cc6f483d96bd966ca..967e410b245da2bedb196b102b981618d6bc6f97 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.permissiontemplates;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfPermissionTemplatesTable extends DdlChange {
 
index dd699378242c6afb0f0a3dc73d984c15ce88ac70..be675e16f84849ae429c5cce0e4eac5dfdd8c4f3 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.permissiontemplates;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "permission_templates";
index 0aaf0b182ba1c131783f2bcb1476deb877635af3..6e82399f888399021b85a32aafb33986084951f3 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.permtemplatesgroups;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable extends DdlChange {
 
index 0411a6c8ad0853d46a7df72d7060cd1c128acfd2..3ecc3dd14429c3605bc5a8ec315b0f504668648f 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.permtemplatesgroups;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "perm_templates_groups";
index baf679d9b42d16da9d9d98473a11cac67237b0bd..6afee11dbea0ecb5204d38f04e4452b4ef4e56c4 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.permtemplatesusers;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable extends DdlChange {
 
index 209d31fe87cad4c5000dd4e7dd8f502e70a19b46..44d526d4c2b41425cbc809b23cd12a0941b350c0 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.permtemplatesusers;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "perm_templates_users";
index 348635f10b3ac56ab06d41b1a923e26114d7dcfd..91d083efd56246a6e99651f69f34956d30a89a62 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.permtplcharacteristic
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable extends DdlChange {
 
index 96375daccbea63af118a996924a0610a82ef6466..c693aaeddf747907c60cdc95b4ab9a04a0cb5952 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.permtplcharacteristics;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "perm_tpl_characteristics";
index 312c9bd86edbb4578db290ce19d731db8e1141e8..a72fb11c2b259a2e782ec8a55dfd225c7c5c1a71 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.projectmeasures;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable extends DdlChange {
 
index f37523647bce55d29687df8da634693044cba147..09aeee4b2cbcc44ad24cd021e41b9557fcf66dca 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.projectmeasures;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "project_measures";
index c47e26cb3d0d07f95b7e8918cedcdb1b9d6a9d71..f3403e230539f9d03b3e2ba5e7209c58ff4141bc 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.projectqprofiles;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfProjectQProfilesTable extends DdlChange {
 
index fb86b8b1df87bc2b3230be28068a150770e55fbe..361339b7aadef3cca3136233c1cbe5ec1ba511e2 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.projectqprofiles;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfProjectQProfilesTable extends DdlChange {
 
index d86eb0578e945689760691bea52fc8692ecf8c04..3bc5072abca02622ee6a82deffd3ad8f6e9c6230 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.properties;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfPropertiesTable extends DdlChange {
 
index 53d1f0fa25986da5ceda9c6cf5b522f7a000e029..b6b6ac90007f4d17a673e0e391c205b04ddd1abc 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.properties;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfPropertiesTable extends DropPrimaryKeyOnIdColumn {
 
index 7cb786d5d53dcea28d4738817a058c35a6beb821..2512809391411247f9b89e65abe87d7a0a62669d 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.qualitygateconditions
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable extends DdlChange {
 
index 5008c4068a81bc300765035938630168fba59e79..3a6f5d2f6e3eadfaa5c21057790b50ecd6ea557e 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.qualitygateconditions;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "quality_gate_conditions";
index 13881446536fcf3f7c9f97f3bb854428087a5d9d..c0b5fce718f683ae0259044002f612e0495b4d3a 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.qualitygates;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfQGatesTable extends DdlChange {
 
index d163d436f74197a3b182d855d624638e70d520d5..2681535bd5dfecfd4f0348aef7cd2ede2723417c 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.qualitygates;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfQGatesTable extends DropPrimaryKeyOnIdColumn {
 
index 2b4c6b6aefcb82250302292060e6b600b91c8d3c..ff621df1d0cfae924f8db2043f6570dc5ca094ad 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.rules;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfRulesTable extends DdlChange {
 
index 362aa8873edc0ebc4fda1d9dc9f2cd9458fe646c..7a31d61f957105e3ebb8476c6a467080d54657e5 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.rules;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfRulesTable extends DdlChange {
 
index fad1c61489ffc1701411ab58d88cd8eb9140b445..9e21632f3b31fbbe970574f9d6518999dd704f7b 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.rules.rulesmetadata;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable extends DdlChange {
 
index 62ff3000211e4bcea0b27653aaa6234dc935ea0d..71ce8f41b3f93a9fdadc4fd071e6d410540d8d78 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.rules.rulesmetadata;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfRulesMetadataTable extends DdlChange {
 
index d2fd3271aeb6f60d0795609fb4a5ac32dea51316..139caacf744195fac61eefe9bc5651d86c0797f0 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.rulesparameters;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfRulesParametersTable extends DdlChange {
 
index f2b4984d361a986e4fdf7e5dae64d9cceb4cfe38..c9e4462b1bb0bb673482fbdd294553dc3693251d 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.rulesparameters;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfRulesParametersTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "rules_parameters";
index e0be6487c77657a4018945ced55dd64f816d9a7e..42b57d69e58e044014b8b738171e3cdcb9a91a5b 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.rulesprofiles;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfRulesProfilesTable extends DdlChange {
 
index ecbece18360c4626e7c8663320f19f8292e20dc5..86ad970794f156882673f6a888454a2fc63c21f7 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.rulesprofiles;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfRulesProfilesTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "rules_profiles";
index f6654ab66ee97631d13d45281445ec246e6f8f82..f063c3822f6f15e0d4cc175f00716ea3bae171f4 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.snapshots.issues;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfSnapshotsTable extends DdlChange {
 
index c79ad62a279640bcf4d41027fe6d431bcd44cc5b..a9f0ff948a6c89342e9c60e23f9c2ce95c1e8314 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.snapshots.issues;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfSnapshotsTable extends DdlChange {
 
index 098d8282453b20d248ade8ba2e335577f079fe32..7204570bbb5b503429556f6d81010df7bd8a725b 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.userroles;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfUserRolesTable extends DdlChange {
 
index 3bf847a30707857c4d989aa2275d533864a1ecda..5ebcfd2b32a3f9635d71ad4ca9808465112c8a81 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.userroles;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfUserRolesTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "user_roles";
index 94dd321dae91807e1952e292789ef1f5ed877473..5a9439c31c9d82ccd6a058e8f6d26e9b58d5eef2 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.users;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfUsersTable extends DdlChange {
 
index 923745c3c95f511a6c6b501f5f19648ff08491d3..daa454ca5596fbd27d7a5eaa9293d3a26d494bad 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.users;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfUsersTable extends DropPrimaryKeyOnIdColumn {
 
index 20bc5d8f6c63f2c656454b96d11c2caed883da2a..5fe52e6dc8fd5f6d5050a71ecb7bc35d35687e68 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.users.fk.organization
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable extends DdlChange {
 
index 0a8f74b254846f156adb79249f75540aa87bd7a5..ca9e233325a4bc764c9e17c9b86ed9924b9313f1 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.users.fk.organization
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable extends DdlChange {
   private static final String TABLE_NAME = "organization_members";
index 114aaaef179591cfee92a77f1821b63c4f3f8d54..4c591ec5a206bd2964e09a03ecd621f9f6dc4039 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v84.usertokens;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidColumnOfUserTokensTable extends DdlChange {
 
index ef09bb82587db0c08708c3e9a4c0f14b9e6621b1..1ea943ef4bc69e16562446d6d746205eb9e5ba6c 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.db.migration.version.v84.usertokens;
 
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
 
 public class DropPrimaryKeyOnIdColumnOfUserTokensTable extends DropPrimaryKeyOnIdColumn {
   private static final String TABLE_NAME = "user_tokens";
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/util/AddPrimaryKeyBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/util/AddPrimaryKeyBuilder.java
deleted file mode 100644 (file)
index 8772a2a..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import com.google.common.collect.Lists;
-import java.util.List;
-
-import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
-import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
-import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.PRIMARY_KEY_PREFIX;
-
-public class AddPrimaryKeyBuilder {
-
-  private final String tableName;
-  private final List<String> primaryKey;
-
-  public AddPrimaryKeyBuilder(String tableName, String column, String... moreColumns) {
-    this.tableName = validateTableName(tableName);
-    this.primaryKey = Lists.asList(column, moreColumns);
-  }
-
-  public String build() {
-    checkState(primaryKey != null, "Primary key is missing");
-    return format("ALTER TABLE %s ADD CONSTRAINT %s%s PRIMARY KEY (%s)", tableName, PRIMARY_KEY_PREFIX, tableName,
-      String.join(",", this.primaryKey));
-  }
-
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/util/DropPrimaryKeySqlGenerator.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/util/DropPrimaryKeySqlGenerator.java
deleted file mode 100644 (file)
index 81a317f..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.MsSql;
-import org.sonar.db.dialect.Oracle;
-import org.sonar.db.dialect.PostgreSql;
-
-import static java.lang.String.format;
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-
-public class DropPrimaryKeySqlGenerator {
-  private static final String GENERIC_DROP_CONSTRAINT_STATEMENT = "ALTER TABLE %s DROP CONSTRAINT %s";
-
-  private final Database db;
-  private SqlHelper sqlHelper;
-
-  public DropPrimaryKeySqlGenerator(Database db, SqlHelper sqlHelper) {
-    this.db = db;
-    this.sqlHelper = sqlHelper;
-  }
-
-  public List<String> generate(String tableName, String columnName, boolean isAutoGenerated) throws SQLException {
-    Dialect dialect = db.getDialect();
-    switch (dialect.getId()) {
-      case PostgreSql.ID:
-        return generateForPostgresSql(tableName, columnName, sqlHelper.getPostgresSqlConstraint(tableName));
-      case MsSql.ID:
-        return generateForMsSql(tableName, sqlHelper.getMssqlConstraint(tableName));
-      case Oracle.ID:
-        return generateForOracle(tableName, sqlHelper.getOracleConstraint(tableName), isAutoGenerated);
-      case H2.ID:
-        return generateForH2(tableName, columnName, sqlHelper.getH2Constraint(tableName));
-      default:
-        throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
-    }
-  }
-
-  private List<String> generateForPostgresSql(String tableName, String column, String constraintName) throws SQLException {
-    List<String> statements = new ArrayList<>();
-    statements.add(format("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT", tableName, column));
-
-    String sequence = sqlHelper.getPostgresSqlSequence(tableName, column);
-    if (sequence != null) {
-      statements.add(format("DROP SEQUENCE %s", sequence));
-    }
-
-    statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
-
-    return statements;
-  }
-
-  private static List<String> generateForOracle(String tableName, String constraintName, boolean isAutoGenerated) {
-    List<String> statements = new ArrayList<>();
-    if (isAutoGenerated) {
-      statements.add(format("DROP TRIGGER %s_IDT", tableName));
-      statements.add(format("DROP SEQUENCE %s_SEQ", tableName));
-    }
-
-    // 'drop index' at the end ensures that associated index with primary key will be deleted
-    statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT + " DROP INDEX", tableName, constraintName));
-    return statements;
-  }
-
-  private static List<String> generateForMsSql(String tableName, String constraintName) {
-    return singletonList(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
-  }
-
-  private static List<String> generateForH2(String tableName, String column, String constraintName) {
-    return asList(
-      format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName),
-      format("ALTER TABLE %s ALTER COLUMN %s INTEGER NOT NULL", tableName, column));
-  }
-
-}
index 2ba54f4a7375fafe36681735687536e75b1c27a1..6e6b801823792fc2d6111edec3d5849864678d5d 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v85;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnUuidForIssueChangesTable extends DdlChange {
 
index 615b03f4144d52a69d2e6d6c3b57b9ddc3b19ec3..15ac2197bea79de6337c2dc4c4caa93a78505dfe 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v86;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPkToApplicationBranchProjs extends DdlChange {
   private static final String TABLE = "app_branch_project_branch";
index 0aa5bb6bf2300ee295bfe1eed89fa62686bcc017..fb96e767806385c73117e4f6233091f830850522 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v86;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPkToApplicationProjects extends DdlChange {
   private static final String TABLE = "app_projects";
index 5ff6fa5e9fb68347103de3959ea7e8e2a24a9382..70f844b9287d22f29a6f70426a8f663a2c177375 100644 (file)
@@ -21,8 +21,8 @@ package org.sonar.server.platform.db.migration.version.v86;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyToDefaultQProfiles extends DdlChange {
   public AddPrimaryKeyToDefaultQProfiles(Database db) {
index f9408bbbc553aaff3d3a8bd12a504cae847c351b..b4b2e6563bbab2ea4cb7652832cfe40bd36e194c 100644 (file)
@@ -21,16 +21,21 @@ package org.sonar.server.platform.db.migration.version.v86;
 
 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.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.DdlChange;
 
 public class DropDefaultQProfilesPk extends DdlChange {
-  public DropDefaultQProfilesPk(Database db) {
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+  private static final String TABLE_NAME = "default_qprofiles";
+  private static final String COLUMN_NAME = "language";
+
+  public DropDefaultQProfilesPk(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
     super(db);
+    this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
   }
 
   @Override
   public void execute(Context context) throws SQLException {
-    context.execute(new DropConstraintBuilder(getDialect()).setName("pk_default_qprofiles").setTable("default_qprofiles").build());
+    context.execute(dropPrimaryKeySqlGenerator.generate(TABLE_NAME, COLUMN_NAME, false));
   }
 }
index a6b7e358fd59c11e944b8de17f5832c318bd7854..32690e3df8dfe41828fa1a85050a64edfb494480 100644 (file)
@@ -21,10 +21,10 @@ package org.sonar.server.platform.db.migration.version.v86;
 
 import java.sql.SQLException;
 import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
 import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
 import org.sonar.server.platform.db.migration.sql.DropConstraintBuilder;
 import org.sonar.server.platform.db.migration.step.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class DropOrganizationInRulesMetadata extends DdlChange {
   private static final String TABLE_NAME = "rules_metadata";
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/AddPrimaryKeyBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/AddPrimaryKeyBuilderTest.java
new file mode 100644 (file)
index 0000000..a57cc4e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyBuilderTest {
+
+  private static final String TABLE_NAME = "issues";
+
+  @Test
+  public void generate() {
+    String sql = new AddPrimaryKeyBuilder(TABLE_NAME, "id").build();
+
+    assertThat(sql).isEqualTo("ALTER TABLE issues ADD CONSTRAINT pk_issues PRIMARY KEY (id)");
+  }
+
+  @Test
+  public void fail_when_table_name_is_invalid() {
+    assertThatThrownBy(() -> new AddPrimaryKeyBuilder("abcdefghijklmnopqrstuvwxyz", "id"))
+      .isInstanceOf(IllegalArgumentException.class);
+  }
+
+  @Test
+  public void fail_when_primary_key_column_is_invalid() {
+    AddPrimaryKeyBuilder builder = new AddPrimaryKeyBuilder("my_table", null);
+    assertThatThrownBy(builder::build)
+      .isInstanceOf(IllegalStateException.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java
new file mode 100644 (file)
index 0000000..dbe5b2c
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DbPrimaryKeyConstraintFinderTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DbPrimaryKeyConstraintFinderTest.class, "schema.sql");
+
+  private final Database dbMock = mock(Database.class);
+  private final DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(dbMock);
+
+  private static final PostgreSql POSTGRESQL = new PostgreSql();
+  private static final MsSql MS_SQL = new MsSql();
+  private static final Oracle ORACLE = new Oracle();
+  private static final org.sonar.db.dialect.H2 H2 = new H2();
+
+  @Test
+  public void findConstraintName_constraint_exists() throws SQLException {
+    DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database());
+    String constraintName = underTest.findConstraintName("TEST_PRIMARY_KEY");
+    assertThat(constraintName).isEqualTo("PK_TEST_PRIMARY_KEY");
+  }
+
+  @Test
+  public void findConstraintName_constraint_not_exist() {
+    DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database());
+    assertThatThrownBy(() -> underTest.findConstraintName("NOT_EXISTING_TABLE"))
+      .hasMessage("Cannot find constraint for table 'NOT_EXISTING_TABLE'")
+      .isInstanceOf(IllegalStateException.class);
+  }
+
+  @Test
+  public void getDbVendorSpecificQuery_mssql() {
+    when(dbMock.getDialect()).thenReturn(MS_SQL);
+
+    assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+      .isEqualTo("SELECT name FROM sys.key_constraints WHERE type = 'PK' AND OBJECT_NAME(parent_object_id) = 'my_table'");
+  }
+
+  @Test
+  public void getDbVendorSpecificQuery_postgresql() {
+    when(dbMock.getDialect()).thenReturn(POSTGRESQL);
+
+    assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+      .isEqualTo("SELECT conname FROM pg_constraint WHERE conrelid =     (SELECT oid     FROM pg_class     WHERE relname LIKE 'my_table')");
+  }
+
+  @Test
+  public void getDbVendorSpecificQuery_oracle() {
+    when(dbMock.getDialect()).thenReturn(ORACLE);
+
+    assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+      .isEqualTo("SELECT constraint_name FROM user_constraints WHERE table_name = UPPER('my_table') AND constraint_type='P'");
+  }
+
+  @Test
+  public void getDbVendorSpecificQuery_h2() {
+    when(dbMock.getDialect()).thenReturn(H2);
+
+    assertThat(underTest.getDbVendorSpecificQuery("my_table"))
+      .isEqualTo("SELECT constraint_name FROM information_schema.constraints WHERE table_name = 'MY_TABLE' and constraint_type = 'PRIMARY KEY'");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGeneratorTest.java
new file mode 100644 (file)
index 0000000..8b1137a
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.sql;
+
+import java.sql.SQLException;
+import java.util.List;
+import org.junit.Test;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DropPrimaryKeySqlGeneratorTest {
+
+  private static final String TABLE_NAME = "issues";
+  private static final String PK_COLUMN = "id";
+  private static final String CONSTRAINT = "pk_id";
+
+  private static final PostgreSql POSTGRESQL = new PostgreSql();
+  private static final MsSql MS_SQL = new MsSql();
+  private static final Oracle ORACLE = new Oracle();
+  private static final org.sonar.db.dialect.H2 H2 = new H2();
+
+  private final Database db = mock(Database.class);
+  private final DbPrimaryKeyConstraintFinder dbConstraintFinder = mock(DbPrimaryKeyConstraintFinder.class);
+
+  private final DropPrimaryKeySqlGenerator underTest = new DropPrimaryKeySqlGenerator(db, dbConstraintFinder);
+
+  @Test
+  public void generate_unknown_dialect() {
+    Dialect mockDialect = mock(Dialect.class);
+    when(mockDialect.getId()).thenReturn("unknown-db-vendor");
+    when(db.getDialect()).thenReturn(mockDialect);
+
+    assertThatThrownBy(() -> underTest.generate(TABLE_NAME, PK_COLUMN, true))
+      .isInstanceOf(IllegalStateException.class);
+  }
+
+  @Test
+  public void generate_for_postgres_sql() throws SQLException {
+    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+    when(dbConstraintFinder.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(TABLE_NAME + "_id_seq");
+    when(db.getDialect()).thenReturn(POSTGRESQL);
+
+    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+    assertThat(sqls).containsExactly("ALTER TABLE issues ALTER COLUMN id DROP DEFAULT",
+      "DROP SEQUENCE issues_id_seq",
+      "ALTER TABLE issues DROP CONSTRAINT pk_id");
+  }
+
+  @Test
+  public void generate_for_postgres_sql_no_seq() throws SQLException {
+    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+    when(dbConstraintFinder.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(null);
+    when(db.getDialect()).thenReturn(POSTGRESQL);
+
+    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+    assertThat(sqls).containsExactly("ALTER TABLE issues ALTER COLUMN id DROP DEFAULT",
+      "ALTER TABLE issues DROP CONSTRAINT pk_id");
+  }
+
+  @Test
+  public void generate_for_ms_sql() throws SQLException {
+    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+    when(db.getDialect()).thenReturn(MS_SQL);
+
+    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+    assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id");
+  }
+
+  @Test
+  public void generate_for_oracle_autogenerated_true() throws SQLException {
+    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+    when(db.getDialect()).thenReturn(ORACLE);
+
+    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+    assertThat(sqls).containsExactly("DROP TRIGGER issues_IDT",
+      "DROP SEQUENCE issues_SEQ",
+      "ALTER TABLE issues DROP CONSTRAINT pk_id DROP INDEX");
+  }
+
+  @Test
+  public void generate_for_oracle_autogenerated_false() throws SQLException {
+    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+    when(db.getDialect()).thenReturn(ORACLE);
+
+    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, false);
+
+    assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id DROP INDEX");
+  }
+
+  @Test
+  public void generate_for_h2() throws SQLException {
+    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(CONSTRAINT);
+    when(db.getDialect()).thenReturn(H2);
+
+    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
+
+    assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id");
+  }
+}
index 86ae9b4812c0d174e0257aaf91b607f7cb671197..48ab42adc12383058f1a9e476879af90c6744d5e 100644 (file)
@@ -24,8 +24,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 
 import static java.sql.Types.INTEGER;
 import static org.sonar.server.platform.db.migration.version.v83.DropIdFromComponentsTable.COLUMN_NAME;
@@ -37,8 +37,8 @@ public class DropIdFromComponentsTableTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(dbTester.database(), new SqlHelper(dbTester.database()));
-  private DropIdFromComponentsTable underTest = new DropIdFromComponentsTable(dbTester.database(), dropPrimaryKeySqlGenerator);
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(dbTester.database(), new DbPrimaryKeyConstraintFinder(dbTester.database()));
+  private final DropIdFromComponentsTable underTest = new DropIdFromComponentsTable(dbTester.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void column_has_been_dropped() throws SQLException {
index 4900f0fec87f859bf0185955168be4cfe9eb81e4..f80e122edf7b611d7b7dd52ac3ee0af44f51d975 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfActiveRuleParametersTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index a0b0b18d8cef4d8cb1af5d34e3e0426efea41a4e..414f78d06592f146b9caf1a919fa16663ae3c83a 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfActiveRulesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfActiveRulesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfActiveRulesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfActiveRulesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index ce746d13e3d77dc10a1ebf33ed33d80a41192403..54339d852710c5ec5831038a7214ecb3d23b016b 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfCeActivityTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfCeActivityTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeActivityTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeActivityTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 1ddcecbf85f02aea3f37ecbf2847f1ee43c91617..b4da09704d347573ad2b58fff4bd881bd2307575 100644 (file)
@@ -24,9 +24,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfCeQueueTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfCeQueueTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeQueueTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeQueueTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 3ae0004ec58809a0f145e13649dff2917c0372b1..15f0da1ca29026a6b963ac16c01ce5b831af19fb 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 4e4a7a8b0cfdffa7c761bf5cbb4d653c2a74eacb..8250ee072938d336d49b3f4c7f4adbadc5a974ea 100644 (file)
@@ -24,8 +24,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.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfEventsTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfEventsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DropPrimaryKeyOnIdColumnOfEventsTable underTest = new DropPrimaryKeyOnIdColumnOfEventsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DropPrimaryKeyOnIdColumnOfEventsTable underTest = new DropPrimaryKeyOnIdColumnOfEventsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index b4add2d6133907f0918d26be601b7d3592931511..46d18993a0a3de635d0cbcb2e8a96bef76014311 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfFileSourcesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfFileSourcesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfFileSourcesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfFileSourcesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 670a6711c301f5690ea136aeadfbb928ffc67107..2f9cb01f019ee3309bf1782f72a2c01ea9e81a70 100644 (file)
@@ -24,8 +24,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.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfGroupRolesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DropPrimaryKeyOnIdColumnOfGroupRolesTable underTest = new DropPrimaryKeyOnIdColumnOfGroupRolesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DropPrimaryKeyOnIdColumnOfGroupRolesTable underTest = new DropPrimaryKeyOnIdColumnOfGroupRolesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 9986f83caff4f735e34a63fd8ca869ed6bb14d92..98a0a724d0d1d927d51e5042621f0a0837fd0255 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfGroupsTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 556e0cf9062a82c5d53e23f774a5ef2e0101d80a..33807090b25b13e48774987528e1591b6b44c2ab 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfManualMeasuresTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfManualMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfManualMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 35f85e4cc04ced01e890d6ec4cf84d67ec6638a2..70fed865fbcd63e315ec87564117c1305c6a7a1b 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfMetricsTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfMetricsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfMetricsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfMetricsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index c0f1931c4db61f8edd02f63ad9fa15a1b56ec255..ac5f71a68adfb1b476ab5cc7495563a760121872 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfNotificationTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfNotificationTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfNotificationTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfNotificationTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 2a95ef1e95f5da18bf7ec5f61b05d91b72a8f40b..7e0376d28572e99b17c8b94107aaa18cfc7839da 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfPermissionTemplatesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPermissionTemplatesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 998d78102e2ae588b29a6334e5a2da4d494c6dfe..aeb5fe459b344896268a59afb6514b5c45cb34e2 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -37,9 +37,9 @@ public class DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest {
   public CoreDbTester db = CoreDbTester.createForSchema(
     DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 90c54aceca4045aec182ac7b9f0dde76b3f6350d..7e8e2cde4937b3ccf2d3100c8f95150cb163b40f 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -37,9 +37,9 @@ public class DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest {
   public CoreDbTester db = CoreDbTester.createForSchema(
     DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 0a11ab48f98f84476b6789e955c8ba964ed86995..fa53ae43288b84e62f4f380bcbdf81999a4460a3 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -37,9 +37,9 @@ public class DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest {
   public CoreDbTester db = CoreDbTester.createForSchema(
     DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index b8f895d6842c34e68bd08a4cdd95b21ba4fb234e..cbe1e4b2b7f483522ed3feb0202d7a213c7bedbb 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfProjectMeasuresTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfProjectMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfProjectMeasuresTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 9e464b57dd0c8d3e1673869ae3d00f2da0e3e564..4e4094188241240c2795118e5e5a55bc2aeab62b 100644 (file)
@@ -23,9 +23,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -34,9 +34,9 @@ public class DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfProjectQProfilesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfProjectQProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfProjectQProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 0e3b583bec27f61d74d2e3869fd41f4d67feaf54..5d33702c092e13e624541ba99cb8272a02cf989b 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfPropertiesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfPropertiesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPropertiesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfPropertiesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 1b84fde48e558a5bafef40d172ef2e4af27b1ca7..615a0cf37d4c8e10cd708cbae89d22ff5c5f6829 100644 (file)
@@ -24,9 +24,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 3b47c7cf239e130b709e947b67e0e9a3aa37180c..ab6a98b54eec9cc3a8e3f9c5a9747228bd1736a0 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfQGatesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQGatesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfQGatesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfQGatesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index b54648c5e6de27b722680f60af0ee219f5acfb1b..595018573fa5c9e524deb5a25740fe447e501602 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -34,8 +34,8 @@ public class DropPrimaryKeyOnIdColumnOfRulesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesTableTest.class, "schema.sql");
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesTable(db.database(),
-    new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesTable(db.database(),
+    new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())));
 
   @Test
   public void execute() throws SQLException {
index 371079a67134ce1049cb8aa33dbe5c542f1f702f..031a8474b73a81621f538452f8cc12db36b140cb 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -34,8 +34,8 @@ public class DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesMetadataTableTest.class, "schema.sql");
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesMetadataTable(db.database(),
-    new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())));
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesMetadataTable(db.database(),
+    new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())));
 
   @Test
   public void execute() throws SQLException {
index 6cf0cdab7506819d4990479915ec69846da2cea3..86eb444fdb3e21e9e9d5cfe591238aad28397531 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfRulesParametersTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesParametersTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesParametersTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfRulesParametersTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index ad2dbeed17d60587734798d11a184ffba484aba4..55c9f279b302bd1cbe787f031c323ec3f7072cf1 100644 (file)
@@ -23,9 +23,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -34,9 +34,9 @@ public class DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfRulesProfilesTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfRulesProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfRulesProfilesTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index d2cb5ad5419835f7f65c78175aeb246e136e2e69..8b18972eaec3caffb64a6fd22369acee14407c8a 100644 (file)
@@ -24,9 +24,9 @@ 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.version.v84.snapshots.issues.DropPrimaryKeyOnIdColumnOfSnapshotsTable;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -36,9 +36,9 @@ public class DropPrimaryKeyOnIdColumnOfSnapshotsTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfSnapshotsTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DropPrimaryKeyOnIdColumnOfSnapshotsTable underTest = new DropPrimaryKeyOnIdColumnOfSnapshotsTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DropPrimaryKeyOnIdColumnOfSnapshotsTable underTest = new DropPrimaryKeyOnIdColumnOfSnapshotsTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index dc53112e842766d1a18bd483c12065ba50242f66..d7e0c4286511e1bd784c88bbb9f4aa7d9142c07a 100644 (file)
@@ -23,9 +23,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -34,9 +34,9 @@ public class DropPrimaryKeyOnIdColumnOfUsersTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfUsersTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfUsersTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnIdColumnOfUsersTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 4019839d54e03b114ce21e712835d65d973e0bb8..3ba6bb952eb12b7c7e8d215f247cdf5ae5039df7 100644 (file)
@@ -23,9 +23,9 @@ 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.DdlChange;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -34,9 +34,9 @@ public class DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private DdlChange underTest = new DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final DdlChange underTest = new DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
index 519e7c9140eea48bd90e057b8da8eff23eecf188..2491c4bee1b5a99fb146e37b25ffb02d0771e339 100644 (file)
@@ -23,9 +23,9 @@ 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;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,9 +35,9 @@ public class DropPrimaryKeyOnIdColumnOfUserTokensTableTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfUserTokensTableTest.class, "schema.sql");
 
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database()));
 
-  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfUserTokensTable(db.database(), dropPrimaryKeySqlGenerator);
+  private final MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfUserTokensTable(db.database(), dropPrimaryKeySqlGenerator);
 
   @Test
   public void execute() throws SQLException {
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/util/AddPrimaryKeyBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/util/AddPrimaryKeyBuilderTest.java
deleted file mode 100644 (file)
index ef69661..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class AddPrimaryKeyBuilderTest {
-
-  private static final String TABLE_NAME = "issues";
-
-  @Test
-  public void generate() {
-    String sql = new AddPrimaryKeyBuilder(TABLE_NAME, "id").build();
-
-    assertThat(sql).isEqualTo("ALTER TABLE issues ADD CONSTRAINT pk_issues PRIMARY KEY (id)");
-  }
-
-  @Test
-  public void fail_when_table_name_is_invalid() {
-    assertThatThrownBy(() -> new AddPrimaryKeyBuilder("abcdefghijklmnopqrstuvwxyz", "id").build())
-      .isInstanceOf(IllegalArgumentException.class);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/util/DropPrimaryKeySqlGeneratorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/util/DropPrimaryKeySqlGeneratorTest.java
deleted file mode 100644 (file)
index c18c8ef..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version.v84.util;
-
-import java.sql.SQLException;
-import java.util.List;
-import org.junit.Test;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.MsSql;
-import org.sonar.db.dialect.Oracle;
-import org.sonar.db.dialect.PostgreSql;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DropPrimaryKeySqlGeneratorTest {
-
-  private static final String TABLE_NAME = "issues";
-  private static final String PK_COLUMN = "id";
-  private static final String CONSTRAINT = "pk_id";
-
-  private static final PostgreSql POSTGRESQL = new PostgreSql();
-  private static final MsSql MS_SQL = new MsSql();
-  private static final Oracle ORACLE = new Oracle();
-  private static final org.sonar.db.dialect.H2 H2 = new H2();
-
-  private Database db = mock(Database.class);
-  private SqlHelper sqlHelper = mock(SqlHelper.class);
-
-  private DropPrimaryKeySqlGenerator underTest = new DropPrimaryKeySqlGenerator(db, sqlHelper);
-
-  @Test
-  public void generate_for_postgres_sql() throws SQLException {
-    when(sqlHelper.getPostgresSqlConstraint(TABLE_NAME)).thenReturn(CONSTRAINT);
-    when(sqlHelper.getPostgresSqlSequence(TABLE_NAME, "id")).thenReturn(TABLE_NAME + "_id_seq");
-    when(db.getDialect()).thenReturn(POSTGRESQL);
-
-    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
-    assertThat(sqls).containsExactly("ALTER TABLE issues ALTER COLUMN id DROP DEFAULT",
-      "DROP SEQUENCE issues_id_seq",
-      "ALTER TABLE issues DROP CONSTRAINT pk_id");
-  }
-
-  @Test
-  public void generate_for_ms_sql() throws SQLException {
-    when(sqlHelper.getMssqlConstraint(TABLE_NAME)).thenReturn(CONSTRAINT);
-    when(db.getDialect()).thenReturn(MS_SQL);
-
-    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
-    assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id");
-  }
-
-  @Test
-  public void generate_for_oracle() throws SQLException {
-    when(sqlHelper.getOracleConstraint(TABLE_NAME)).thenReturn(CONSTRAINT);
-    when(db.getDialect()).thenReturn(ORACLE);
-
-    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
-    assertThat(sqls).containsExactly("DROP TRIGGER issues_IDT",
-      "DROP SEQUENCE issues_SEQ",
-      "ALTER TABLE issues DROP CONSTRAINT pk_id DROP INDEX");
-  }
-
-  @Test
-  public void generate_for_h2() throws SQLException {
-    when(sqlHelper.getH2Constraint(TABLE_NAME)).thenReturn(CONSTRAINT);
-    when(db.getDialect()).thenReturn(H2);
-
-    List<String> sqls = underTest.generate(TABLE_NAME, PK_COLUMN, true);
-
-    assertThat(sqls).containsExactly("ALTER TABLE issues DROP CONSTRAINT pk_id",
-      "ALTER TABLE issues ALTER COLUMN id INTEGER NOT NULL");
-  }
-}
index 45b34c2ca5dbc183345f32ebbe340ec91c415321..aef06c6537b7cb1ef1199f6c0915fd2c16a2e768 100644 (file)
@@ -23,13 +23,15 @@ 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 DropDefaultQProfilesPkTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DropDefaultQProfilesPkTest.class, "schema.sql");
 
-  private MigrationStep underTest = new DropDefaultQProfilesPk(db.database());
+  private final MigrationStep underTest = new DropDefaultQProfilesPk(db.database(), new DropPrimaryKeySqlGenerator(db.database(), new DbPrimaryKeyConstraintFinder(db.database())));
 
   @Test
   public void execute() throws SQLException {
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql
new file mode 100644 (file)
index 0000000..bb4ba64
--- /dev/null
@@ -0,0 +1,4 @@
+CREATE TABLE "TEST_PRIMARY_KEY"(
+    "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "TEST_PRIMARY_KEY" ADD CONSTRAINT "PK_TEST_PRIMARY_KEY" PRIMARY KEY("UUID");