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
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;
CreateTableRuleRepositories.class,
DropTableActivities.class,
DropTableProperties.class,
+ RenameTableProperties2ToProperties.class,
// 6.2
CreateTableOrganizations.class,
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);
--- /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.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());
+ }
+
+}
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);
}
}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+}
--- /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.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");
+ }
+
+}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+
+}
--- /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.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);
+ }
+
+}
underTest.execute();
verifyColumnDefinitions();
+ verifyIndex();
}
@Test
underTest.execute();
verifyColumnDefinitions();
+ verifyIndex();
assertThat(idsOfRowsInDuplicationsIndex()).containsOnly(1L, 2L);
}
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());
}
underTest.execute();
verifyColumnDefinitions();
+ verifyIndices();
}
@Test
underTest.execute();
verifyColumnDefinitions();
+ verifyIndices();
}
@Test
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,
underTest.execute();
verifyColumnDefinitions();
+ verifyIndex();
}
@Test
underTest.execute();
verifyColumnDefinitions();
+ verifyIndex();
}
@Test
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(
underTest.execute();
verifyColumnDefinitions();
+ verifyIndex();
}
@Test
underTest.execute();
verifyColumnDefinitions();
+ verifyIndex();
}
@Test
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",
--- /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.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);
+ }
+}