From: Julien Lancelot Date: Wed, 4 May 2016 07:11:07 +0000 (+0200) Subject: SONAR-7212 Remove migration to remove default assignee properties on removed users X-Git-Tag: 5.6-RC1~220 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c9fea779de11697317df46ff9ad8e9eb6011651e;p=sonarqube.git SONAR-7212 Remove migration to remove default assignee properties on removed users Remove this migration because in Oracle, PROPERTIES.TEXT_VALUE is a clob, so it's not possible to do a JOIN on this column --- diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_remove_default_assignee_properties_on_disabled_users.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_remove_default_assignee_properties_on_disabled_users.rb deleted file mode 100644 index 17356447b5c..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1200_remove_default_assignee_properties_on_disabled_users.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2014 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube 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. -# -# SonarQube 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. -# - -# -# SonarQube 5.6 -# SONAR-7212 -# -class RemoveDefaultAssigneePropertiesOnDisabledUsers < ActiveRecord::Migration - - def self.up - execute_java_migration('org.sonar.db.version.v56.RemoveDefaultAssigneePropertiesOnDisabledUsers') - end - -end diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index 64d79499016..8f51cc19382 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -29,7 +29,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 1200; + public static final int LAST_VERSION = 1125; /** * The minimum supported version which can be upgraded. Lower diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index cd2a0d76dd5..831333de097 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -82,7 +82,6 @@ import org.sonar.db.version.v55.FeedActiveRulesLongDateColumns; import org.sonar.db.version.v55.FeedIssueTypes; import org.sonar.db.version.v55.FeedRulesLongDateColumns; import org.sonar.db.version.v55.FeedRulesTypes; -import org.sonar.db.version.v56.RemoveDefaultAssigneePropertiesOnDisabledUsers; public class MigrationStepModule extends Module { @Override @@ -162,10 +161,6 @@ public class MigrationStepModule extends Module { FeedRulesTypes.class, DeleteMeasuresWithRuleId.class, DeleteManualIssues.class, - DeleteManualRules.class, - - // 5.6 - RemoveDefaultAssigneePropertiesOnDisabledUsers.class - ); + DeleteManualRules.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsers.java b/sonar-db/src/main/java/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsers.java deleted file mode 100644 index b3942a65e05..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsers.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.db.version.v56; - -import java.sql.SQLException; -import org.sonar.db.Database; -import org.sonar.db.version.BaseDataChange; -import org.sonar.db.version.MassUpdate; -import org.sonar.db.version.Select; -import org.sonar.db.version.SqlStatement; - -/** - * Remove properties "sonar.issues.defaultAssigneeLogin" when values are on removed users - */ -public class RemoveDefaultAssigneePropertiesOnDisabledUsers extends BaseDataChange { - - private static final String DEFAULT_ISSUE_ASSIGNEE_PROP = "sonar.issues.defaultAssigneeLogin"; - - public RemoveDefaultAssigneePropertiesOnDisabledUsers(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT p.id FROM properties p " + - "INNER JOIN users u ON u.login=p.text_value AND u.active=? " + - "WHERE p.prop_key=?") - .setBoolean(1, false) - .setString(2, DEFAULT_ISSUE_ASSIGNEE_PROP); - massUpdate.update("DELETE FROM properties WHERE id=?"); - massUpdate.rowPluralName("default assignee properties on removed users"); - massUpdate.execute(new MigrationHandler()); - } - - private static class MigrationHandler implements MassUpdate.Handler { - - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - update.setLong(1, id); - return true; - } - } - -} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v56/package-info.java b/sonar-db/src/main/java/org/sonar/db/version/v56/package-info.java deleted file mode 100644 index c3a55a0eb13..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/v56/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.db.version.v56; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index c6dccde162f..72e8889de26 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -403,7 +403,6 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1122'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1123'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1124'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1125'); -INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1200'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index 91bda96d3de..20c4b0d3537 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(65); + assertThat(container.size()).isEqualTo(64); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsersTest.java b/sonar-db/src/test/java/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsersTest.java deleted file mode 100644 index b200b6cd022..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsersTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.db.version.v56; - -import com.google.common.collect.ImmutableMap; -import java.util.List; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; -import org.sonar.db.version.MigrationStep; - -import static org.assertj.core.api.Assertions.assertThat; - -public class RemoveDefaultAssigneePropertiesOnDisabledUsersTest { - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveDefaultAssigneePropertiesOnDisabledUsersTest.class, "schema.sql"); - - private MigrationStep migration = new RemoveDefaultAssigneePropertiesOnDisabledUsers(db.database());; - - @Test - public void delete_properties() throws Exception { - insertUser("user1", false); - insertUser("user2", true); - - insertProperty("sonar.issues.defaultAssigneeLogin", "user1", 10L); - insertProperty("sonar.issues.defaultAssigneeLogin", "user1", 11L); - insertProperty("sonar.other.property", "user1", 11L); - insertProperty("sonar.issues.defaultAssigneeLogin", "user2", 13L); - - migration.execute(); - - List> rows = db.select("select prop_key, text_value from properties"); - assertThat(rows).containsOnly( - ImmutableMap.of("PROP_KEY", "sonar.issues.defaultAssigneeLogin","TEXT_VALUE", "user2"), - ImmutableMap.of("PROP_KEY", "sonar.other.property","TEXT_VALUE", "user1") - ); - } - - private void insertUser(String login, boolean active) { - db.executeInsert("users", ImmutableMap.of( - "LOGIN", login, - "ACTIVE", Boolean.toString(active) - )); - } - - private void insertProperty(String key, String value, long componentId) { - db.executeInsert("properties", ImmutableMap.of( - "PROP_KEY", key, - "RESOURCE_ID", Long.toString(componentId), - "TEXT_VALUE", value - )); - } - -} diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsersTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsersTest/schema.sql deleted file mode 100644 index f8c90e90464..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v56/RemoveDefaultAssigneePropertiesOnDisabledUsersTest/schema.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE TABLE "USERS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "LOGIN" VARCHAR(255), - "NAME" VARCHAR(200), - "EMAIL" VARCHAR(100), - "CRYPTED_PASSWORD" VARCHAR(40), - "SALT" VARCHAR(40), - "REMEMBER_TOKEN" VARCHAR(500), - "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP, - "ACTIVE" BOOLEAN DEFAULT TRUE, - "SCM_ACCOUNTS" VARCHAR(4000), - "EXTERNAL_IDENTITY" VARCHAR(255), - "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100), - "USER_LOCAL" BOOLEAN, - "CREATED_AT" BIGINT, - "UPDATED_AT" BIGINT -); - -CREATE TABLE "PROPERTIES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROP_KEY" VARCHAR(512), - "RESOURCE_ID" INTEGER, - "TEXT_VALUE" CLOB(2147483647), - "USER_ID" INTEGER -);