]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19556 indexes are now re-created when renaming a column
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Thu, 15 Jun 2023 15:34:58 +0000 (17:34 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 20 Jun 2023 13:10:19 +0000 (13:10 +0000)
15 files changed:
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/CreateIndexOnColumn.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivity.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueue.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRoles.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRoles.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRoles.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRoles.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivity.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueue.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivity.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql [new file with mode: 0644]

index 6984619c21264f22b87473a60c52d826257b2d16..6efa0698926da3f613d5d41162d3a8ca6d8c776a 100644 (file)
@@ -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 (file)
index 0000000..8855706
--- /dev/null
@@ -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;
+  }
+}
index ec5d97057ff114600847ddb5709e843915b7219c..f1a40c60241c907a4aecebac230905be83b8033a 100644 (file)
@@ -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 (file)
index 0000000..8b482fb
--- /dev/null
@@ -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 (file)
index 0000000..e61a3af
--- /dev/null
@@ -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 (file)
index 0000000..5a603c3
--- /dev/null
@@ -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 (file)
index 0000000..1453651
--- /dev/null
@@ -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);
+  }
+}
index 60008a21274437747f1b91575023a50f8868e3fb..20a9cff3ad1b18fe6412be0c9b23ee0d51d8d24d 100644 (file)
@@ -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 (file)
index 0000000..24934d8
--- /dev/null
@@ -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 (file)
index 0000000..0612f1c
--- /dev/null
@@ -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 (file)
index 0000000..24ff2c0
--- /dev/null
@@ -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 (file)
index 0000000..5543467
--- /dev/null
@@ -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);
+  }
+}
index c41576a18d42c2db984a2324685e604645467673..2acbca0a99e258f81158b5d66e8f1e812a9ac00e 100644 (file)
@@ -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 (file)
index 0000000..8e00318
--- /dev/null
@@ -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 (file)
index 0000000..28453ff
--- /dev/null
@@ -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);