aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderPropertyTest.java90
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java44
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderProperty.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/package-info.java23
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501Test.java40
6 files changed, 242 insertions, 0 deletions
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderPropertyTest.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderPropertyTest.java
new file mode 100644
index 00000000000..52cf62d7cec
--- /dev/null
+++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderPropertyTest.java
@@ -0,0 +1,90 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.v202501;
+
+import java.sql.SQLException;
+import java.util.Map;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.sonar.db.MigrationDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+class MigrateConfidentialHeaderPropertyTest {
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MigrateConfidentialHeaderProperty.class);
+ private final DataChange underTest = new MigrateConfidentialHeaderProperty(db.database());
+
+ private static final String NEW_PROPERTY_NAME = "sonar.pdf.confidential.header.enabled";
+ private static final String OLD_PROPERTY_NAME = "sonar.portfolios.confidential.header";
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void execute_shouldCreateNewPropertyWithCorrectValue(Boolean propertyValue) throws SQLException {
+ createConfidentialPortfolioHeaderProperty(db, propertyValue);
+
+ underTest.execute();
+
+ Assertions.assertThat(db.select("select text_value from properties where prop_key = '" + NEW_PROPERTY_NAME + "'"))
+ .hasSize(1)
+ .containsExactly(Map.of("text_value", propertyValue.toString()));
+
+ Assertions.assertThat(db.select("select text_value from properties where prop_key = '" + OLD_PROPERTY_NAME + "'"))
+ .isEmpty();
+ }
+
+ @Test
+ void execute_whenSourcePropertyDoesntExist_shouldNotCreateNewProperty() throws SQLException {
+
+ underTest.execute();
+
+ Assertions.assertThat(db.select("select text_value from properties where prop_key = '" + OLD_PROPERTY_NAME + "'"))
+ .isEmpty();
+ Assertions.assertThat(db.select("select text_value from properties where prop_key = '" + NEW_PROPERTY_NAME + "'"))
+ .isEmpty();
+ }
+
+ @Test
+ void execute_whenReentrant_shouldNotFail() throws SQLException {
+ createConfidentialPortfolioHeaderProperty(db, true);
+
+ underTest.execute();
+ underTest.execute();
+
+ Assertions.assertThat(db.select("select text_value from properties where prop_key = '" + NEW_PROPERTY_NAME + "'"))
+ .hasSize(1)
+ .containsExactly(Map.of("text_value", "true"));
+
+ Assertions.assertThat(db.select("select text_value from properties where prop_key = '" + OLD_PROPERTY_NAME + "'"))
+ .isEmpty();
+ }
+
+ private void createConfidentialPortfolioHeaderProperty(MigrationDbTester db, Boolean value) {
+ db.executeInsert("properties ",
+ "prop_key", "sonar.portfolios.confidential.header",
+ "is_empty", false,
+ "text_value", value.toString(),
+ "created_at", 100_000L,
+ "uuid", "some-random-uuid1");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
index a4f007f82e0..596689875db 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
@@ -37,6 +37,7 @@ import org.sonar.server.platform.db.migration.version.v105.DbVersion105;
import org.sonar.server.platform.db.migration.version.v106.DbVersion106;
import org.sonar.server.platform.db.migration.version.v107.DbVersion107;
import org.sonar.server.platform.db.migration.version.v108.DbVersion108;
+import org.sonar.server.platform.db.migration.version.v202501.DbVersion202501;
public class MigrationConfigurationModule extends Module {
@Override
@@ -54,6 +55,7 @@ public class MigrationConfigurationModule extends Module {
DbVersion106.class,
DbVersion107.class,
DbVersion108.class,
+ DbVersion202501.class,
// migration steps
MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java
new file mode 100644
index 00000000000..aee0eaed57d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501.java
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.v202501;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
+@SuppressWarnings("java:S3937")
+public class DbVersion202501 implements DbVersion {
+
+ /**
+ * We use the start of the 10.X cycle as an opportunity to align migration numbers with the SQ version number.
+ * Please follow this pattern:
+ * 2025_01_000
+ * 2025_01_001
+ * 2025_01_002
+ */
+
+ @Override
+ public void addSteps(MigrationStepRegistry registry) {
+ registry
+ .add(2025_01_000, "Rename 'sonar.portfolios.confidential.header' property to 'sonar.pdf.confidential.header.enabled'",
+ MigrateConfidentialHeaderProperty.class)
+ ;
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderProperty.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderProperty.java
new file mode 100644
index 00000000000..d0a8e96ae31
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/MigrateConfidentialHeaderProperty.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.v202501;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class MigrateConfidentialHeaderProperty extends DataChange {
+
+ private static final String SOURCE_PROPERTY = "sonar.portfolios.confidential.header";
+ private static final String TARGET_PROPERTY = "sonar.pdf.confidential.header.enabled";
+
+ public MigrateConfidentialHeaderProperty(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ context.prepareUpsert("update properties set prop_key = ? where prop_key = ?")
+ .setString(1, TARGET_PROPERTY)
+ .setString(2, SOURCE_PROPERTY)
+ .execute()
+ .commit();
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/package-info.java
new file mode 100644
index 00000000000..ad6cb01286b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202501/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v202501;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501Test.java
new file mode 100644
index 00000000000..449157a1b34
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v202501/DbVersion202501Test.java
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.v202501;
+
+import org.junit.jupiter.api.Test;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+class DbVersion202501Test {
+
+ private final DbVersion202501 underTest = new DbVersion202501();
+
+ @Test
+ void migrationNumber_starts_at_2025_01_000() {
+ verifyMinimumMigrationNumber(underTest, 2025_01_000);
+ }
+
+ @Test
+ void verify_migration_is_not_empty() {
+ verifyMigrationNotEmpty(underTest);
+ }
+}