aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Vinot <antoine.vinot@sonarsource.com>2025-07-03 16:14:04 +0200
committersonartech <sonartech@sonarsource.com>2025-07-03 20:04:26 +0000
commitaee0eb051497a3f05b27e2266e8d53700721613a (patch)
treea595723780bdec82c47c830a7da15d5e175bad0a
parent1ccf2322046f36999e055fce6526abd8b21fddec (diff)
downloadsonarqube-aee0eb051497a3f05b27e2266e8d53700721613a.tar.gz
sonarqube-aee0eb051497a3f05b27e2266e8d53700721613a.zip
SONAR-25117 Update rule names max size to 255
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl2
-rw-r--r--server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSizeTest.java55
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/DbVersion202504.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSize.java53
4 files changed, 110 insertions, 3 deletions
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 1718ab4dddd..8f044babde1 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -967,7 +967,7 @@ CREATE UNIQUE NULLS NOT DISTINCT INDEX "RULE_TAGS_RULE_UUID" ON "RULE_TAGS"("RUL
CREATE TABLE "RULES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
- "NAME" CHARACTER VARYING(200),
+ "NAME" CHARACTER VARYING(255),
"PLUGIN_RULE_KEY" CHARACTER VARYING(200) NOT NULL,
"PLUGIN_KEY" CHARACTER VARYING(200),
"PLUGIN_CONFIG_KEY" CHARACTER VARYING(200),
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSizeTest.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSizeTest.java
new file mode 100644
index 00000000000..c087c930ef2
--- /dev/null
+++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSizeTest.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2025 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.v202504;
+
+import java.sql.SQLException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.db.MigrationDbTester;
+
+import static java.sql.Types.VARCHAR;
+import static org.sonar.db.MigrationDbTester.createForMigrationStep;
+
+class UpdateRulesNameColumnSizeTest {
+
+ private static final String TABLE_NAME = "rules";
+ private static final String COLUMN_NAME = "name";
+
+ @RegisterExtension
+ public final MigrationDbTester db = createForMigrationStep(DropUniqueIndexOnScaLicenseProfiles.class);
+ private final UpdateRulesNameColumnSize updateRulesNameColumnSize = new UpdateRulesNameColumnSize(db.database());
+
+ @Test
+ void migration_updates_rules_name_column_size() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 200, true);
+
+ updateRulesNameColumnSize.execute();
+
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 255, true);
+ }
+
+ @Test
+ void migration_is_reentrant() throws SQLException {
+ updateRulesNameColumnSize.execute();
+ updateRulesNameColumnSize.execute();
+
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 255, true);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/DbVersion202504.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/DbVersion202504.java
index 97a956b6ca7..def39c458a1 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/DbVersion202504.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/DbVersion202504.java
@@ -37,7 +37,6 @@ public class DbVersion202504 implements DbVersion {
.add(2025_04_005, "Add 'original_severity' and 'manual_severity' columns to 'sca_issues_releases' table", AddOriginalAndManualSeverityToScaIssues.class)
.add(2025_04_006, "Populate 'original_severity' column for 'sca_issues_releases' table", PopulateOriginalSeverityForScaIssuesReleasesTable.class)
.add(2025_04_007, "Update 'original_severity' column to be not nullable in 'sca_issues_releases' table", UpdateScaIssuesReleasesOriginalSeverityColumnNotNullable.class)
-
- ;
+ .add(2025_04_008, "Update size of 'name' column in 'rules' table", UpdateRulesNameColumnSize.class);
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSize.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSize.java
new file mode 100644
index 00000000000..c93096e5293
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202504/UpdateRulesNameColumnSize.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2025 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.v202504;
+
+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.db.DatabaseUtils.tableColumnExists;
+
+public class UpdateRulesNameColumnSize extends DdlChange {
+ private static final String TABLE_NAME = "rules";
+ private static final String COLUMN_NAME = "name";
+ private static final int NEW_COLUMN_SIZE = 255;
+
+ public UpdateRulesNameColumnSize(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ if (tableColumnExists(connection, TABLE_NAME, COLUMN_NAME)) {
+ var columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
+ .setColumnName(COLUMN_NAME)
+ .setLimit(NEW_COLUMN_SIZE)
+ .build();
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
+ .updateColumn(columnDef)
+ .build());
+ }
+ }
+ }
+}