aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2021-09-07 17:03:57 +0200
committersonartech <sonartech@sonarsource.com>2021-09-15 20:03:23 +0000
commit4692d37a7a93179eb8b9f864de4faebb056a84c5 (patch)
treeb40db8aca97caec7c7e3a9ac0ef916660e2380f9 /server
parent236d058a02b709baf4cfeeab56ee226f622b9106 (diff)
downloadsonarqube-4692d37a7a93179eb8b9f864de4faebb056a84c5.tar.gz
sonarqube-4692d37a7a93179eb8b9f864de4faebb056a84c5.zip
SONAR-15378 create migration script to remove svn properties
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesData.java45
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest.java71
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest/schema.sql10
5 files changed, 129 insertions, 2 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
index d84329d82f4..a72d527d89b 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
@@ -44,6 +44,7 @@ public class DbVersion91 implements DbVersion {
.add(6016, "Create unique index for 'portfolio_projects'", CreateIndexForPortfolioProjects.class)
.add(6017, "Migrate portfolios to new tables", MigratePortfoliosToNewTables.class)
.add(6018, "Create index for 'issue_changes' on 'issue_key' and 'change_type'", CreateIndexForIssueChangesOnIssueKeyAndChangeType.class)
- ;
+ .add(6019, "Remove SVN related properties", RemoveSVNPropertiesData.class);
+
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesData.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesData.java
new file mode 100644
index 00000000000..0ee0247f7dc
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesData.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+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.Upsert;
+
+public class RemoveSVNPropertiesData extends DataChange {
+
+ private static final String[] propKeysInINClause = {"'sonar.svn.username'", "'sonar.svn.privateKeyPath'",
+ "'sonar.svn.password.secured'", "'sonar.svn.passphrase.secured'"};
+
+ public RemoveSVNPropertiesData(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ String updateQuery = String.format("DELETE FROM properties WHERE prop_key in (%s)",
+ String.join(",", propKeysInINClause));
+
+ Upsert upsert = context.prepareUpsert(updateQuery);
+ upsert.execute();
+ upsert.commit();
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
index ab995043de2..9b7ae27d9f6 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
@@ -41,7 +41,7 @@ public class DbVersion91Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 18);
+ verifyMigrationCount(underTest, 19);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest.java
new file mode 100644
index 00000000000..b4a6b0f7ed4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest.java
@@ -0,0 +1,71 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v91;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
+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.assertj.core.api.Assertions.assertThatCode;
+
+public class RemoveSVNPropertiesDataTest {
+
+ private static final String TABLE_NAME = "properties";
+
+ private final UuidFactory uuidFactory = new SequenceUuidFactory();
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(RemoveSVNPropertiesDataTest.class, "schema.sql");
+
+ private final DataChange underTest = new RemoveSVNPropertiesData(db.database());
+
+ @Test
+ public void do_not_fail_if_no_rows_to_delete() {
+ assertThatCode(underTest::execute)
+ .doesNotThrowAnyException();
+ }
+
+ @Test
+ public void deletes_svn_properties_when_they_exist_in_database() throws SQLException {
+ insertProperty("sonar.svn.username", "Test");
+ insertProperty("sonar.svn.privateKeyPath", "Test");
+ insertProperty("sonar.svn.password.secured", "Test");
+ insertProperty("sonar.svn.passphrase.secured", "Test");
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from properties where prop_key like 'sonar.svn%'")).isZero();
+ }
+
+ private void insertProperty(String key, String value) {
+ db.executeInsert(TABLE_NAME,
+ "PROP_KEY", key,
+ "TEXT_VALUE", value,
+ "IS_EMPTY", String.valueOf(false),
+ "CREATED_AT", 2,
+ "UUID", uuidFactory.create());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest/schema.sql
new file mode 100644
index 00000000000..a4f7dac82b6
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest/schema.sql
@@ -0,0 +1,10 @@
+CREATE TABLE "PROPERTIES"(
+ "PROP_KEY" VARCHAR(512) NOT NULL,
+ "IS_EMPTY" BOOLEAN NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000) NULL,
+ "CLOB_VALUE" VARCHAR(4000) NULL,
+ "CREATED_AT" INTEGER NOT NULL,
+ "COMPONENT_UUID" VARCHAR(40) NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "USER_UUID" VARCHAR(255) NULL
+);