aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Poreda <jacek.poreda@sonarsource.com>2024-11-21 10:59:38 +0100
committersonartech <sonartech@sonarsource.com>2024-11-29 20:03:06 +0000
commit7aeeaa3fe7b3a491385d467f523a6273a06053fd (patch)
tree124b362a30a7af89d1cc622ca73f8bc1cc06756c
parent2e581ba13369a28401e3ea359579f977b2c8a3c0 (diff)
downloadsonarqube-7aeeaa3fe7b3a491385d467f523a6273a06053fd.tar.gz
sonarqube-7aeeaa3fe7b3a491385d467f523a6273a06053fd.zip
SONAR-23619 Add DB migration for 'quality_gates' table to add 'ai_code_supported' boolean flag
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml2
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTable.java53
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java4
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTableTest.java54
7 files changed, 124 insertions, 3 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java
index 7d588c0d1e8..a953a97d098 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java
@@ -63,6 +63,7 @@ class QualityGateDaoIT {
assertThat(reloaded.getName()).isEqualTo("My Quality Gate");
assertThat(reloaded.getUuid()).isEqualTo(newQgate.getUuid());
assertThat(reloaded.isBuiltIn()).isFalse();
+ assertThat(reloaded.isAiCodeSupported()).isFalse();
assertThat(reloaded.getCreatedAt()).isNotNull();
assertThat(reloaded.getUpdatedAt()).isNotNull();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java
index 4d48cfada0d..5ef681fb22e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java
@@ -29,6 +29,7 @@ public class QualityGateDto {
private String name;
private String uuid;
private boolean isBuiltIn;
+ private boolean aiCodeSupported;
private Date createdAt;
private Date updatedAt;
@@ -59,6 +60,15 @@ public class QualityGateDto {
return this;
}
+ public boolean isAiCodeSupported() {
+ return aiCodeSupported;
+ }
+
+ public QualityGateDto setAiCodeSupported(boolean aiCodeSupported) {
+ this.aiCodeSupported = aiCodeSupported;
+ return this;
+ }
+
public Date getCreatedAt() {
return createdAt;
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
index 3465cb761f2..2036ff7ac4d 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
@@ -3,7 +3,7 @@
<mapper namespace="org.sonar.db.qualitygate.QualityGateMapper">
<sql id="gateColumns">
- qg.uuid, qg.name, qg.is_built_in as isBuiltIn, qg.created_at as createdAt, qg.updated_at as updatedAt
+ qg.uuid, qg.name, qg.is_built_in as isBuiltIn, qg.ai_code_supported as aiCodeSupported, qg.created_at as createdAt, qg.updated_at as updatedAt
</sql>
<sql id="qualityGateFindingColumns">
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 34cfb933d22..eaa9aa9cf7f 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -898,7 +898,8 @@ CREATE TABLE "QUALITY_GATES"(
"NAME" CHARACTER VARYING(100) NOT NULL,
"IS_BUILT_IN" BOOLEAN NOT NULL,
"CREATED_AT" TIMESTAMP,
- "UPDATED_AT" TIMESTAMP
+ "UPDATED_AT" TIMESTAMP,
+ "AI_CODE_SUPPORTED" BOOLEAN DEFAULT FALSE NOT NULL
);
ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTable.java
new file mode 100644
index 00000000000..b9e67816e14
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTable.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.v108;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.db.DatabaseUtils.tableColumnExists;
+
+public class AddAICodeSupportedColumnToQualityGatesTable extends DdlChange {
+ private static final String QUALITY_GATE_TABLE_NAME = "quality_gates";
+ private static final String SUPPORTS_AI_CODE_COLUMN_NAME = "ai_code_supported";
+
+ public AddAICodeSupportedColumnToQualityGatesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ if (!tableColumnExists(connection, QUALITY_GATE_TABLE_NAME, SUPPORTS_AI_CODE_COLUMN_NAME)) {
+ var columnDef = BooleanColumnDef.newBooleanColumnDefBuilder()
+ .setColumnName(SUPPORTS_AI_CODE_COLUMN_NAME)
+ .setIsNullable(false)
+ .setDefaultValue(false)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), QUALITY_GATE_TABLE_NAME)
+ .addColumn(columnDef)
+ .build());
+ }
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java
index e69eae20426..1b2b94be3cc 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java
@@ -64,7 +64,9 @@ public class DbVersion108 implements DbVersion {
.add(10_8_021, "Migrate deprecated project_measures to replacement metrics", MigrateProjectMeasuresDeprecatedMetrics.class)
.add(10_8_022, "Add 'manual_severity' column in 'issues_impacts' table", AddManualSeverityColumnInIssuesImpactsTable.class)
.add(10_8_023, "Add 'ai_code_fix_enabled' column to 'projects' table", AddAICodeFixEnabledColumnToProjectsTable.class)
- .add(10_8_024, "Migrate boolean values of 'sonar.ai.suggestions.enabled' property to new enum values", MigrateAiSuggestionEnabledValues.class);
+ .add(10_8_024, "Migrate boolean values of 'sonar.ai.suggestions.enabled' property to new enum values", MigrateAiSuggestionEnabledValues.class)
+ .add(10_8_025, "Add 'ai_code_supported' column in 'quality_gates' table", AddAICodeSupportedColumnToQualityGatesTable.class)
+ ;
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTableTest.java
new file mode 100644
index 00000000000..110f1725f52
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeSupportedColumnToQualityGatesTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.v108;
+
+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.BOOLEAN;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
+
+class AddAICodeSupportedColumnToQualityGatesTableTest {
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddAICodeSupportedColumnToQualityGatesTable.class);
+
+ private final AddAICodeSupportedColumnToQualityGatesTable underTest = new AddAICodeSupportedColumnToQualityGatesTable(db.database());
+
+ @Test
+ void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
+ db.assertColumnDoesNotExist("quality_gates", "ai_code_supported");
+ underTest.execute();
+ assertColumnExists();
+ }
+
+ @Test
+ void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException {
+ underTest.execute();
+ assertColumnExists();
+ assertThatCode(underTest::execute).doesNotThrowAnyException();
+ }
+
+ private void assertColumnExists() {
+ db.assertColumnDefinition("quality_gates", "ai_code_supported", BOOLEAN, null, false);
+ }
+
+}