diff options
22 files changed, 767 insertions, 16 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1315_rename_table_properties2_to_properties.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1315_rename_table_properties2_to_properties.rb index 0241e47f304..e82bc5bc19d 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1315_rename_table_properties2_to_properties.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1315_rename_table_properties2_to_properties.rb @@ -24,19 +24,7 @@ class RenameTableProperties2ToProperties < ActiveRecord::Migration def self.up - drop_index_quietly :properties2, :properties2_key - rename_table_quietly :properties2, :properties - add_varchar_index :properties, :prop_key, :name => 'properties_key' - end - - private - - def self.rename_table_quietly(oldName, newName) - begin - rename_table oldName, newName - rescue - #ignore - end + execute_java_migration('org.sonar.db.version.v61.RenameTableProperties2ToProperties') end end 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 d687d760a97..01c2f6c9b1d 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 @@ -177,6 +177,7 @@ import org.sonar.db.version.v61.DropTableActivities; import org.sonar.db.version.v61.DropTableProperties; import org.sonar.db.version.v61.PopulateTableProperties2; import org.sonar.db.version.v61.RemoveViewsDefinitionFromProperties; +import org.sonar.db.version.v61.RenameTableProperties2ToProperties; import org.sonar.db.version.v61.ShrinkModuleUuidPathOfProjects; import org.sonar.db.version.v62.AddIsRootColumnOnTableUsers; import org.sonar.db.version.v62.AddOrganizationUuidToGroupRoles; @@ -402,6 +403,7 @@ public class MigrationStepModule extends Module { CreateTableRuleRepositories.class, DropTableActivities.class, DropTableProperties.class, + RenameTableProperties2ToProperties.class, // 6.2 CreateTableOrganizations.class, diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java b/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java index b1e561fee51..24d13ddcf5d 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211.java @@ -28,8 +28,8 @@ import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder; public class CreateTemporaryIndicesFor1211 extends DdlChange { - public static final String INDEX_ON_CE_ACTIVITY = "ce_activity_snapshot_id"; - public static final String INDEX_ON_DUPLICATIONS_INDEX = "dup_index_psid"; + static final String INDEX_ON_CE_ACTIVITY = "ce_activity_snapshot_id"; + static final String INDEX_ON_DUPLICATIONS_INDEX = "dup_index_psid"; public CreateTemporaryIndicesFor1211(Database db) { super(db); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v61/RenameTableProperties2ToProperties.java b/sonar-db/src/main/java/org/sonar/db/version/v61/RenameTableProperties2ToProperties.java new file mode 100644 index 00000000000..5a1d3e22efe --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v61/RenameTableProperties2ToProperties.java @@ -0,0 +1,56 @@ +/* + * 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.v61; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.CreateIndexBuilder; +import org.sonar.db.version.DdlChange; +import org.sonar.db.version.DropIndexBuilder; +import org.sonar.db.version.RenameTableBuilder; + +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class RenameTableProperties2ToProperties extends DdlChange { + + public RenameTableProperties2ToProperties(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("properties2") + .setName("properties2_key") + .build()); + + context.execute(new RenameTableBuilder(getDialect()) + .setName("properties2") + .setNewName("properties") + .build()); + + context.execute(new CreateIndexBuilder(getDialect()) + .setTable("properties") + .setName("properties_key") + .addColumn(newVarcharColumnDefBuilder().setColumnName("prop_key").setLimit(512).setIsNullable(false).build()) + .build()); + } + +} 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 615bade9e16..2b59ac8c770 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(187); + assertThat(container.size()).isEqualTo(188); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRolesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRolesTest.java new file mode 100644 index 00000000000..ff0ea40618d --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v56/RemoveUselessIndexesOnGroupRolesTest.java @@ -0,0 +1,59 @@ +/* + * 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 org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class RemoveUselessIndexesOnGroupRolesTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void remove_two_indices_from_group_roles() throws Exception { + RemoveUselessIndexesOnGroupRoles underTest = new RemoveUselessIndexesOnGroupRoles(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX group_roles_group ON group_roles")); + verify(context).execute(asList("DROP INDEX group_roles_role ON group_roles")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasuresTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasuresTest.java new file mode 100644 index 00000000000..25b00a1bc01 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/AddIndexOnComponentUuidOfMeasuresTest.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.db.version.v60; + +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.H2; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + + +public class AddIndexOnComponentUuidOfMeasuresTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Test + public void add_index_to_measures() throws Exception { + when(db.getDialect()).thenReturn(new H2()); + AddIndexOnComponentUuidOfMeasures underTest = new AddIndexOnComponentUuidOfMeasures(db); + + underTest.execute(context); + + verify(context).execute(asList("CREATE INDEX measures_component_uuid ON project_measures (component_uuid)")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshotsTest.java new file mode 100644 index 00000000000..848b7044f9a --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/AddUniqueIndexOnUuidOfSnapshotsTest.java @@ -0,0 +1,49 @@ +/* + * 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.v60; + +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.H2; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class AddUniqueIndexOnUuidOfSnapshotsTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Test + public void create_unique_index() throws Exception { + when(db.getDialect()).thenReturn(new H2()); + AddUniqueIndexOnUuidOfSnapshots underTest = new AddUniqueIndexOnUuidOfSnapshots(db); + + underTest.execute(context); + + verify(context).execute(asList("CREATE UNIQUE INDEX analyses_uuid ON snapshots (uuid)")); + verifyNoMoreInteractions(context); + } +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristicsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristicsTest.java new file mode 100644 index 00000000000..7285f40e3ed --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/CreatePermTemplatesCharacteristicsTest.java @@ -0,0 +1,57 @@ +/* + * 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.v60; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class CreatePermTemplatesCharacteristicsTest { + + private static final String TABLE_NAME = "perm_tpl_characteristics"; + + @Rule + public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreatePermTemplatesCharacteristicsTest.class, "empty.sql"); + + private CreatePermTemplatesCharacteristics underTest = new CreatePermTemplatesCharacteristics(dbTester.database()); + + @Test + public void creates_table_and_index() throws SQLException { + underTest.execute(); + + assertThat(dbTester.countRowsOfTable(TABLE_NAME)).isEqualTo(0); + dbTester.assertColumnDefinition(TABLE_NAME, "id", Types.INTEGER, null, false); + dbTester.assertPrimaryKey(TABLE_NAME, "pk_" + TABLE_NAME, "id"); + dbTester.assertColumnDefinition(TABLE_NAME, "template_id", Types.INTEGER, null); + dbTester.assertColumnDefinition(TABLE_NAME, "permission_key", Types.VARCHAR, 64, false); + dbTester.assertColumnDefinition(TABLE_NAME, "with_project_creator", Types.BOOLEAN, null, false); + dbTester.assertColumnDefinition(TABLE_NAME, "created_at", Types.BIGINT, null, false); + dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", Types.BIGINT, null, false); + + dbTester.assertUniqueIndex(TABLE_NAME, "uniq_perm_tpl_charac", "template_id", "permission_key"); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211Test.java b/sonar-db/src/test/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211Test.java new file mode 100644 index 00000000000..15fafccaccf --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/CreateTemporaryIndicesFor1211Test.java @@ -0,0 +1,57 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.H2; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + + +public class CreateTemporaryIndicesFor1211Test { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + when(db.getDialect()).thenReturn(new H2()); + } + + @Test + public void create_two_indices() throws Exception { + CreateTemporaryIndicesFor1211 underTest = new CreateTemporaryIndicesFor1211(db); + + underTest.execute(context); + + verify(context).execute(asList("CREATE INDEX ce_activity_snapshot_id ON ce_activity (snapshot_id)")); + verify(context).execute(asList("CREATE INDEX dup_index_psid ON duplications_index (project_snapshot_id)")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndexTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndexTest.java new file mode 100644 index 00000000000..182b6dabf41 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexDuplicationsIndexSidFromDuplicationsIndexTest.java @@ -0,0 +1,58 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + + +public class DropIndexDuplicationsIndexSidFromDuplicationsIndexTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void drop_index() throws Exception { + DropIndexDuplicationsIndexSidFromDuplicationsIndex underTest = new DropIndexDuplicationsIndexSidFromDuplicationsIndex(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX duplications_index_sid ON duplications_index")); + verifyNoMoreInteractions(context); + } +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjectsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjectsTest.java new file mode 100644 index 00000000000..3aa0a24b8b3 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexProjectsRootIdFromProjectsTest.java @@ -0,0 +1,59 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + + +public class DropIndexProjectsRootIdFromProjectsTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void drop_index() throws Exception { + DropIndexProjectsRootIdFromProjects underTest = new DropIndexProjectsRootIdFromProjects(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX projects_root_id ON projects")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjectsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjectsTest.java new file mode 100644 index 00000000000..c28cd60968f --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/DropIndexProjectsUuidFromProjectsTest.java @@ -0,0 +1,58 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class DropIndexProjectsUuidFromProjectsTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void drop_index() throws Exception { + DropIndexProjectsUuidFromProjects underTest = new DropIndexProjectsUuidFromProjects(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX projects_uuid ON projects")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndexTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndexTest.java new file mode 100644 index 00000000000..7032d2efbd7 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/DropResourceIndexRidFromResourceIndexTest.java @@ -0,0 +1,58 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class DropResourceIndexRidFromResourceIndexTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void drop_index_from_resource_index() throws Exception { + DropResourceIndexRidFromResourceIndex underTest = new DropResourceIndexRidFromResourceIndex(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX resource_index_rid ON resource_index")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshotsTest.java new file mode 100644 index 00000000000..3c09a3cd917 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/DropSnapshotProjectIdFromSnapshotsTest.java @@ -0,0 +1,60 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +// FIXME migration is badly named +public class DropSnapshotProjectIdFromSnapshotsTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void drop_two_indices_from_snapshots() throws Exception { + DropSnapshotProjectIdFromSnapshots underTest = new DropSnapshotProjectIdFromSnapshots(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX snapshot_project_id ON snapshots")); + verify(context).execute(asList("DROP INDEX snapshots_root_project_id ON snapshots")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210Test.java b/sonar-db/src/test/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210Test.java new file mode 100644 index 00000000000..4c98c65b4db --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/DropTemporaryIndicesOf1210Test.java @@ -0,0 +1,60 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.MySql; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + + +public class DropTemporaryIndicesOf1210Test { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + // Some databases have unique names of indexes, so table name is not declared + // when dropping an index ("drop index <index name>"). Because of that MySQL is + // used in the test so that the table name can also be verified + when(db.getDialect()).thenReturn(new MySql()); + } + + @Test + public void drop_two_indices() throws Exception { + DropTemporaryIndicesOf1210 underTest = new DropTemporaryIndicesOf1210(db); + + underTest.execute(context); + + verify(context).execute(asList("DROP INDEX ce_activity_snapshot_id ON ce_activity")); + verify(context).execute(asList("DROP INDEX dup_index_psid ON duplications_index")); + verifyNoMoreInteractions(context); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest.java index 203c2f578f6..8002ccaff69 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest.java @@ -47,6 +47,7 @@ public class MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndex(); } @Test @@ -57,6 +58,7 @@ public class MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndex(); assertThat(idsOfRowsInDuplicationsIndex()).containsOnly(1L, 2L); } @@ -85,6 +87,10 @@ public class MakeComponentUuidAndAnalysisUuidNotNullOnDuplicationsIndexTest { db.assertColumnDefinition("duplications_index", "analysis_uuid", Types.VARCHAR, 50, false); } + private void verifyIndex() { + db.assertIndex("duplications_index", "duplication_analysis_component", "analysis_uuid", "component_uuid"); + } + private List<Long> idsOfRowsInDuplicationsIndex() { return db.select("select ID from duplications_index").stream().map(map -> (Long) map.get("ID")).collect(Collectors.toList()); } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java index 2263e9e3866..c900360deb1 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java @@ -46,6 +46,7 @@ public class MakeComponentUuidColumnsNotNullOnSnapshotsTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndices(); } @Test @@ -56,6 +57,7 @@ public class MakeComponentUuidColumnsNotNullOnSnapshotsTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndices(); } @Test @@ -73,6 +75,11 @@ public class MakeComponentUuidColumnsNotNullOnSnapshotsTest { db.assertColumnDefinition(SNAPSHOTS_TABLE, "root_component_uuid", Types.VARCHAR, 50, false); } + private void verifyIndices() { + db.assertIndex(SNAPSHOTS_TABLE, "snapshot_component", "component_uuid"); + db.assertIndex(SNAPSHOTS_TABLE, "snapshot_root_component", "root_component_uuid"); + } + private void insertSnapshots(long id, boolean hasComponentUiid, boolean hasRootComponentUuid) { db.executeInsert( SNAPSHOTS_TABLE, diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjectsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjectsTest.java index a232ff295b4..6c504f4d32f 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjectsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnProjectsTest.java @@ -46,6 +46,7 @@ public class MakeUuidColumnsNotNullOnProjectsTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndex(); } @Test @@ -56,6 +57,7 @@ public class MakeUuidColumnsNotNullOnProjectsTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndex(); } @Test @@ -83,6 +85,10 @@ public class MakeUuidColumnsNotNullOnProjectsTest { db.assertColumnDefinition(PROJECTS_TABLE, "root_uuid", Types.VARCHAR, 50, false); } + private void verifyIndex() { + db.assertIndex(PROJECTS_TABLE, "projects_root_uuid", "root_uuid"); + } + private String insertComponent(long id, boolean hasUuid, boolean hasRootUuid) { String uuid = "uuid_" + id; db.executeInsert( diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndexTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndexTest.java index f60e3085763..1181ea3f7a8 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndexTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndexTest.java @@ -44,6 +44,7 @@ public class MakeUuidColumnsNotNullOnResourceIndexTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndex(); } @Test @@ -54,6 +55,7 @@ public class MakeUuidColumnsNotNullOnResourceIndexTest { underTest.execute(); verifyColumnDefinitions(); + verifyIndex(); } @Test @@ -71,6 +73,10 @@ public class MakeUuidColumnsNotNullOnResourceIndexTest { db.assertColumnDefinition("resource_index", "root_component_uuid", Types.VARCHAR, 50, false); } + private void verifyIndex() { + db.assertIndex("resource_index", "resource_index_component", "component_uuid"); + } + private void insertResourceIndex(long id, boolean hasComponentUiid, boolean hasRootComponentUuid) { db.executeInsert( "resource_index", diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjectsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjectsTest.java new file mode 100644 index 00000000000..61ff7402979 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/RecreateIndexProjectsUuidFromProjectsTest.java @@ -0,0 +1,54 @@ +/* + * 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.v60; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.sonar.db.Database; +import org.sonar.db.dialect.H2; +import org.sonar.db.version.DdlChange; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +public class RecreateIndexProjectsUuidFromProjectsTest { + + private Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); + private DdlChange.Context context = mock(DdlChange.Context.class); + + @Before + public void setUp() { + when(db.getDialect()).thenReturn(new H2()); + } + + @Test + public void create_index() throws Exception { + RecreateIndexProjectsUuidFromProjects underTest = new RecreateIndexProjectsUuidFromProjects(db); + + underTest.execute(context); + + verify(context).execute(asList("CREATE INDEX projects_uuid ON projects (uuid)")); + verifyNoMoreInteractions(context); + } +} diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v60/CreatePermTemplatesCharacteristicsTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v60/CreatePermTemplatesCharacteristicsTest/empty.sql new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v60/CreatePermTemplatesCharacteristicsTest/empty.sql |