"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);
--- /dev/null
+/*
+ * 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());
+ }
+ }
+ }
+}
.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);
}
}
--- /dev/null
+/*
+ * 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);
+ }
+
+}