-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-14367 Add inline_annotations_enabled column to project_alm_sett…
…ings table
- Loading branch information
1 parent
baf3f9f
commit cd6e5cb
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...migration/version/v202501/AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ation/version/v202501/AddInlineAnnotationsEnabledColumnToProjectAlmSettingsTableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |