--- /dev/null
+#
+# 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
public class DatabaseVersion {
- public static final int LAST_VERSION = 1125;
+ public static final int LAST_VERSION = 1200;
/**
* The minimum supported version which can be upgraded. Lower
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
FeedRulesTypes.class,
DeleteMeasuresWithRuleId.class,
DeleteManualIssues.class,
- DeleteManualRules.class
+ DeleteManualRules.class,
+
+ // 5.6
+ RemoveDefaultAssigneePropertiesOnDisabledUsers.class
);
}
}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+
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;
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(64);
+ assertThat(container.size()).isEqualTo(65);
}
}
--- /dev/null
+/*
+ * 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<Map<String, Object>> rows = db.select("select prop_key, text_value from properties");
+ assertThat(rows).containsOnly(
+ ImmutableMap.<String, Object>of("PROP_KEY", "sonar.issues.defaultAssigneeLogin","TEXT_VALUE", "user2"),
+ ImmutableMap.<String, Object>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
+ ));
+ }
+
+}
--- /dev/null
+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
+);