aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-09-21 11:10:29 -0500
committersonartech <sonartech@sonarsource.com>2021-09-22 20:03:21 +0000
commitbee7ee5ec9f07f9f54804eeb22c1e2e547afc2e8 (patch)
tree35043e9d36f398459d41db45e849113584dd9128 /server/sonar-db-migration
parent954e6a04356300aaa28e7c0dc7df5d1aa555c7b1 (diff)
downloadsonarqube-bee7ee5ec9f07f9f54804eeb22c1e2e547afc2e8.tar.gz
sonarqube-bee7ee5ec9f07f9f54804eeb22c1e2e547afc2e8.zip
SONAR-15422 Portfolios 'selection_expression' column is too short
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTable.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java32
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest.java53
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92Test.java47
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest/schema.sql15
6 files changed, 198 insertions, 0 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
index aefa1a5d9ad..beb3929e55f 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
@@ -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
index 00000000000..441b05ee398
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTable.java
@@ -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
index 00000000000..64d0ed85f5f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92.java
@@ -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
index 00000000000..3ea431b6ca4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest.java
@@ -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
index 00000000000..cb68553e66a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v92/DbVersion92Test.java
@@ -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
index 00000000000..3b5fef0154b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v92/AlterSelectionExpressionInPortfoliosTableTest/schema.sql
@@ -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");