diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2019-11-28 16:08:19 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2020-01-13 20:46:24 +0100 |
commit | b9e5b79c297f4978be1f4dd60922e2496ec6b01a (patch) | |
tree | 22242f6893f28171cd4b6d9d03497fff6ea1863c /server/sonar-db-migration | |
parent | e292839ab8e07dda4fd8c41c35ad447f6fe80889 (diff) | |
download | sonarqube-b9e5b79c297f4978be1f4dd60922e2496ec6b01a.tar.gz sonarqube-b9e5b79c297f4978be1f4dd60922e2496ec6b01a.zip |
SONAR-12722 drop `in_review` status
Diffstat (limited to 'server/sonar-db-migration')
5 files changed, 233 insertions, 2 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java index 997f9362c41..f9a518f8978 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java @@ -42,6 +42,7 @@ public class DbVersion81 implements DbVersion { RenameDaysBeforeDeletingInactiveSLBSetting.class) .add(3112, "Migrate short and long living branches types to common BRANCH type", MigrateSlbsAndLlbsToCommonType.class) .add(3113, "Migrate short and long living branches types to common BRANCH type in ce tasks table", - MigrateSlbsAndLlbsToCommonTypeInCeTasks.class); + MigrateSlbsAndLlbsToCommonTypeInCeTasks.class) + .add(3114, "Drop 'In Review' Security Hotspots status ", DropSecurityHotSpotsInReviewStatus.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java new file mode 100644 index 00000000000..7b1248d2c19 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java @@ -0,0 +1,58 @@ +/* + * 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.v81; + +import java.sql.SQLException; +import org.sonar.api.utils.System2; +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 DropSecurityHotSpotsInReviewStatus extends DataChange { + + private System2 system; + + public DropSecurityHotSpotsInReviewStatus(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id,kee from issues where status = 'IN_REVIEW'"); + massUpdate.update("update issues set status = 'TO_REVIEW' where id = ? and status = 'IN_REVIEW'"); + massUpdate.update("insert into issue_changes(issue_key, change_type, change_data, created_at, updated_at, issue_change_creation_date) " + + "VALUES(?, 'diff', 'status=IN_REVIEW|TO_REVIEW', ?, ?, ?)"); + massUpdate.execute((row, update, updateIndex) -> { + + if (updateIndex == 0) { + update.setLong(1, row.getLong(1)); + } else if (updateIndex == 1) { + long currentTime = system.now(); + update.setString(1, row.getString(2)) + .setLong(2, currentTime) + .setLong(3, currentTime) + .setLong(4, currentTime); + } + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java index 46c2f39dfd8..05e5efc4be1 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java @@ -36,7 +36,7 @@ public class DbVersion81Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 14); + verifyMigrationCount(underTest, 15); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java new file mode 100644 index 00000000000..33272ea586a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java @@ -0,0 +1,118 @@ +/* + * 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.v81; + +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.api.issue.Issue.STATUSES; + +public class DropSecurityHotSpotsInReviewStatusTest { + + private final static String ISSUES_TABLE_NAME = "issues"; + private final static int NUMBER_OF_ISSUES_IN_REVIEW = 3; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropSecurityHotSpotsInReviewStatusTest.class, "schema.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private System2 system2 = System2.INSTANCE; + + private DataChange underTest = new DropSecurityHotSpotsInReviewStatus(db.database(), system2); + + @Test + public void should_change_IN_REVIEW_statuses_only() throws SQLException { + + Map<Integer, String> statuses = IntStream.range(0, STATUSES.size()) + .boxed() + .collect(Collectors.toMap(Function.identity(), STATUSES::get)); + + statuses.forEach(this::insertIssue); + + int startIndex = STATUSES.size(); + int endIndex = startIndex + NUMBER_OF_ISSUES_IN_REVIEW; + IntStream.range(startIndex, endIndex).forEach(value -> insertIssue(value, "IN_REVIEW")); + + underTest.execute(); + + IntStream.range(startIndex, endIndex).forEach(this::assertIssueChanged); + + statuses.forEach(this::assertIssueNotChanged); + + // should not fail if executed twice + underTest.execute(); + } + + @Test + public void should_not_fail_if_no_issues() throws SQLException { + underTest.execute(); + assertThat(db.countRowsOfTable("issues")).isEqualTo(0); + } + + private void assertIssueChanged(int issueId) { + List<Map<String, Object>> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); + assertThat(row).hasSize(1); + assertThat(row.get(0).get("STATUS")) + .isEqualTo("TO_REVIEW"); + + List<Map<String, Object>> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + + " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); + assertThat(changelogRows).hasSize(1); + + Map<String, Object> changelogRow = changelogRows.get(0); + assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff"); + assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("status=IN_REVIEW|TO_REVIEW"); + + assertThat(changelogRow.get("CREATED_AT")).isNotNull(); + assertThat(changelogRow.get("UPDATED_AT")).isNotNull(); + assertThat(changelogRow.get("ISSUE_CHANGE_CREATION_DATE")).isNotNull(); + } + + private void assertIssueNotChanged(int issueId, String expectedStatus) { + List<Map<String, Object>> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); + assertThat(row).hasSize(1); + assertThat(row.get(0).get("STATUS")) + .isEqualTo(expectedStatus); + + List<Map<String, Object>> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + + " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); + assertThat(changelogRows).isEmpty(); + } + + private void insertIssue(int issueId, String status) { + db.executeInsert(ISSUES_TABLE_NAME, + "kee", "issue-key-" + issueId, + "status", status, + "manual_severity", false); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql new file mode 100644 index 00000000000..d8f2d4316ab --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql @@ -0,0 +1,54 @@ +CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50) NOT NULL, + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "GAP" DOUBLE, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50), + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" VARCHAR(4000), + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "LOCATIONS" BLOB, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); +CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); + +CREATE TABLE "ISSUE_CHANGES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50), + "ISSUE_KEY" VARCHAR(50) NOT NULL, + "USER_LOGIN" VARCHAR(255), + "CHANGE_TYPE" VARCHAR(20), + "CHANGE_DATA" CLOB(2147483647), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CHANGE_CREATION_DATE" BIGINT +); +ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY"); +CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE"); |