aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-06-12 22:57:00 +0200
committerEric Hartmann <hartmann.eric@gmail.com>2017-06-14 15:43:13 +0200
commitbce59a878501872b105e120bc0d8e13494f79aee (patch)
tree44862b1c6e1887eddd561223ed12b8ffefcd7044 /server/sonar-db-migration/src
parentdd5713279b5b6beccdb5cc65681dbde25898f035 (diff)
downloadsonarqube-bce59a878501872b105e120bc0d8e13494f79aee.tar.gz
sonarqube-bce59a878501872b105e120bc0d8e13494f79aee.zip
SONAR-9305 Built-in quality profiles should be updated automatically
Diffstat (limited to 'server/sonar-db-migration/src')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteOrphansFromRulesProfiles.java86
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java2
3 files changed, 16 insertions, 75 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
index 0f13d2d420a..b8647194efd 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
@@ -52,7 +52,6 @@ public class DbVersion65 implements DbVersion {
.add(1723, "Populate table qprofiles", PopulateOrgQProfiles.class)
.add(1724, "Drop columns organization_uuid and parent_kee from rules_profiles", DropOrgColumnsFromRulesProfiles.class)
.add(1725, "Mark rules_profiles.is_built_in to true for default organization", SetRulesProfilesIsBuiltInToTrueForDefaultOrganization.class)
- .add(1726, "Update OrgQProfiles to point to built-in profiles", UpdateOrgQProfilesToPointToBuiltInProfiles.class)
- .add(1727, "Delete orphans rules_profiles table and associated tables", DeleteOrphansFromRulesProfiles.class);
+ .add(1726, "Update OrgQProfiles to point to built-in profiles", UpdateOrgQProfilesToPointToBuiltInProfiles.class);
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteOrphansFromRulesProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteOrphansFromRulesProfiles.java
index 133e6de6e51..a63fd8fd0ba 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteOrphansFromRulesProfiles.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteOrphansFromRulesProfiles.java
@@ -21,90 +21,32 @@
package org.sonar.server.platform.db.migration.version.v65;
import java.sql.SQLException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.MassUpdate;
public class DeleteOrphansFromRulesProfiles extends DataChange {
+ private static final Logger LOG = Loggers.get(DeleteOrphansFromRulesProfiles.class);
+
public DeleteOrphansFromRulesProfiles(Database db) {
super(db);
}
@Override
protected void execute(Context context) throws SQLException {
- deleteOrphansFromRulesProfiles(context);
- deleteOrphansFromActiveRules(context);
- deleteOrphansFromActiveRuleParameters(context);
- deleteOrphansFromQProfileChanges(context);
- }
-
- private static void deleteOrphansFromRulesProfiles(Context context) throws SQLException {
- MassUpdate massUpdate = context.prepareMassUpdate()
- .rowPluralName("rules profiles");
-
- massUpdate.select("select rp.kee " +
- " from rules_profiles rp" +
- " where not exists " +
- " ( select 1 from org_qprofiles oqp where oqp.rules_profile_uuid = rp.kee )");
-
- massUpdate.update("delete from rules_profiles where kee = ?")
- .execute((row, update) -> {
- String kee = row.getString(1);
- update.setString(1, kee);
- return true;
- });
- }
-
- private static void deleteOrphansFromActiveRules(Context context) throws SQLException {
- MassUpdate massUpdate = context.prepareMassUpdate()
- .rowPluralName("active rules");
-
- massUpdate.select("select ar.id " +
- " from active_rules ar " +
- " where not exists " +
- " ( select 1 from rules_profiles rp where ar.profile_id = rp.id )");
-
- massUpdate.update("delete from active_rules where id = ?")
- .execute((row, update) -> {
- int id = row.getInt(1);
- update.setInt(1, id);
- return true;
- });
- }
-
- private static void deleteOrphansFromActiveRuleParameters(Context context) throws SQLException {
- MassUpdate massUpdate = context.prepareMassUpdate()
- .rowPluralName("active rule parameters");
-
- massUpdate.select("select arp.id " +
- " from active_rule_parameters arp " +
- " where not exists " +
- " ( select 1 from active_rules ar where ar.id = arp.active_rule_id )");
-
- massUpdate.update("delete from active_rule_parameters where id = ?")
- .execute((row, update) -> {
- int id = row.getInt(1);
- update.setInt(1, id);
- return true;
- });
+ execute(context, "rules_profiles", "delete from rules_profiles where not exists( select 1 from org_qprofiles oqp where oqp.rules_profile_uuid = kee)");
+ execute(context, "active_rules", "delete from active_rules where not exists ( select 1 from rules_profiles rp where rp.id = profile_id)");
+ execute(context, "active_rule_parameters", "delete from active_rule_parameters where not exists ( select 1 from active_rules ar where ar.id = active_rule_id)");
+ execute(context, "qprofile_changes", "delete from qprofile_changes where not exists ( select 1 from rules_profiles rp where rp.kee = qprofile_key)");
}
- private static void deleteOrphansFromQProfileChanges(Context context) throws SQLException {
- MassUpdate massUpdate = context.prepareMassUpdate()
- .rowPluralName("qprofile changes");
-
- massUpdate.select("select qpc.kee " +
- " from qprofile_changes qpc" +
- " where not exists " +
- " ( select 1 from rules_profiles rp where qpc.qprofile_key = rp.kee )");
-
- massUpdate.update("delete from qprofile_changes where kee = ?")
- .execute((row, update) -> {
- String kee = row.getString(1);
- update.setString(1, kee);
- return true;
- });
+ private void execute(Context context, String tableName, String sql) throws SQLException {
+ LOG.info("Deleting orphans from " + tableName);
+ context
+ .prepareUpsert(sql)
+ .execute()
+ .commit();
}
-
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
index ff124e18248..551158fabc0 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
@@ -35,6 +35,6 @@ public class DbVersion65Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 28);
+ verifyMigrationCount(underTest, 27);
}
}