aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndex.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest.java53
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest/schema.sql12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/SqTables.java4
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql1
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl13
10 files changed, 122 insertions, 21 deletions
diff --git a/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java b/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java
index 1095e543667..fda7b3074d4 100644
--- a/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java
+++ b/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java
@@ -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) {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
index b0f0cfca80a..90725ae23c9 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63.java
@@ -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
index 00000000000..57689981e50
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndex.java
@@ -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());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
index 6f430efcf52..7b286029c7f 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DbVersion63Test.java
@@ -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
index 00000000000..f5322e9e44d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest.java
@@ -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
index 00000000000..be7a240bff8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v63/DropTableResourceIndexTest/schema.sql
@@ -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");
+
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
index 20c9d60d7cd..5583e4ee670 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
@@ -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 = {
diff --git a/sonar-db/src/main/java/org/sonar/db/version/SqTables.java b/sonar-db/src/main/java/org/sonar/db/version/SqTables.java
index e08c27fdc89..b4c5af2e0f9 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/SqTables.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/SqTables.java
@@ -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",
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 7bfcdc34def..d7ba8f8625d 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
@@ -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;
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 d5e8379eec4..1ca427b7046 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
@@ -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,