]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19133 Increase KEE column size in INTERNAL_PROPERTIES table
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Mon, 24 Apr 2023 07:56:23 +0000 (09:56 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 24 Apr 2023 20:04:24 +0000 (20:04 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
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/IncreaseKeeColumnSizeInInternalProperties.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest/schema.sql [new file with mode: 0644]

index 4cf0b9a17a05fc4a76872543d2ce8649873b60fe..08a75b195bee4e547d856471752bb86778e25e8d 100644 (file)
@@ -370,7 +370,7 @@ ALTER TABLE "INTERNAL_COMPONENT_PROPS" ADD CONSTRAINT "PK_INTERNAL_COMPONENT_PRO
 CREATE UNIQUE INDEX "UNIQUE_COMPONENT_UUID_KEE" ON "INTERNAL_COMPONENT_PROPS"("COMPONENT_UUID" NULLS FIRST, "KEE" NULLS FIRST);
 
 CREATE TABLE "INTERNAL_PROPERTIES"(
-    "KEE" CHARACTER VARYING(20) NOT NULL,
+    "KEE" CHARACTER VARYING(40) NOT NULL,
     "IS_EMPTY" BOOLEAN NOT NULL,
     "TEXT_VALUE" CHARACTER VARYING(4000),
     "CLOB_VALUE" CHARACTER LARGE OBJECT,
index fda502b11aab3cb9016aa0b21e8909ab379f91b7..7434d7b35dee32489fffe1b877cfba3f0723a18e 100644 (file)
@@ -52,6 +52,7 @@ public class DbVersion101 implements DbVersion {
       .add(10_1_005, "Add column 'is_main' to 'project_branches' table", AddIsMainColumnInProjectBranches.class)
       .add(10_1_006, "Update value of 'is_main' in 'project_branches' table", UpdateIsMainColumnInProjectBranches.class)
       .add(10_1_007, "Alter column 'is_main' in 'project_branches' table - make it not nullable", AlterIsMainColumnInProjectBranches.class)
+      .add(10_1_008, "Increase size of 'internal_properties.kee' from 20 to 40 characters", IncreaseKeeColumnSizeInInternalProperties.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalProperties.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalProperties.java
new file mode 100644 (file)
index 0000000..16b6b23
--- /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 IncreaseKeeColumnSizeInInternalProperties extends DdlChange {
+  @VisibleForTesting
+  static final String TABLE_NAME = "internal_properties";
+  @VisibleForTesting
+  static final String COLUMN_NAME = "kee";
+  @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 IncreaseKeeColumnSizeInInternalProperties(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/IncreaseKeeColumnSizeInInternalPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest.java
new file mode 100644 (file)
index 0000000..9143931
--- /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.IncreaseKeeColumnSizeInInternalProperties.COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.NEW_COLUMN_SIZE;
+import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.TABLE_NAME;
+
+public class IncreaseKeeColumnSizeInInternalPropertiesTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(IncreaseKeeColumnSizeInInternalPropertiesTest.class, "schema.sql");
+
+  private final IncreaseKeeColumnSizeInInternalProperties underTest = new IncreaseKeeColumnSizeInInternalProperties(db.database());
+
+  @Test
+  public void execute_increaseColumnSize() throws SQLException {
+    db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 20, 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, 20, 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/IncreaseKeeColumnSizeInInternalPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest/schema.sql
new file mode 100644 (file)
index 0000000..857779b
--- /dev/null
@@ -0,0 +1,8 @@
+CREATE TABLE "INTERNAL_PROPERTIES"(
+    "KEE" CHARACTER VARYING(20) NOT NULL,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" CHARACTER VARYING(4000),
+    "CLOB_VALUE" CHARACTER LARGE OBJECT,
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "INTERNAL_PROPERTIES" ADD CONSTRAINT "PK_INTERNAL_PROPERTIES" PRIMARY KEY("KEE");