From: Julien Lancelot Date: Thu, 30 Mar 2017 08:26:44 +0000 (+0200) Subject: SONAR-9014 Delete 'sonar.defaultGroup' setting from database X-Git-Tag: 6.4-RC1~434 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee51a9a448d08d824e0e4751aab913078e534925;p=sonarqube.git SONAR-9014 Delete 'sonar.defaultGroup' setting from database --- diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql index be656d01a44..188f663d1b9 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -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; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java index 0147618043a..81f6e713420 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java @@ -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 index 00000000000..5058ead3a65 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSetting.java @@ -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(); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java index a0c631d5f09..14d7f07e8d1 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java @@ -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 index 00000000000..c9303d16e2c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest.java @@ -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 index 00000000000..dfc39d8d285 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/DeleteDefaultGroupSettingTest/initial.sql @@ -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");