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) {
.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);
}
}
--- /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.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());
+ }
+
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 7);
+ verifyMigrationCount(underTest, 8);
}
}
--- /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.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();
+ }
+}
--- /dev/null
+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");
+
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 = {
* 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",
"issue_filter_favourites",
"measure_filters",
"measure_filter_favourites",
+ "resource_index",
"widgets",
"widget_properties");
"project_qprofiles",
"properties",
"qprofile_changes",
- "resource_index",
"rules",
"rules_parameters",
"rules_profiles",
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;
);
-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,