diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-11-09 19:26:39 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-11-10 09:57:51 +0100 |
commit | 787f0f12659ba158028a7a4b5643210852fd4673 (patch) | |
tree | 3d4f7c91bf67146980a0de5ca8f02762e68dcf4a /sonar-db/src | |
parent | 0962f303a557888bf6f1fcb92e7515eb2cfa02d7 (diff) | |
download | sonarqube-787f0f12659ba158028a7a4b5643210852fd4673.tar.gz sonarqube-787f0f12659ba158028a7a4b5643210852fd4673.zip |
SONAR-8377 Drop issue filters tables
Diffstat (limited to 'sonar-db/src')
8 files changed, 145 insertions, 27 deletions
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 c68e40547fb..69753022cf2 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 @@ -30,7 +30,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 1_421; + public static final int LAST_VERSION = 1_422; /** * The minimum supported version which can be upgraded. Lower @@ -50,6 +50,8 @@ public class DatabaseVersion { "active_dashboards", "activities", "dashboards", + "issue_filters", + "issue_filter_favourites", "measure_filters", "measure_filter_favourites", "widgets", @@ -77,8 +79,6 @@ public class DatabaseVersion { "internal_properties", "issues", "issue_changes", - "issue_filters", - "issue_filter_favourites", "loaded_templates", "manual_measures", "metrics", 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 a18e3c1dbfe..4742c008b43 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 @@ -167,6 +167,7 @@ import org.sonar.db.version.v62.AddOrganizationUuidToUserRoles; import org.sonar.db.version.v62.CreateDefaultOrganization; import org.sonar.db.version.v62.CreateTableOrganizations; import org.sonar.db.version.v62.DeletePermissionShareDashboard; +import org.sonar.db.version.v62.DropIssueFiltersTables; import org.sonar.db.version.v62.DropMeasureFiltersTables; import org.sonar.db.version.v62.DropRelatedDashboardTables; import org.sonar.db.version.v62.MakeOrganizationUuidNotNullOnGroupRoles; @@ -380,6 +381,7 @@ public class MigrationStepModule extends Module { MakeOrganizationUuidNotNullOnGroupRoles.class, UpdateQualityGateConditionsOnCoverage.class, DropRelatedDashboardTables.class, - DropMeasureFiltersTables.class); + DropMeasureFiltersTables.class, + DropIssueFiltersTables.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v62/DropIssueFiltersTables.java b/sonar-db/src/main/java/org/sonar/db/version/v62/DropIssueFiltersTables.java new file mode 100644 index 00000000000..5f03c82570e --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v62/DropIssueFiltersTables.java @@ -0,0 +1,65 @@ +/* + * 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.v62; + +import com.google.common.collect.ImmutableList; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropTableBuilder; + +import static org.sonar.core.util.stream.Collectors.toList; + +public class DropIssueFiltersTables extends DdlChange { + + private static final Logger LOGGER = Loggers.get(DropIssueFiltersTables.class); + + private static final List<String> TABLES_TO_DROP = ImmutableList.of("issue_filters", "issue_filter_favourites"); + + private final Database db; + + public DropIssueFiltersTables(Database db) { + super(db); + this.db = db; + } + + @Override + public void execute(Context context) throws SQLException { + List<String> tablesToDrop = getEffectiveTablesToDrop(); + LOGGER.info("Removing tables {}", tablesToDrop); + context.execute(tablesToDrop + .stream() + .flatMap(table -> new DropTableBuilder(db.getDialect(), table).build().stream()) + .collect(toList())); + } + + private List<String> getEffectiveTablesToDrop() throws SQLException { + try (Connection connection = db.getDataSource().getConnection()) { + return TABLES_TO_DROP.stream() + .filter(table -> DatabaseUtils.tableExists(table, connection)) + .collect(toList()); + } + } +} 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 ebc66acf092..4521f8644fa 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 @@ -510,6 +510,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1418'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1419'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1420'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1421'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1422'); 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', true, '1418215735482', '1418215735482'); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index 67583b26b67..b21263e127f 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -480,28 +480,6 @@ CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES" ("KEE"); CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES" ("ISSUE_KEY"); -CREATE TABLE "ISSUE_FILTERS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "NAME" VARCHAR(100) NOT NULL, - "SHARED" BOOLEAN NOT NULL DEFAULT FALSE, - "USER_LOGIN" VARCHAR(255), - "DESCRIPTION" VARCHAR(4000), - "DATA" CLOB(2147483647), - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP -); -CREATE INDEX "ISSUE_FILTERS_NAME" ON "ISSUE_FILTERS" ("NAME"); - - -CREATE TABLE "ISSUE_FILTER_FAVOURITES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "USER_LOGIN" VARCHAR(255) NOT NULL, - "ISSUE_FILTER_ID" INTEGER NOT NULL, - "CREATED_AT" TIMESTAMP -); -CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER_LOGIN"); - - CREATE TABLE "PERMISSION_TEMPLATES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "ORGANIZATION_UUID" VARCHAR(40) NOT NULL, 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 f9576af847e..6ad5962474d 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(162); + assertThat(container.size()).isEqualTo(163); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v62/DropIssueFiltersTableTest.java b/sonar-db/src/test/java/org/sonar/db/version/v62/DropIssueFiltersTableTest.java new file mode 100644 index 00000000000..068d2058edb --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v62/DropIssueFiltersTableTest.java @@ -0,0 +1,52 @@ +/* + * 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.v62; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +public class DropIssueFiltersTableTest { + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, DropIssueFiltersTableTest.class, "schema.sql"); + + private DropIssueFiltersTables underTest = new DropIssueFiltersTables(db.database()); + + @Test + public void delete_tables() throws SQLException { + underTest.execute(); + + db.assertTableDoesNotExist("issue_filters"); + db.assertTableDoesNotExist("issue_filter_favourites"); + } + + @Test + public void migration_is_re_entrant() throws Exception { + underTest.execute(); + underTest.execute(); + + db.assertTableDoesNotExist("issue_filters"); + db.assertTableDoesNotExist("issue_filter_favourites"); + } +} diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v62/DropIssueFiltersTableTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v62/DropIssueFiltersTableTest/schema.sql new file mode 100644 index 00000000000..e842593fef6 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v62/DropIssueFiltersTableTest/schema.sql @@ -0,0 +1,20 @@ +CREATE TABLE "ISSUE_FILTERS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "NAME" VARCHAR(100) NOT NULL, + "SHARED" BOOLEAN NOT NULL DEFAULT FALSE, + "USER_LOGIN" VARCHAR(255), + "DESCRIPTION" VARCHAR(4000), + "DATA" CLOB(2147483647), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +CREATE INDEX "ISSUE_FILTERS_NAME" ON "ISSUE_FILTERS" ("NAME"); + + +CREATE TABLE "ISSUE_FILTER_FAVOURITES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "USER_LOGIN" VARCHAR(255) NOT NULL, + "ISSUE_FILTER_ID" INTEGER NOT NULL, + "CREATED_AT" TIMESTAMP +); +CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER_LOGIN"); |