aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-10-31 08:38:55 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-10-31 08:38:55 +0100
commitb641ada84fdbdd74a6af22e2af1ec9b5e9169d47 (patch)
tree8dad0a7645581d36f493410ca5c6447904fef03a
parentaf0457f6e364a67f34e79dbc7c2fc711f2710e24 (diff)
downloadsonarqube-b641ada84fdbdd74a6af22e2af1ec9b5e9169d47.tar.gz
sonarqube-b641ada84fdbdd74a6af22e2af1ec9b5e9169d47.zip
SONAR-5810 Fix migration when project key does not exists
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java15
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute-result.xml63
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute.xml69
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/not_migrate_already_migrated_data-result.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/after.xml)6
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/not_migrate_already_migrated_data.xml (renamed from server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/before.xml)6
6 files changed, 162 insertions, 19 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java
index 6d79f726de1..c7e889bac72 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuid.java
@@ -27,6 +27,8 @@ import org.sonar.server.db.migrations.MassUpdate;
import org.sonar.server.db.migrations.Select;
import org.sonar.server.db.migrations.SqlStatement;
+import javax.annotation.Nullable;
+
import java.sql.SQLException;
import java.util.Date;
@@ -51,14 +53,14 @@ public class ReplaceIssueFiltersProjectKeyByUuid extends BaseDataChange {
final Date now = new Date(system.now());
MassUpdate massUpdate = context.prepareMassUpdate();
- massUpdate.select("SELECT f.id, f.data FROM issue_filters f");
+ massUpdate.select("SELECT f.id, f.data FROM issue_filters f WHERE f.data like '%componentRoots=%'");
massUpdate.update("UPDATE issue_filters SET data=?, updated_at=? WHERE id=?");
massUpdate.execute(new MassUpdate.Handler() {
@Override
public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
Long id = row.getLong(1);
String data = row.getString(2);
- if (!data.contains(OLD_COMPONENT_ROOTS_FIELDS)) {
+ if (data == null) {
return false;
}
update.setString(1, convertData(context, data));
@@ -76,11 +78,7 @@ public class ReplaceIssueFiltersProjectKeyByUuid extends BaseDataChange {
String field = fields[i];
if (field.contains(OLD_COMPONENT_ROOTS_FIELDS)) {
String[] componentRootValues = field.split("=");
- if (componentRootValues.length == 2) {
- newFields.append(convertField(context, componentRootValues[1]));
- } else {
- newFields.append(NEW_COMPONENT_ROOTS_FIELDS + "=");
- }
+ append(context, newFields, componentRootValues.length == 2 ? componentRootValues[1] : null);
} else {
newFields.append(field);
}
@@ -91,9 +89,13 @@ public class ReplaceIssueFiltersProjectKeyByUuid extends BaseDataChange {
return newFields.toString();
}
- private String convertField(Context context, String projectKey) throws SQLException {
- String projectUuid = context.prepareSelect("SELECT p.uuid FROM projects p WHERE p.kee=?").setString(1, projectKey).get(Select.STRING_READER);
- return NEW_COMPONENT_ROOTS_FIELDS + "=" + projectUuid;
+ private void append(Context context, StringBuilder newFields, @Nullable String projectKey) throws SQLException {
+ if (projectKey != null) {
+ String projectUuid = context.prepareSelect("SELECT p.uuid FROM projects p WHERE p.kee=?").setString(1, projectKey).get(Select.STRING_READER);
+ if (projectUuid != null) {
+ newFields.append(NEW_COMPONENT_ROOTS_FIELDS + "=" + projectUuid);
+ }
+ }
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java
index 00d1a17cf85..c75ff109b04 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java
@@ -47,11 +47,20 @@ public class ReplaceIssueFiltersProjectKeyByUuidTest {
@Test
public void execute() throws Exception {
- db.prepareDbUnit(getClass(), "before.xml");
+ db.prepareDbUnit(getClass(), "execute.xml");
migration.execute();
- db.assertDbUnit(getClass(), "after.xml", "issue_filters");
+ db.assertDbUnit(getClass(), "execute-result.xml", "issue_filters");
}
-} \ No newline at end of file
+ @Test
+ public void not_migrate_already_migrated_data() throws Exception {
+ db.prepareDbUnit(getClass(), "not_migrate_already_migrated_data.xml");
+
+ migration.execute();
+
+ db.assertDbUnit(getClass(), "not_migrate_already_migrated_data-result.xml", "issue_filters");
+ }
+
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute-result.xml
new file mode 100644
index 00000000000..bd1e8a11577
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute-result.xml
@@ -0,0 +1,63 @@
+<dataset>
+
+ <issue_filters
+ id="1"
+ name="Struts Issues"
+ user_login="stephane"
+ shared="[true]"
+ description="All issues of Struts"
+ data="componentRootUuids=ABCD"
+ created_at="2013-06-10"
+ updated_at="2014-10-29" />
+
+ <issue_filters
+ id="2"
+ name="Open issues"
+ user_login="michael"
+ shared="[false]"
+ description="All open issues"
+ data="statuses=OPEN"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+ <issue_filters
+ id="3"
+ name="Sonar Open issues"
+ user_login="michael"
+ shared="[true]"
+ description="All open issues on Sonar"
+ data="statuses=CLOSED|componentRootUuids=ABCD|resolution=FIXED"
+ created_at="2013-06-10"
+ updated_at="2014-10-29" />
+
+ <issue_filters
+ id="4"
+ name="Bad component roots fields"
+ user_login="michael"
+ shared="[true]"
+ description="Bad component roots fields"
+ data="statuses=CLOSED||resolution=FIXED"
+ created_at="2013-06-10"
+ updated_at="2014-10-29" />
+
+ <issue_filters
+ id="5"
+ name="Linked on not existing file"
+ user_login="michael"
+ shared="[true]"
+ description="Linked on not existing file"
+ data="statuses=CLOSED||resolution=FIXED"
+ created_at="2013-06-10"
+ updated_at="2014-10-29" />
+
+ <issue_filters
+ id="6"
+ name="Empty data"
+ user_login="michael"
+ shared="[true]"
+ description="Empty data"
+ data="[null]"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute.xml
new file mode 100644
index 00000000000..770f048586d
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/execute.xml
@@ -0,0 +1,69 @@
+<dataset>
+
+ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="[null]"
+ description="the description" long_name="Apache Struts"
+ enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]"
+ created_at="2014-06-18" authorization_updated_at="2014-06-18" />
+
+ <issue_filters
+ id="1"
+ name="Struts Issues"
+ user_login="stephane"
+ shared="[true]"
+ description="All issues of Struts"
+ data="componentRoots=org.struts:struts"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+ <issue_filters
+ id="2"
+ name="Open issues"
+ user_login="michael"
+ shared="[false]"
+ description="All open issues"
+ data="statuses=OPEN"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+ <issue_filters
+ id="3"
+ name="Sonar Open issues"
+ user_login="michael"
+ shared="[true]"
+ description="All open issues on Sonar"
+ data="statuses=CLOSED|componentRoots=org.struts:struts|resolution=FIXED"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+ <issue_filters
+ id="4"
+ name="Bad component roots fields"
+ user_login="michael"
+ shared="[true]"
+ description="Bad component roots fields"
+ data="statuses=CLOSED|componentRoots=|resolution=FIXED"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+ <issue_filters
+ id="5"
+ name="Linked on not existing file"
+ user_login="michael"
+ shared="[true]"
+ description="Linked on not existing file"
+ data="statuses=CLOSED|componentRoots=unknown|resolution=FIXED"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+ <issue_filters
+ id="6"
+ name="Empty data"
+ user_login="michael"
+ shared="[true]"
+ description="Empty data"
+ data="[null]"
+ created_at="2013-06-10"
+ updated_at="2013-06-10" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/after.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/not_migrate_already_migrated_data-result.xml
index ec83825f445..c0e063eb9f8 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/after.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/not_migrate_already_migrated_data-result.xml
@@ -8,7 +8,7 @@
description="All issues of Struts"
data="componentRootUuids=ABCD"
created_at="2013-06-10"
- updated_at="2014-10-29" />
+ updated_at="2013-06-10" />
<issue_filters
id="2"
@@ -28,7 +28,7 @@
description="All open issues on Sonar"
data="statuses=CLOSED|componentRootUuids=ABCD|resolution=FIXED"
created_at="2013-06-10"
- updated_at="2014-10-29" />
+ updated_at="2013-06-10" />
<issue_filters
id="4"
@@ -38,6 +38,6 @@
description="All open issues on Sonar"
data="statuses=CLOSED|componentRootUuids=|resolution=FIXED"
created_at="2013-06-10"
- updated_at="2014-10-29" />
+ updated_at="2013-06-10" />
</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/not_migrate_already_migrated_data.xml
index 840bba32908..313bbb19f65 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/before.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest/not_migrate_already_migrated_data.xml
@@ -12,7 +12,7 @@
user_login="stephane"
shared="[true]"
description="All issues of Struts"
- data="componentRoots=org.struts:struts"
+ data="componentRootUuids=ABCD"
created_at="2013-06-10"
updated_at="2013-06-10" />
@@ -32,7 +32,7 @@
user_login="michael"
shared="[true]"
description="All open issues on Sonar"
- data="statuses=CLOSED|componentRoots=org.struts:struts|resolution=FIXED"
+ data="statuses=CLOSED|componentRootUuids=ABCD|resolution=FIXED"
created_at="2013-06-10"
updated_at="2013-06-10" />
@@ -42,7 +42,7 @@
user_login="michael"
shared="[true]"
description="All open issues on Sonar"
- data="statuses=CLOSED|componentRoots=|resolution=FIXED"
+ data="statuses=CLOSED|componentRootUuids=|resolution=FIXED"
created_at="2013-06-10"
updated_at="2013-06-10" />