]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15378 create migration script to remove svn properties
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Tue, 7 Sep 2021 15:03:57 +0000 (17:03 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 15 Sep 2021 20:03:23 +0000 (20:03 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesData.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/DbVersion91Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v91/RemoveSVNPropertiesDataTest/schema.sql [new file with mode: 0644]

index d84329d82f4d73dd384e59eaba7dff0d1d988f06..a72d527d89b7724ddac5bd6e1434aac9406260ad 100644 (file)
@@ -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 (file)
index 0000000..0ee0247
--- /dev/null
@@ -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();
+  }
+}
index ab995043de2dd0a05872fd1063942e65eb23dedc..9b7ae27d9f674f0f6776cc2c533ecb64acfe38b2 100644 (file)
@@ -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 (file)
index 0000000..b4a6b0f
--- /dev/null
@@ -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 (file)
index 0000000..a4f7dac
--- /dev/null
@@ -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
+);