]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8675 drop table resource_index
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 24 Jan 2017 13:57:34 +0000 (14:57 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 25 Jan 2017 10:41:57 +0000 (11:41 +0100)
it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndex.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest/schema.sql [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
sonar-db/src/main/java/org/sonar/db/version/SqTables.java
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl

index 1095e5436671bcefe136c5435f39d0640d5ebb0c..fda7b3074d4052835b6927d95b9d92ccb668457c 100644 (file)
@@ -303,12 +303,10 @@ public class PurgeTest {
 
   private void assertDisabled(String key) {
     assertThat(enabledStatusOfComponent(key)).isFalse();
-    assertThat(count("resource_index ri where ri.component_uuid=(select p.uuid from projects p where p.kee='" + key + "')")).isZero();
   }
 
   private void assertExists(String key) {
     assertThat(enabledStatusOfComponent(key)).isTrue();
-    assertThat(count("resource_index ri where ri.component_uuid=(select p.uuid from projects p where p.kee='" + key + "')")).isGreaterThan(1);
   }
 
   private Boolean enabledStatusOfComponent(String key) {
index b0f0cfca80aabc87f9b58799e021b00a41c35bf0..90725ae23c94a0b1870c6764ad7e2588c0c5c8b7 100644 (file)
@@ -38,6 +38,7 @@ public class DbVersion63 implements DbVersion {
       .add(1503, "Add PROJECTS.ORGANIZATION_UUID", AddOrganizationUuidToProjects.class)
       .add(1504, "Populate PROJECTS.ORGANIZATION_UUID", PopulateOrganizationUuidToProjects.class)
       .add(1505, "Make PROJECTS.ORGANIZATION_UUID not nullable", MakeOrganizationUuidOfProjectsNotNullable.class)
-      .add(1506, "Add index on PROJECTS.ORGANIZATION_UUID", AddIndexOnOrganizationUuidOfProjects.class);
+      .add(1506, "Add index on PROJECTS.ORGANIZATION_UUID", AddIndexOnOrganizationUuidOfProjects.class)
+      .add(1507, "Drop table RESOURCE_INDEX", DropTableResourceIndex.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndex.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndex.java
new file mode 100644 (file)
index 0000000..5768998
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.server.platform.db.migration.version.v63;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropTableResourceIndex extends DdlChange {
+
+  private static final String TABLE_RESOURCE_INDEX = "resource_index";
+
+  public DropTableResourceIndex(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect())
+      .setTable(TABLE_RESOURCE_INDEX)
+      .setName("resource_index_key")
+      .build());
+
+    context.execute(new DropIndexBuilder(getDialect())
+      .setTable(TABLE_RESOURCE_INDEX)
+      .setName("resource_index_component")
+      .build());
+
+    context.execute(new DropTableBuilder(getDialect(), TABLE_RESOURCE_INDEX).build());
+  }
+
+}
index 6f430efcf5285e2c1b9bfbea70c9b82d8afd197f..7b286029c7fc817689531b29f73a13e730754046 100644 (file)
@@ -41,7 +41,7 @@ public class DbVersion63Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 7);
+    verifyMigrationCount(underTest, 8);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest.java
new file mode 100644 (file)
index 0000000..f5322e9
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.server.platform.db.migration.version.v63;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+public class DropTableResourceIndexTest {
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, DropTableResourceIndexTest.class, "schema.sql");
+
+  private DropTableResourceIndex underTest = new DropTableResourceIndex(db.database());
+
+  @Test
+  public void should_drop_table() throws SQLException {
+    underTest.execute();
+
+    db.assertTableDoesNotExist("resource_index");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws Exception {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+    underTest.execute();
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest/schema.sql
new file mode 100644 (file)
index 0000000..be7a240
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "RESOURCE_INDEX" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "KEE" VARCHAR(400) NOT NULL,
+  "POSITION" INTEGER NOT NULL,
+  "NAME_SIZE" INTEGER NOT NULL,
+  "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+  "ROOT_COMPONENT_UUID" VARCHAR(50) NOT NULL,
+  "QUALIFIER" VARCHAR(10) NOT NULL
+);
+CREATE INDEX "RESOURCE_INDEX_KEY" ON "RESOURCE_INDEX" ("KEE");
+CREATE INDEX "RESOURCE_INDEX_COMPONENT" ON "RESOURCE_INDEX" ("COMPONENT_UUID");
+
index 20c9d60d7cd2161a52a4dabf422318fbb6b06b8e..5583e4ee67011c34c07b5e59230a882771f6d291 100644 (file)
@@ -48,7 +48,7 @@ public class BackendCleanup {
 
   private static final String[] INSPECTION_TABLES = {
     "authors", "duplications_index", "events", "issues", "issue_changes", "manual_measures",
-    "notifications", "project_links", "project_measures", "projects", "resource_index",
+    "notifications", "project_links", "project_measures", "projects",
     "snapshots", "file_sources"
   };
   private static final String[] RESOURCE_RELATED_TABLES = {
index e08c27fdc8969714c23337bc27aa1f23cfab0768..b4c5af2e0f9c8636507d84c58396151b3a7f4568 100644 (file)
@@ -27,8 +27,6 @@ public final class SqTables {
    * These tables are still involved in DB migrations, so potentially
    * incorrect collation must be fixed so that joins with other
    * tables are possible.
-   *
-   * @see org.sonar.db.charset.ColumnDef#isInSonarQubeTable()
    */
   public static final Set<String> OLD_DROPPED_TABLES = ImmutableSet.of(
     "active_dashboards",
@@ -38,6 +36,7 @@ public final class SqTables {
     "issue_filter_favourites",
     "measure_filters",
     "measure_filter_favourites",
+    "resource_index",
     "widgets",
     "widget_properties");
 
@@ -80,7 +79,6 @@ public final class SqTables {
     "project_qprofiles",
     "properties",
     "qprofile_changes",
-    "resource_index",
     "rules",
     "rules_parameters",
     "rules_profiles",
index 7bfcdc34defe53d5165e40e3fb0e3992916f239d..d7ba8f8625d374346262a9de8ec5e71e57ab5cf2 100644 (file)
@@ -520,6 +520,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1503');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1504');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1505');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1506');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1507');
 
 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;
index d5e8379eec40682f554659a104cd07b98ceb30ca..1ca427b7046b26ca8c38184dc6fef549172d5945 100644 (file)
@@ -399,19 +399,6 @@ CREATE TABLE "LOADED_TEMPLATES" (
 );
 
 
-CREATE TABLE "RESOURCE_INDEX" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "KEE" VARCHAR(400) NOT NULL,
-  "POSITION" INTEGER NOT NULL,
-  "NAME_SIZE" INTEGER NOT NULL,
-  "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-  "ROOT_COMPONENT_UUID" VARCHAR(50) NOT NULL,
-  "QUALIFIER" VARCHAR(10) NOT NULL
-);
-CREATE INDEX "RESOURCE_INDEX_KEY" ON "RESOURCE_INDEX" ("KEE");
-CREATE INDEX "RESOURCE_INDEX_COMPONENT" ON "RESOURCE_INDEX" ("COMPONENT_UUID");
-
-
 CREATE TABLE "AUTHORS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "PERSON_ID" INTEGER,