From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Fri, 4 Aug 2023 13:57:26 +0000 (+0200) Subject: SONAR-19789 Add background task to sync single project permissions from GitHub X-Git-Tag: 10.2.0.77647~254 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2387329bac690b4cba46e553ef9678cbc7df7c11;p=sonarqube.git SONAR-19789 Add background task to sync single project permissions from GitHub --- diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 74e851017bd..cdc4eb7f5c1 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -136,9 +136,9 @@ CREATE TABLE "CE_ACTIVITY"( "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, + "MAIN_IS_LAST_KEY" CHARACTER VARYING(80) NOT NULL, "IS_LAST" BOOLEAN NOT NULL, - "IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL, + "IS_LAST_KEY" CHARACTER VARYING(80) NOT NULL, "SUBMITTER_UUID" CHARACTER VARYING(255), "SUBMITTED_AT" BIGINT NOT NULL, "STARTED_AT" BIGINT, 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 72853abfe41..a9b3582ef42 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 @@ -25,7 +25,6 @@ import org.sonar.server.platform.db.migration.version.DbVersion; // ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions @SuppressWarnings("java:S3937") public class DbVersion102 implements DbVersion { - /** * We use the start of the 10.X cycle as an opportunity to align migration numbers with the SQ version number. * Please follow this pattern: @@ -83,6 +82,9 @@ public class DbVersion102 implements DbVersion { .add(10_2_028, "Drop column 'created_at' in 'components' table", DropCreatedAtInComponents.class) .add(10_2_029, "Rename column 'created_at_temp' to 'created_at' in 'components' table", RenameCreatedAtTempInComponents.class) - .add(10_2_030, "Create table 'anticipated_transitions'", CreateAnticipatedTransitionsTable.class); + .add(10_2_030, "Create table 'anticipated_transitions'", CreateAnticipatedTransitionsTable.class) + + .add(10_2_031, "Increase size of 'ce_queue.is_last_key' from 55 to 80 characters", IncreaseIsLastKeyInCeActivity.class) + .add(10_2_032, "Increase size of 'ce_queue.main_is_last_key' from 55 to 80 characters", IncreaseMainIsLastKeyInCeActivity.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivity.java new file mode 100644 index 00000000000..06b273a7995 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivity.java @@ -0,0 +1,53 @@ +/* + * 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 com.google.common.annotations.VisibleForTesting; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class IncreaseIsLastKeyInCeActivity extends DdlChange { + @VisibleForTesting + static final String TABLE_NAME = "ce_activity"; + @VisibleForTesting + static final String COLUMN_NAME = "is_last_key"; + @VisibleForTesting + static final int NEW_COLUMN_SIZE = 80; + + private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName(COLUMN_NAME) + .setLimit(NEW_COLUMN_SIZE) + .setIsNullable(false) + .build(); + + public IncreaseIsLastKeyInCeActivity(Database db) { + super(db); + } + + @Override + public void execute(DdlChange.Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME) + .updateColumn(COLUMN_DEFINITION) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivity.java new file mode 100644 index 00000000000..67d7a059883 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivity.java @@ -0,0 +1,54 @@ +/* + * 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 com.google.common.annotations.VisibleForTesting; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class IncreaseMainIsLastKeyInCeActivity extends DdlChange { + + @VisibleForTesting + static final String TABLE_NAME = "ce_activity"; + @VisibleForTesting + static final String COLUMN_NAME = "main_is_last_key"; + @VisibleForTesting + static final int NEW_COLUMN_SIZE = 80; + + private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName(COLUMN_NAME) + .setLimit(NEW_COLUMN_SIZE) + .setIsNullable(false) + .build(); + + public IncreaseMainIsLastKeyInCeActivity(Database db) { + super(db); + } + + @Override + public void execute(DdlChange.Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME) + .updateColumn(COLUMN_DEFINITION) + .build()); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java new file mode 100644 index 00000000000..9df7f4dc744 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java @@ -0,0 +1,54 @@ +/* + * 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; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.TABLE_NAME; + +public class IncreaseIsLastKeyInCeActivityTest { + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(IncreaseIsLastKeyInCeActivityTest.class, "schema.sql"); + + private final IncreaseIsLastKeyInCeActivity underTest = new IncreaseIsLastKeyInCeActivity(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java new file mode 100644 index 00000000000..270fdd92a37 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java @@ -0,0 +1,54 @@ +/* + * 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; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.TABLE_NAME; + +public class IncreaseMainIsLastKeyInCeActivityTest { + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(IncreaseMainIsLastKeyInCeActivityTest.class, "schema.sql"); + + private final IncreaseMainIsLastKeyInCeActivity underTest = new IncreaseMainIsLastKeyInCeActivity(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest/schema.sql new file mode 100644 index 00000000000..73f57a708ad --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest/schema.sql @@ -0,0 +1,32 @@ +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); +CREATE INDEX "CE_ACTIVITY_ENTITY_UUID" ON "CE_ACTIVITY"("ENTITY_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest/schema.sql new file mode 100644 index 00000000000..73f57a708ad --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest/schema.sql @@ -0,0 +1,32 @@ +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); +CREATE INDEX "CE_ACTIVITY_ENTITY_UUID" ON "CE_ACTIVITY"("ENTITY_UUID" NULLS FIRST);