]> source.dussan.org Git - sonarqube.git/commitdiff
CODEFIX-177 Add 'ai_code_fix_enabled' column to the 'projects' table
authorSerhat Yenican <serhat.yenican@sonarsource.com>
Wed, 6 Nov 2024 06:44:15 +0000 (07:44 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 19 Nov 2024 20:02:53 +0000 (20:02 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeFixEnabledColumnToProjectsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeFixEnabledColumnToProjectsTableTest.java [new file with mode: 0644]

index b6a46b9bc40c96742cbdc9ad19920b85da4ea9c2..34cfb933d2230b294cf7411938671b80f1dc6081 100644 (file)
@@ -799,7 +799,8 @@ CREATE TABLE "PROJECTS"(
     "UPDATED_AT" BIGINT NOT NULL,
     "NCLOC" BIGINT,
     "CREATION_METHOD" CHARACTER VARYING(50) NOT NULL,
-    "AI_CODE_ASSURANCE" BOOLEAN DEFAULT FALSE NOT NULL
+    "AI_CODE_ASSURANCE" BOOLEAN DEFAULT FALSE NOT NULL,
+    "AI_CODE_FIX_ENABLED" BOOLEAN DEFAULT FALSE NOT NULL
 );
 ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID");
 CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeFixEnabledColumnToProjectsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeFixEnabledColumnToProjectsTable.java
new file mode 100644 (file)
index 0000000..f5d0e6e
--- /dev/null
@@ -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 AddAICodeFixEnabledColumnToProjectsTable extends DdlChange {
+  static final String PROJECTS_TABLE_NAME = "projects";
+  static final String AI_CODE_FIX_ENABLED_COLUMN_NAME = "ai_code_fix_enabled";
+
+  public AddAICodeFixEnabledColumnToProjectsTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    try (var connection = getDatabase().getDataSource().getConnection()) {
+      if (!tableColumnExists(connection, PROJECTS_TABLE_NAME, AI_CODE_FIX_ENABLED_COLUMN_NAME)) {
+        var columnDef = BooleanColumnDef.newBooleanColumnDefBuilder()
+          .setColumnName(AI_CODE_FIX_ENABLED_COLUMN_NAME)
+          .setIsNullable(false)
+          .setDefaultValue(false)
+          .build();
+        context.execute(new AddColumnsBuilder(getDialect(), PROJECTS_TABLE_NAME)
+          .addColumn(columnDef)
+          .build());
+      }
+    }
+  }
+}
index 2c493a67fc7b0f1f46b24e6859db2216ca23f2be..169a59e5fc273e92a684e587ad604f5f99c974c2 100644 (file)
@@ -62,7 +62,8 @@ public class DbVersion108 implements DbVersion {
       .add(10_8_019, "Delete Software Quality ratings from project_measures", DeleteSoftwareQualityRatingFromProjectMeasures.class)
       .add(10_8_020, "Create new software quality metrics", CreateNewSoftwareQualityMetrics.class)
       .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_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);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeFixEnabledColumnToProjectsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v108/AddAICodeFixEnabledColumnToProjectsTableTest.java
new file mode 100644 (file)
index 0000000..7fd5c36
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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;
+import static org.sonar.server.platform.db.migration.version.v108.AddAICodeFixEnabledColumnToProjectsTable.AI_CODE_FIX_ENABLED_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v108.AddAICodeFixEnabledColumnToProjectsTable.PROJECTS_TABLE_NAME;
+
+class AddAICodeFixEnabledColumnToProjectsTableTest {
+
+  @RegisterExtension
+  public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddImpactsColumnInActiveRulesTable.class);
+
+  private final AddAICodeFixEnabledColumnToProjectsTable underTest = new AddAICodeFixEnabledColumnToProjectsTable(db.database());
+
+  @Test
+  void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
+    db.assertColumnDoesNotExist(PROJECTS_TABLE_NAME, AI_CODE_FIX_ENABLED_COLUMN_NAME);
+    underTest.execute();
+    assertColumnExists();
+  }
+
+  @Test
+  void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException {
+    underTest.execute();
+    assertColumnExists();
+    assertThatCode(underTest::execute).doesNotThrowAnyException();
+  }
+
+  private void assertColumnExists() {
+    db.assertColumnDefinition(PROJECTS_TABLE_NAME, AI_CODE_FIX_ENABLED_COLUMN_NAME, BOOLEAN, null, false);
+  }
+
+}