]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19159 Increase TASK_TYPE column size in ce_queue and ce_activity
authorAntoine Vigneau <antoine.vigneau@sonarsource.com>
Thu, 27 Apr 2023 15:17:15 +0000 (17:17 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 11 May 2023 20:03:13 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.java
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDtoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/DbVersion101.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivity.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueue.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest/schema.sql [new file with mode: 0644]

index 755da76480640e43d1821bf2204035c47cb8f808..266a8f9326f607ca55568a3ab5ab46f51593244e 100644 (file)
@@ -21,11 +21,8 @@ package org.sonar.db.ce;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.sonar.db.component.ComponentDto;
 
-import static com.google.common.base.MoreObjects.firstNonNull;
 import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
 
 public class CeQueueDto {
 
@@ -110,7 +107,7 @@ public class CeQueueDto {
   }
 
   public CeQueueDto setTaskType(String s) {
-    checkArgument(s.length() <= 15, "Value of task type is too long: %s", s);
+    checkArgument(s.length() <= 40, "Value of task type is too long: %s", s);
     this.taskType = s;
     return this;
   }
index 4395b873456ccc76fea13600edfbad21373df617..07f05419329c9fbd7871b96214101bf086f1cfc4 100644 (file)
@@ -116,7 +116,7 @@ CREATE INDEX "AUDITS_CREATED_AT" ON "AUDITS"("CREATED_AT" NULLS FIRST);
 
 CREATE TABLE "CE_ACTIVITY"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
-    "TASK_TYPE" CHARACTER VARYING(15) NOT NULL,
+    "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
     "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
     "COMPONENT_UUID" CHARACTER VARYING(40),
     "STATUS" CHARACTER VARYING(15) NOT NULL,
@@ -149,7 +149,7 @@ CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY" N
 
 CREATE TABLE "CE_QUEUE"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
-    "TASK_TYPE" CHARACTER VARYING(15) NOT NULL,
+    "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
     "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
     "COMPONENT_UUID" CHARACTER VARYING(40),
     "STATUS" CHARACTER VARYING(15),
index e810a53a7d0a8eb714014174fc31f42590f5cf04..3bdb4f1183ecf2fcebb01209fcad0ca2c8e55a3c 100644 (file)
@@ -79,11 +79,11 @@ public class CeQueueDtoTest {
 
   @Test
   public void setTaskType_throws_IAE_if_value_is_41_chars() {
-    String str_16_chars = STR_15_CHARS + "a";
+    String str_41_chars = STR_40_CHARS + "a";
 
-    assertThatThrownBy(() -> underTest.setTaskType(str_16_chars))
+    assertThatThrownBy(() -> underTest.setTaskType(str_41_chars))
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Value of task type is too long: " + str_16_chars);
+      .hasMessage("Value of task type is too long: " + str_41_chars);
   }
 
   @Test
index 59f01e643cd1b9008ca5f825fb5da8925789188f..0ff5b82f4393c95036675a50ff8867396f045a8b 100644 (file)
@@ -54,6 +54,7 @@ public class DbVersion101 implements DbVersion {
       .add(10_1_010, "Remove user tokens linked to unexistent project", RemoveOrphanUserTokens.class)
       .add(10_1_011, "Populate 'project_key' in 'user_tokens'", PopulateProjectUuidInUserTokens.class)
       .add(10_1_012, "Drop column 'project_key' in 'user_tokens", DropProjectKeyInUserTokens.class)
-    ;
+      .add(10_1_013, "Increase size of 'ce_queue.task_type' from 15 to 40 characters", IncreaseTaskTypeColumnSizeInCeQueue.class)
+      .add(10_1_014, "Increase size of 'ce_activity.task_type' from 15 to 40 characters", IncreaseTaskTypeColumnSizeInCeActivity.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivity.java
new file mode 100644 (file)
index 0000000..29834ea
--- /dev/null
@@ -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.v101;
+
+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 IncreaseTaskTypeColumnSizeInCeActivity extends DdlChange {
+  @VisibleForTesting
+  static final String TABLE_NAME = "ce_activity";
+  @VisibleForTesting
+  static final String COLUMN_NAME = "task_type";
+  @VisibleForTesting
+  static final int NEW_COLUMN_SIZE = 40;
+
+  private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder()
+    .setColumnName(COLUMN_NAME)
+    .setLimit(NEW_COLUMN_SIZE)
+    .setIsNullable(false)
+    .build();
+
+  public IncreaseTaskTypeColumnSizeInCeActivity(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(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/v101/IncreaseTaskTypeColumnSizeInCeQueue.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueue.java
new file mode 100644 (file)
index 0000000..54ea923
--- /dev/null
@@ -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.v101;
+
+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 IncreaseTaskTypeColumnSizeInCeQueue extends DdlChange {
+  @VisibleForTesting
+  static final String TABLE_NAME = "ce_queue";
+  @VisibleForTesting
+  static final String COLUMN_NAME = "task_type";
+  @VisibleForTesting
+  static final int NEW_COLUMN_SIZE = 40;
+
+  private static final VarcharColumnDef COLUMN_DEFINITION = VarcharColumnDef.newVarcharColumnDefBuilder()
+    .setColumnName(COLUMN_NAME)
+    .setLimit(NEW_COLUMN_SIZE)
+    .setIsNullable(false)
+    .build();
+
+  public IncreaseTaskTypeColumnSizeInCeQueue(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(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/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java
new file mode 100644 (file)
index 0000000..3dbde96
--- /dev/null
@@ -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.v101;
+
+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.v101.IncreaseTaskTypeColumnSizeInCeActivity.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.NEW_COLUMN_SIZE;
+import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.TABLE_NAME;
+
+public class IncreaseTaskTypeColumnSizeInCeActivityTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(IncreaseTaskTypeColumnSizeInCeActivityTest.class, "schema.sql");
+
+  private final IncreaseTaskTypeColumnSizeInCeActivity underTest = new IncreaseTaskTypeColumnSizeInCeActivity(db.database());
+
+  @Test
+  public void execute_increaseColumnSize() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, 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, 15, 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/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java
new file mode 100644 (file)
index 0000000..ea718a3
--- /dev/null
@@ -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.v101;
+
+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.v101.IncreaseTaskTypeColumnSizeInCeQueue.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.NEW_COLUMN_SIZE;
+import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.TABLE_NAME;
+
+public class IncreaseTaskTypeColumnSizeInCeQueueTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(IncreaseTaskTypeColumnSizeInCeQueueTest.class, "schema.sql");
+
+  private final IncreaseTaskTypeColumnSizeInCeQueue underTest = new IncreaseTaskTypeColumnSizeInCeQueue(db.database());
+
+  @Test
+  public void execute_increaseColumnSize() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, 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, 15, 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/v101/IncreaseTaskTypeColumnSizeInCeActivityTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest/schema.sql
new file mode 100644 (file)
index 0000000..2e59554
--- /dev/null
@@ -0,0 +1,32 @@
+CREATE TABLE "CE_ACTIVITY"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "TASK_TYPE" CHARACTER VARYING(15) NOT NULL,
+    "MAIN_COMPONENT_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_COMPONENT" ON "CE_ACTIVITY"("MAIN_COMPONENT_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);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest/schema.sql
new file mode 100644 (file)
index 0000000..9ae76a9
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "CE_QUEUE"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "TASK_TYPE" CHARACTER VARYING(15) NOT NULL,
+    "MAIN_COMPONENT_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_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST);