import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.slf4j.LoggerFactory;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.System2;
-import org.slf4j.LoggerFactory;
import org.sonar.ce.task.CeTask;
import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.stream.MoreCollectors;
private final String columnName;
private final boolean unique;
- public CreateIndexOnColumn(Database db, String table, String columnName, boolean unique) {
+ protected CreateIndexOnColumn(Database db, String table, String columnName, boolean unique) {
super(db);
this.table = table;
this.columnName = columnName;
public class CreateIndexEntityUuidInUserRoles extends CreateIndexOnColumn {
- private static final String TABLE_NAME = "group_roles";
+ private static final String TABLE_NAME = "user_roles";
private static final String COLUMN_NAME = "entity_uuid";
public CreateIndexEntityUuidInUserRoles(Database db) {
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);
--- /dev/null
+/*
+ * 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 CreateIndexEntityUuidInCeActivityTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexEntityUuidInCeActivityTest.class, "schema.sql");
+
+ private final CreateIndexEntityUuidInCeActivity createIndex = new CreateIndexEntityUuidInCeActivity(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("ce_activity", "ce_activity_entity_uuid");
+
+ createIndex.execute();
+
+ db.assertIndex("ce_activity", "ce_activity_entity_uuid", "entity_uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ createIndex.execute();
+ createIndex.execute();
+
+ db.assertIndex("ce_activity", "ce_activity_entity_uuid", "entity_uuid");
+ }
+}
--- /dev/null
+/*
+ * 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 CreateIndexEntityUuidInCeQueueTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexEntityUuidInCeQueueTest.class, "schema.sql");
+
+ private final CreateIndexEntityUuidInCeQueue createIndex = new CreateIndexEntityUuidInCeQueue(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("ce_queue", "ce_queue_entity_uuid");
+
+ createIndex.execute();
+
+ db.assertIndex("ce_queue", "ce_queue_entity_uuid", "entity_uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ createIndex.execute();
+ createIndex.execute();
+
+ db.assertIndex("ce_queue", "ce_queue_entity_uuid", "entity_uuid");
+ }
+}
--- /dev/null
+/*
+ * 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 CreateIndexEntityUuidInGroupRolesTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexEntityUuidInGroupRolesTest.class, "schema.sql");
+
+ private final CreateIndexEntityUuidInGroupRoles createIndex = new CreateIndexEntityUuidInGroupRoles(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("group_roles", "group_roles_entity_uuid");
+
+ createIndex.execute();
+
+ db.assertIndex("group_roles", "group_roles_entity_uuid", "entity_uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ createIndex.execute();
+ createIndex.execute();
+
+ db.assertIndex("group_roles", "group_roles_entity_uuid", "entity_uuid");
+ }
+}
--- /dev/null
+/*
+ * 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 CreateIndexEntityUuidInUserRolesTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexEntityUuidInUserRolesTest.class, "schema.sql");
+
+ private final CreateIndexEntityUuidInUserRoles createIndex = new CreateIndexEntityUuidInUserRoles(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("user_roles", "user_roles_entity_uuid");
+
+ createIndex.execute();
+
+ db.assertIndex("user_roles", "user_roles_entity_uuid", "entity_uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ createIndex.execute();
+ createIndex.execute();
+
+ db.assertIndex("user_roles", "user_roles_entity_uuid", "entity_uuid");
+ }
+}
--- /dev/null
+CREATE TABLE "CE_ACTIVITY"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
+ "ENTITY_UUID" CHARACTER VARYING(40),
+ "COMPONENT_UUID" CHARACTER VARYING(40),
+ "STATUS" CHARACTER VARYING(15) NOT NULL,
+ "MAIN_IS_LAST" BOOLEAN NOT NULL,
+ "MAIN_IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL,
+ "IS_LAST" BOOLEAN NOT NULL,
+ "IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL,
+ "SUBMITTER_UUID" CHARACTER VARYING(255),
+ "SUBMITTED_AT" BIGINT NOT NULL,
+ "STARTED_AT" BIGINT,
+ "EXECUTED_AT" BIGINT,
+ "EXECUTION_COUNT" INTEGER NOT NULL,
+ "EXECUTION_TIME_MS" BIGINT,
+ "ANALYSIS_UUID" CHARACTER VARYING(50),
+ "ERROR_MESSAGE" CHARACTER VARYING(1000),
+ "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+ "ERROR_TYPE" CHARACTER VARYING(20),
+ "WORKER_UUID" CHARACTER VARYING(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "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_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);
\ No newline at end of file
--- /dev/null
+CREATE TABLE "CE_QUEUE"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
+ "ENTITY_UUID" CHARACTER VARYING(40),
+ "COMPONENT_UUID" CHARACTER VARYING(40),
+ "STATUS" CHARACTER VARYING(15),
+ "SUBMITTER_UUID" CHARACTER VARYING(255),
+ "STARTED_AT" BIGINT,
+ "WORKER_UUID" CHARACTER VARYING(40),
+ "EXECUTION_COUNT" INTEGER NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST);
\ No newline at end of file
--- /dev/null
+CREATE TABLE "GROUP_ROLES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "ROLE" CHARACTER VARYING(64) NOT NULL,
+ "ENTITY_UUID" CHARACTER VARYING(40),
+ "GROUP_UUID" CHARACTER VARYING(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "ENTITY_UUID" NULLS FIRST, "ROLE" NULLS FIRST);
\ No newline at end of file
--- /dev/null
+CREATE TABLE "USER_ROLES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "ROLE" CHARACTER VARYING(64) NOT NULL,
+ "ENTITY_UUID" CHARACTER VARYING(40),
+ "USER_UUID" CHARACTER VARYING(255)
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID" NULLS FIRST);
\ No newline at end of file
/**
* Should use {@link org.sonar.server.project.Project#fromProjectDtoWithTags(org.sonar.db.project.ProjectDto)} instead
*/
- @Deprecated
+ @Deprecated(since = "10.2")
public static Project from(ComponentDto project) {
return new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList());
}
switch (entity.getQualifier()) {
case Qualifiers.PROJECT -> issueQueryBuilder.projectUuids(Set.of(entity.getUuid()));
case Qualifiers.VIEW, Qualifiers.APP -> issueQueryBuilder.viewUuids(Set.of(entity.getUuid()));
- default ->
- throw new IllegalArgumentException(String.format("Entity of type '%s' is not supported", entity.getQualifier()));
+ default -> throw new IllegalArgumentException(String.format("Entity of type '%s' is not supported", entity.getQualifier()));
}
if (branch != null && !branch.isMain()) {