Skip to content

Commit

Permalink
SONAR-14367 Add inline_annotations_enabled column to project_alm_sett…
Browse files Browse the repository at this point in the history
…ings table
  • Loading branch information
jacek-poreda-sonarsource authored and sonartech committed Jan 9, 2025
1 parent baf3f9f commit cd6e5cb
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/sonar-db-dao/src/schema/schema-sq.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ CREATE TABLE "PROJECT_ALM_SETTINGS"(
"UPDATED_AT" BIGINT NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"SUMMARY_COMMENT_ENABLED" BOOLEAN,
"MONOREPO" BOOLEAN NOT NULL
"MONOREPO" BOOLEAN NOT NULL,
"INLINE_ANNOTATIONS_ENABLED" BOOLEAN
);
ALTER TABLE "PROJECT_ALM_SETTINGS" ADD CONSTRAINT "PK_PROJECT_ALM_SETTINGS" PRIMARY KEY("UUID");
CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJECT_UUID" NULLS FIRST);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.v202501;

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 AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable extends DdlChange {
private static final String PROJECT_ALM_SETTINGS_TABLE_NAME = "project_alm_settings";
private static final String INLINE_ANNOTATIONS_ENABLED_COLUMN_NAME = "inline_annotations_enabled";

public AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
try (var connection = getDatabase().getDataSource().getConnection()) {
if (!tableColumnExists(connection, PROJECT_ALM_SETTINGS_TABLE_NAME, INLINE_ANNOTATIONS_ENABLED_COLUMN_NAME)) {
var columnDef = BooleanColumnDef.newBooleanColumnDefBuilder()
.setColumnName(INLINE_ANNOTATIONS_ENABLED_COLUMN_NAME)
.setIsNullable(true)
.setDefaultValue(null)
.build();
context.execute(new AddColumnsBuilder(getDialect(), PROJECT_ALM_SETTINGS_TABLE_NAME)
.addColumn(columnDef)
.build());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void addSteps(MigrationStepRegistry registry) {
.add(2025_01_006, "Add 'detected_ai_code' column to 'projects' table", AddDetectedAICodeColumnToProjectsTable.class)
.add(2025_01_007, "Create table 'migration_logs'", CreateMigrationLogsTable.class)
.add(2025_01_008, "Log message if SAML configuration is not valid", LogMessageIfInvalidSamlSetup.class)
.add(2025_01_009, "Add 'inline_annotations_enabled' column to 'project_alm_settings' table", AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable.class)
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.v202501;

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 AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTableTest {

@RegisterExtension
public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable.class);

private final AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable underTest = new AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable(db.database());

@Test
void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
db.assertColumnDoesNotExist("project_alm_settings", "inline_annotations_enabled");
underTest.execute();
assertColumnExists();
}

@Test
void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException {
underTest.execute();
assertColumnExists();
assertThatCode(underTest::execute).doesNotThrowAnyException();
}

private void assertColumnExists() {
db.assertColumnDefinition("project_alm_settings", "inline_annotations_enabled", BOOLEAN, null, true);
}

}

0 comments on commit cd6e5cb

Please sign in to comment.