aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/main/java/org/sonar
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-12-13 09:58:18 +0100
committerGitHub <noreply@github.com>2016-12-13 09:58:18 +0100
commitfb9f4f8314cc44d45aef2f41a82520d969080444 (patch)
tree9c6986ac840e82a7ace298feca6aff36009d79e9 /sonar-db/src/main/java/org/sonar
parent457ef6b42ba71ddc8ce44c24b49249edab5779e5 (diff)
downloadsonarqube-fb9f4f8314cc44d45aef2f41a82520d969080444.tar.gz
sonarqube-fb9f4f8314cc44d45aef2f41a82520d969080444.zip
SONAR-8534 delete ACTIVITY rows which don't have profileKey field
Signed-off-by: Simon Brandhof <simon.brandhof@sonarsource.com>
Diffstat (limited to 'sonar-db/src/main/java/org/sonar')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/v60/PopulateProfileKeyOfActivities.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateProfileKeyOfActivities.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateProfileKeyOfActivities.java
index fa9f0877115..345703f2657 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateProfileKeyOfActivities.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateProfileKeyOfActivities.java
@@ -29,8 +29,7 @@ import org.sonar.db.version.MassUpdate;
import org.sonar.db.version.Select;
import org.sonar.db.version.SqlStatement;
-import static com.google.common.base.Preconditions.checkState;
-import static org.apache.commons.lang.StringUtils.isNotBlank;
+import static org.apache.commons.lang.StringUtils.isBlank;
public class PopulateProfileKeyOfActivities extends BaseDataChange {
@@ -45,6 +44,11 @@ public class PopulateProfileKeyOfActivities extends BaseDataChange {
massUpdate.update("update activities set profile_key=?, data_field=? where id=?");
massUpdate.rowPluralName("activities");
massUpdate.execute(PopulateProfileKeyOfActivities::handle);
+
+ // SONAR-8534 delete orphans
+ context.prepareUpsert("delete from activities where profile_key is null")
+ .execute()
+ .commit();
}
private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
@@ -52,12 +56,12 @@ public class PopulateProfileKeyOfActivities extends BaseDataChange {
String data = row.getString(2);
Map<String, String> fields = KeyValueFormat.parse(data);
String profileKey = fields.remove("profileKey");
- checkState(isNotBlank(profileKey), "No profile key found in db row of activities.data_field", id);
-
+ if (isBlank(profileKey)) {
+ return false;
+ }
update.setString(1, profileKey);
update.setString(2, KeyValueFormat.format(fields));
update.setInt(3, id);
-
return true;
}
}