From 4142434c9e6d89edde1bdeef643768557803d437 Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Thu, 15 Jun 2023 17:34:58 +0200 Subject: [PATCH] SONAR-19556 indexes are now re-created when renaming a column --- server/sonar-db-dao/src/schema/schema-sq.ddl | 7 +-- .../migration/step/CreateIndexOnColumn.java | 58 +++++++++++++++++++ .../step/RenameVarcharColumnChange.java | 6 +- .../CreateIndexEntityUuidInCeActivity.java | 33 +++++++++++ .../v102/CreateIndexEntityUuidInCeQueue.java | 33 +++++++++++ .../CreateIndexEntityUuidInGroupRoles.java | 33 +++++++++++ .../CreateIndexEntityUuidInUserRoles.java | 33 +++++++++++ .../migration/version/v102/DbVersion102.java | 17 +++++- .../DropIndexComponentUuidInGroupRoles.java | 33 +++++++++++ .../DropIndexComponentUuidInUserRoles.java | 33 +++++++++++ ...ropIndexMainComponentUuidInCeActivity.java | 33 +++++++++++ .../DropIndexMainComponentUuidInCeQueue.java | 33 +++++++++++ .../RenameMainComponentUuidInCeActivity.java | 1 + ...ropIndexComponentUuidInGroupRolesTest.java | 46 +++++++++++++++ .../schema.sql | 9 +++ 15 files changed, 398 insertions(+), 10 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivity.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueue.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRoles.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRoles.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRoles.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRoles.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivity.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueue.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 6984619c212..6efa0698926 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -140,12 +140,12 @@ CREATE TABLE "CE_ACTIVITY"( "NODE_NAME" CHARACTER VARYING(100) ); ALTER TABLE "CE_ACTIVITY" ADD CONSTRAINT "PK_CE_ACTIVITY" PRIMARY KEY("UUID"); -CREATE INDEX "CE_ACTIVITY_COMPONENT" ON "CE_ACTIVITY"("COMPONENT_UUID" NULLS FIRST); CREATE INDEX "CE_ACTIVITY_ISLAST" ON "CE_ACTIVITY"("IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST); CREATE INDEX "CE_ACTIVITY_ISLAST_KEY" ON "CE_ACTIVITY"("IS_LAST_KEY" NULLS FIRST); CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("ENTITY_UUID" NULLS FIRST); CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST" ON "CE_ACTIVITY"("MAIN_IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST); CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY" NULLS FIRST); +CREATE INDEX "CE_ACTIVITY_ENTITY_UUID" ON "CE_ACTIVITY"("ENTITY_UUID" NULLS FIRST); CREATE TABLE "CE_QUEUE"( "UUID" CHARACTER VARYING(40) NOT NULL, @@ -161,8 +161,8 @@ CREATE TABLE "CE_QUEUE"( "UPDATED_AT" BIGINT NOT NULL ); ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID"); -CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("ENTITY_UUID" NULLS FIRST); CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST); +CREATE INDEX "CE_QUEUE_ENTITY_UUID" ON "CE_QUEUE"("ENTITY_UUID" NULLS FIRST); CREATE TABLE "CE_SCANNER_CONTEXT"( "TASK_UUID" CHARACTER VARYING(40) NOT NULL, @@ -345,8 +345,8 @@ CREATE TABLE "GROUP_ROLES"( "GROUP_UUID" CHARACTER VARYING(40) ); ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID"); -CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("ENTITY_UUID" NULLS FIRST); CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "ENTITY_UUID" NULLS FIRST, "ROLE" NULLS FIRST); +CREATE INDEX "GROUP_ROLES_ENTITY_UUID" ON "GROUP_ROLES"("ENTITY_UUID" NULLS FIRST); CREATE TABLE "GROUPS"( "UUID" CHARACTER VARYING(40) NOT NULL, @@ -1011,7 +1011,6 @@ CREATE TABLE "USER_ROLES"( "USER_UUID" CHARACTER VARYING(255) ); ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); -CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("ENTITY_UUID" NULLS FIRST); CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID" NULLS FIRST); CREATE TABLE "USER_TOKENS"( diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumn.java new file mode 100644 index 00000000000..88557064bb3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumn.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.step; + +import java.sql.Connection; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; + +public abstract class CreateIndexOnColumn extends DdlChange { + + private final String table; + private final String columnName; + private final boolean unique; + + public CreateIndexOnColumn(Database db, String table, String columnName, boolean unique) { + super(db); + this.table = table; + this.columnName = columnName; + this.unique = unique; + } + + @Override + public void execute(Context context) throws SQLException { + try (Connection connection = getDatabase().getDataSource().getConnection()) { + if (!DatabaseUtils.indexExistsIgnoreCase(table, newIndexName(), connection)) { + context.execute(new CreateIndexBuilder() + .setTable(table) + .setName(newIndexName()) + .addColumn(columnName) + .setUnique(unique) + .build()); + } + } + } + + public String newIndexName() { + return table + "_" + columnName; + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java index ec5d97057ff..f1a40c60241 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java @@ -30,9 +30,9 @@ import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder; public abstract class RenameVarcharColumnChange extends DdlChange { - private final String table; - private final String oldColumn; - private final String newColumn; + protected final String table; + protected final String oldColumn; + protected final String newColumn; protected RenameVarcharColumnChange(Database db, String table, String oldColumn, String newColumn) { super(db); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivity.java new file mode 100644 index 00000000000..8b482fb9d57 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivity.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn; + +public class CreateIndexEntityUuidInCeActivity extends CreateIndexOnColumn { + + private static final String TABLE_NAME = "ce_activity"; + private static final String COLUMN_NAME = "entity_uuid"; + + public CreateIndexEntityUuidInCeActivity(Database db) { + super(db, TABLE_NAME, COLUMN_NAME, false); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueue.java new file mode 100644 index 00000000000..e61a3af1893 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueue.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn; + +public class CreateIndexEntityUuidInCeQueue extends CreateIndexOnColumn { + + private static final String TABLE_NAME = "ce_queue"; + private static final String COLUMN_NAME = "entity_uuid"; + + public CreateIndexEntityUuidInCeQueue(Database db) { + super(db, TABLE_NAME, COLUMN_NAME, false); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRoles.java new file mode 100644 index 00000000000..5a603c370d1 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRoles.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn; + +public class CreateIndexEntityUuidInGroupRoles extends CreateIndexOnColumn { + + private static final String TABLE_NAME = "group_roles"; + private static final String COLUMN_NAME = "entity_uuid"; + + public CreateIndexEntityUuidInGroupRoles(Database db) { + super(db, TABLE_NAME, COLUMN_NAME, false); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRoles.java new file mode 100644 index 00000000000..1453651969b --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRoles.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn; + +public class CreateIndexEntityUuidInUserRoles extends CreateIndexOnColumn { + + private static final String TABLE_NAME = "group_roles"; + private static final String COLUMN_NAME = "entity_uuid"; + + public CreateIndexEntityUuidInUserRoles(Database db) { + super(db, TABLE_NAME, COLUMN_NAME, false); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java index 60008a21274..20a9cff3ad1 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java @@ -40,10 +40,21 @@ public class DbVersion102 implements DbVersion { @Override public void addSteps(MigrationStepRegistry registry) { - registry.add(10_2_000, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid'", RenameComponentUuidInUserRoles.class) + registry.add(10_2_000, "Drop index 'group_roles_component_uuid' in 'group_roles'", DropIndexComponentUuidInGroupRoles.class) .add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class) - .add(10_2_002, "Rename 'main_component_uuid' in 'ce_activity' table to 'entity_uuid'", RenameMainComponentUuidInCeActivity.class) - .add(10_2_003, "Rename 'main_component_uuid' in 'ce_queue' table to 'entity_uuid'", RenameMainComponentUuidInCeQueue.class) + .add(10_2_002, "Create index 'entity_uuid_user_roles' in 'group_roles' table", CreateIndexEntityUuidInGroupRoles.class) + + .add(10_2_003, "Drop index 'user_roles_component_uuid' in 'user_roles' table", DropIndexComponentUuidInUserRoles.class) + .add(10_2_004, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid", RenameComponentUuidInUserRoles.class) + .add(10_2_005, "Create index 'user_roles_entity_uuid' in 'user_roles'", CreateIndexEntityUuidInUserRoles.class) + + .add(10_2_006, "Drop index 'ce_activity_component' in 'ce_activity'", DropIndexMainComponentUuidInCeActivity.class) + .add(10_2_007, "Rename 'main_component_uuid' in 'ce_activity' table to 'entity_uuid'", RenameMainComponentUuidInCeActivity.class) + .add(10_2_008, "Create index 'ce_activity_entity_uuid' in 'ce_activity' table'", CreateIndexEntityUuidInCeActivity.class) + + .add(10_2_009, "Drop index 'ce_queue_main_component' in 'ce_queue' table", DropIndexMainComponentUuidInCeQueue.class) + .add(10_2_010, "Rename 'main_component_uuid' in 'ce_queue' table to 'entity_uuid'", RenameMainComponentUuidInCeQueue.class) + .add(10_2_011, "Create index 'ce_queue_entity_uuid' in 'ce_queue' table", CreateIndexEntityUuidInCeQueue.class) ; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRoles.java new file mode 100644 index 00000000000..24934d89f77 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRoles.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexComponentUuidInGroupRoles extends DropIndexChange { + + private static final String TABLE_NAME = "group_roles"; + private static final String INDEX_NAME = "group_roles_component_uuid"; + + public DropIndexComponentUuidInGroupRoles(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRoles.java new file mode 100644 index 00000000000..0612f1cdee3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRoles.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexComponentUuidInUserRoles extends DropIndexChange { + + private static final String TABLE_NAME = "user_roles"; + private static final String INDEX_NAME = "user_roles_component_uuid"; + + public DropIndexComponentUuidInUserRoles(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivity.java new file mode 100644 index 00000000000..24ff2c08287 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivity.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexMainComponentUuidInCeActivity extends DropIndexChange { + + private static final String TABLE_NAME = "ce_activity"; + private static final String INDEX_NAME = "ce_activity_component"; + + public DropIndexMainComponentUuidInCeActivity(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueue.java new file mode 100644 index 00000000000..5543467a4e7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueue.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexMainComponentUuidInCeQueue extends DropIndexChange { + + private static final String TABLE_NAME = "ce_queue"; + private static final String INDEX_NAME = "ce_queue_main_component"; + + public DropIndexMainComponentUuidInCeQueue(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java index c41576a18d4..2acbca0a99e 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java @@ -27,6 +27,7 @@ public class RenameMainComponentUuidInCeActivity extends RenameVarcharColumnChan private static final String TABLE_NAME = "ce_activity"; private static final String OLD_COLUMN_NAME = "main_component_uuid"; private static final String NEW_COLUMN_NAME = "entity_uuid"; + private static final String OLD_INDEX_NAME = "ce_activity_main_component"; public RenameMainComponentUuidInCeActivity(Database db) { super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java new file mode 100644 index 00000000000..8e00318d4f5 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +public class DropIndexComponentUuidInGroupRolesTest { + + private static final String TABLE_NAME = "group_roles"; + private static final String COLUMN_NAME = "component_uuid"; + private static final String INDEX_NAME = "group_roles_component_uuid"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(RenameComponentUuidInGroupRolesTest.class, "schema.sql"); + + private final RenameComponentUuidInGroupRoles underTest = new RenameComponentUuidInGroupRoles(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql new file mode 100644 index 00000000000..28453ffd067 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "GROUP_ROLES"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "ROLE" CHARACTER VARYING(64) NOT NULL, + "COMPONENT_UUID" CHARACTER VARYING(40), + "GROUP_UUID" CHARACTER VARYING(40) +); +ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID"); +CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID" NULLS FIRST); +CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "COMPONENT_UUID" NULLS FIRST, "ROLE" NULLS FIRST); -- 2.39.5