diff options
Diffstat (limited to 'server/sonar-db-migration/src')
3 files changed, 130 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/UpdateScaIssuesReleasesOpenStatusIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/UpdateScaIssuesReleasesOpenStatusIT.java new file mode 100644 index 00000000000..43069c4911a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/UpdateScaIssuesReleasesOpenStatusIT.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202503; + +import java.sql.SQLException; +import java.util.Date; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.db.MigrationDbTester.createForMigrationStep; + +class UpdateScaIssuesReleasesOpenStatusIT { + @RegisterExtension + public final MigrationDbTester db = createForMigrationStep(UpdateScaIssuesReleasesOpenStatus.class); + private final DataChange underTest = new UpdateScaIssuesReleasesOpenStatus(db.database()); + + @Test + void execute_doesNotCreateRecords() throws SQLException { + underTest.execute(); + assertThat(db.countSql("select count(*) from sca_issues_releases")).isZero(); + } + + @Test + void execute_doesNotOverwriteOtherStatus() throws SQLException { + insertScaIssuesReleases("FIXED"); + + underTest.execute(); + + assertAllStatusesEqual("FIXED"); + } + + @Test + void execute_whenAlreadyExecuted_shouldBeIdempotent() throws SQLException { + insertScaIssuesReleases("TO_REVIEW"); + underTest.execute(); + assertAllStatusesEqual("OPEN"); + underTest.execute(); + assertAllStatusesEqual("OPEN"); + } + + private void insertScaIssuesReleases(String status) { + db.executeInsert("sca_issues_releases", + "uuid", "uuid", + "sca_issue_uuid", "issue_id", + "sca_release_uuid", "release_id", + "severity", "severity", + "severity_sort_key", 1, + "status", status, + "created_at", new Date().getTime(), + "updated_at", new Date().getTime() + ); + } + + private void assertAllStatusesEqual(String status) { + List<Map<String, Object>> rows = db.select("select status from sca_issues_releases"); + assertThat(rows).isNotEmpty() + .allSatisfy(row -> assertThat(row).containsEntry("status", status)); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java index 656ca4db2e5..4fdd647853d 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java @@ -50,6 +50,7 @@ public class DbVersion202503 implements DbVersion { .add(2025_03_011, "Drop new_in_pull_request column from SCA dependencies", DropNewInPullRequestFromScaDependenciesTable.class) .add(2025_03_012, "Add assignee to SCA issues releases", AddAssigneeToScaIssuesReleases.class) .add(2025_03_013, "Create ScaIssuesReleasesHistory table", CreateScaIssuesReleasesChangesTable.class) - .add(2025_03_014, "Create index for sca_issues_releases UUID on changes table", CreateIndexOnScaIssuesReleaseChangesReleaseId.class); + .add(2025_03_014, "Create index for sca_issues_releases UUID on changes table", CreateIndexOnScaIssuesReleaseChangesReleaseId.class) + .add(2025_03_015, "Update default SCA dependency issue status to OPEN from TO_REVIEW", UpdateScaIssuesReleasesOpenStatus.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/UpdateScaIssuesReleasesOpenStatus.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/UpdateScaIssuesReleasesOpenStatus.java new file mode 100644 index 00000000000..2b755559f44 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/UpdateScaIssuesReleasesOpenStatus.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202503; + +import java.sql.SQLException; +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 UpdateScaIssuesReleasesOpenStatus extends DataChange { + static final String SELECT_QUERY = "select uuid from sca_issues_releases where status = 'TO_REVIEW'"; + static final String UPDATE_QUERY = "update sca_issues_releases set status = 'OPEN' where uuid = ?"; + + public UpdateScaIssuesReleasesOpenStatus(Database db) { + super(db); + } + + @Override + protected void execute(DataChange.Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select(SELECT_QUERY); + massUpdate.update(UPDATE_QUERY); + + massUpdate.execute((row, update, index) -> { + update + .setString(1, row.getString(1)); + return true; + }); + } +} |