]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15422 Portfolios 'selection_expression' column is too short
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 21 Sep 2021 16:10:29 +0000 (11:10 -0500)
committersonartech <sonartech@sonarsource.com>
Wed, 22 Sep 2021 20:03:21 +0000 (20:03 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest/schema.sql [new file with mode: 0644]

index 869c173f7e0530c42163f936b2844c3615dbc586..a5d8d5fec77c326a50137fa07829c114c288c46b 100644 (file)
@@ -590,7 +590,7 @@ CREATE TABLE "PORTFOLIOS"(
     "PARENT_UUID" VARCHAR(40),
     "PRIVATE" BOOLEAN NOT NULL,
     "SELECTION_MODE" VARCHAR(50) NOT NULL,
-    "SELECTION_EXPRESSION" VARCHAR(50),
+    "SELECTION_EXPRESSION" VARCHAR(4000),
     "CREATED_AT" BIGINT NOT NULL,
     "UPDATED_AT" BIGINT NOT NULL
 );
index aefa1a5d9ad6773b67d64c9c5f31f13bd9b18162..beb3929e55f78523caf6f072f7dc75bd8be62974 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
 import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
 import org.sonar.server.platform.db.migration.version.v90.DbVersion90;
 import org.sonar.server.platform.db.migration.version.v91.DbVersion91;
+import org.sonar.server.platform.db.migration.version.v92.DbVersion92;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -38,6 +39,7 @@ public class MigrationConfigurationModule extends Module {
       DbVersion00.class,
       DbVersion90.class,
       DbVersion91.class,
+      DbVersion92.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTable.java
new file mode 100644 (file)
index 0000000..441b05e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+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;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AlterSelectionExpressionInPortfoliosTable extends DdlChange {
+  private static final String TABLE = "portfolios";
+
+  private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("selection_expression")
+    .setIsNullable(true)
+    .setLimit(VarcharColumnDef.MAX_SIZE)
+    .build();
+
+  public AlterSelectionExpressionInPortfoliosTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(columnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java
new file mode 100644 (file)
index 0000000..64d0ed8
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion92 implements DbVersion {
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry
+      .add(6101, "Change size of column 'selection_expression' in 'Portfolios'", AlterSelectionExpressionInPortfoliosTable.class)
+    ;
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest.java
new file mode 100644 (file)
index 0000000..3ea431b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static java.sql.Types.VARCHAR;
+
+public class AlterSelectionExpressionInPortfoliosTableTest {
+  private final String TABLE = "portfolios";
+  private final String COLUMN = "selection_expression";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AlterSelectionExpressionInPortfoliosTableTest.class, "schema.sql");
+
+  private final DdlChange underTest = new AlterSelectionExpressionInPortfoliosTable(db.database());
+
+  @Test
+  public void selection_expression_column_is_altered() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition(TABLE, COLUMN, VARCHAR, 4000, true);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    underTest.execute();
+    underTest.execute();
+
+    db.assertColumnDefinition(TABLE, COLUMN, VARCHAR, 4000, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92Test.java
new file mode 100644 (file)
index 0000000..cb68553
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v92;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion92Test {
+
+  private final DbVersion92 underTest = new DbVersion92();
+
+  @Test
+  public void verify_no_support_component() {
+    assertThat(underTest.getSupportComponents()).isEmpty();
+  }
+
+  @Test
+  public void migrationNumber_starts_at_6101() {
+    verifyMinimumMigrationNumber(underTest, 6101);
+  }
+
+  @Test
+  public void verify_migration_count() {
+    verifyMigrationCount(underTest, 1);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest/schema.sql
new file mode 100644 (file)
index 0000000..3b5fef0
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE TABLE "PORTFOLIOS"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(400) NOT NULL,
+    "NAME" VARCHAR(2000) NOT NULL,
+    "DESCRIPTION" VARCHAR(2000),
+    "ROOT_UUID" VARCHAR(40) NOT NULL,
+    "PARENT_UUID" VARCHAR(40),
+    "PRIVATE" BOOLEAN NOT NULL,
+    "SELECTION_MODE" VARCHAR(50) NOT NULL,
+    "SELECTION_EXPRESSION" VARCHAR(50),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PORTFOLIOS" ADD CONSTRAINT "PK_PORTFOLIOS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_PORTFOLIOS_KEE" ON "PORTFOLIOS"("KEE");