]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9014 Delete 'sonar.defaultGroup' setting from database
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 30 Mar 2017 08:26:44 +0000 (10:26 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 13 Apr 2017 09:51:55 +0000 (11:51 +0200)
server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSetting.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest/initial.sql [new file with mode: 0644]

index be656d01a441c929ed60bb5d951d5cab8c02137e..188f663d1b9b7ccf437e95d0009998c846d643aa 100644 (file)
@@ -553,6 +553,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1616');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1617');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1618');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1619');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1620');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', false, '1418215735482', '1418215735482');
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 0147618043a10ab694614c061a06aa65318a9490..81f6e7134207f4cd71cbdae5ae92815e366b50fe 100644 (file)
@@ -47,6 +47,7 @@ public class DbVersion64 implements DbVersion {
       .add(1617, "Drop metadata columns from RULES", DropMetadataColumnsFromRules.class)
       // ensure the index is made unique even on existing 6.4-SNAPSHOT instances (such as next or the developer machines)
       .add(1618, "Make index on ORGANIZATIONS.KEE unique", org.sonar.server.platform.db.migration.version.v63.MakeIndexOnOrganizationsKeeUnique.class)
-      .add(1619, "Restore 'sonar-users' group", RestoreSonarUsersGroups.class);
+      .add(1619, "Restore 'sonar-users' group", RestoreSonarUsersGroups.class)
+      .add(1620, "Delete 'sonar.defaultGroup' setting", DeleteDefaultGroupSetting.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSetting.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSetting.java
new file mode 100644 (file)
index 0000000..5058ead
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class DeleteDefaultGroupSetting extends DataChange {
+
+  public DeleteDefaultGroupSetting(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    context.prepareUpsert("DELETE FROM properties WHERE prop_key=?")
+      .setString(1, "sonar.defaultGroup")
+      .execute().commit();
+  }
+
+}
index a0c631d5f09f5cc40e630a2eb8d5d828ea00339a..14d7f07e8d15020cc309f70199745b25141eae95 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion64Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 20);
+    verifyMigrationCount(underTest, 21);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest.java
new file mode 100644 (file)
index 0000000..c9303d1
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v64;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DeleteDefaultGroupSettingTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DeleteDefaultGroupSettingTest.class, "initial.sql");
+
+  private DeleteDefaultGroupSetting underTest = new DeleteDefaultGroupSetting(db.database());
+
+  @Test
+  public void delete_setting() throws SQLException {
+    insertDefaultGroupProperty();
+
+    underTest.execute();
+
+    assertThat(db.countRowsOfTable("properties")).isZero();
+  }
+
+  @Test
+  public void does_not_fail_when_setting_does_not_exist() throws Exception {
+    underTest.execute();
+
+    assertThat(db.countRowsOfTable("properties")).isZero();
+  }
+
+  @Test
+  public void does_not_delete_other_setting() throws Exception {
+    insertDefaultGroupProperty();
+    insertProperty("sonar.prop", "a value");
+
+    underTest.execute();
+
+    assertThat(db.countRowsOfTable("properties")).isEqualTo(1);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws Exception {
+    insertDefaultGroupProperty();
+
+    underTest.execute();
+    assertThat(db.countRowsOfTable("properties")).isZero();
+
+    underTest.execute();
+    assertThat(db.countRowsOfTable("properties")).isZero();
+  }
+
+  private void insertDefaultGroupProperty() {
+    insertProperty("sonar.defaultGroup", "123");
+  }
+
+  private void insertProperty(String key, String value) {
+    db.executeInsert(
+      "PROPERTIES",
+      "PROP_KEY", key,
+      "TEXT_VALUE", value,
+      "IS_EMPTY", "false",
+      "CREATED_AT", "1000");
+  }
+
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest/initial.sql
new file mode 100644 (file)
index 0000000..dfc39d8
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "PROPERTIES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PROP_KEY" VARCHAR(512) NOT NULL,
+  "RESOURCE_ID" INTEGER,
+  "USER_ID" INTEGER,
+  "IS_EMPTY" BOOLEAN NOT NULL,
+  "TEXT_VALUE" VARCHAR(4000),
+  "CLOB_VALUE" CLOB(2147483647),
+  "CREATED_AT" BIGINT
+);
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY");