diff options
author | Travis Collins <travistx@gmail.com> | 2025-04-24 04:15:53 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2025-04-24 20:03:15 +0000 |
commit | 711305e9c047462306473d0919d849e55f928d97 (patch) | |
tree | 9dfa37e4a3e1aeba9c006fb56da4fd5319dbdf2d /server/sonar-db-migration/src | |
parent | 460e0e9ef83870614049a251db4c7b2291890ea5 (diff) | |
download | sonarqube-711305e9c047462306473d0919d849e55f928d97.tar.gz sonarqube-711305e9c047462306473d0919d849e55f928d97.zip |
SCA-300 Add change_comment column
Diffstat (limited to 'server/sonar-db-migration/src')
5 files changed, 198 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/AddCommentToScaIssuesReleasesChangesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/AddCommentToScaIssuesReleasesChangesTableIT.java new file mode 100644 index 00000000000..b1df6436185 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/AddCommentToScaIssuesReleasesChangesTableIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202503; + +import java.sql.SQLException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static java.sql.Types.VARCHAR; +import static org.sonar.db.MigrationDbTester.createForMigrationStep; + +class AddCommentToScaIssuesReleasesChangesTableIT { + private static final String TABLE_NAME = "sca_issue_rels_changes"; + private static final String COLUMN_NAME = "change_comment"; + + @RegisterExtension + public final MigrationDbTester db = createForMigrationStep(AddCommentToScaIssuesReleasesChangesTable.class); + private final DdlChange underTest = new AddCommentToScaIssuesReleasesChangesTable(db.database()); + + @Test + void execute_shouldAddColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 4000, true); + } + + @Test + void execute_shouldBeReentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 4000, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/DropChangeTypeFromScaIssuesReleasesChangesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/DropChangeTypeFromScaIssuesReleasesChangesTableIT.java new file mode 100644 index 00000000000..a16ebb131a4 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202503/DropChangeTypeFromScaIssuesReleasesChangesTableIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202503; + +import java.sql.SQLException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static java.sql.Types.VARCHAR; +import static org.sonar.db.MigrationDbTester.createForMigrationStep; + +class DropChangeTypeFromScaIssuesReleasesChangesTableIT { + private static final String TABLE_NAME = "sca_issue_rels_changes"; + private static final String COLUMN_NAME = "change_type"; + + @RegisterExtension + public final MigrationDbTester db = createForMigrationStep(DropChangeTypeFromScaIssuesReleasesChangesTable.class); + private final DdlChange underTest = new DropChangeTypeFromScaIssuesReleasesChangesTable(db.database()); + + @Test + void execute_shouldDropColumn() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + void execute_shouldBeReentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/AddCommentToScaIssuesReleasesChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/AddCommentToScaIssuesReleasesChangesTable.java new file mode 100644 index 00000000000..80231e458ab --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/AddCommentToScaIssuesReleasesChangesTable.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202503; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +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; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE; + +public class AddCommentToScaIssuesReleasesChangesTable extends DdlChange { + static final String TABLE_NAME = "sca_issue_rels_changes"; + static final String COLUMN_NAME = "change_comment"; + + public AddCommentToScaIssuesReleasesChangesTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + try (var connection = getDatabase().getDataSource().getConnection()) { + if (!tableColumnExists(connection, TABLE_NAME, COLUMN_NAME)) { + var columnDef = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName(COLUMN_NAME) + .setLimit(MAX_SIZE) + .setIsNullable(true) + .build(); + + context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME) + .addColumn(columnDef) + .build()); + } + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java index 02e00f5c160..a66a1884bce 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DbVersion202503.java @@ -61,6 +61,10 @@ public class DbVersion202503 implements DbVersion { .add(2025_03_022, "Create unique index on SCA license profile customizations table", CreateUniqueIndexOnScaLicenseProfileCustomizations.class) .add(2025_03_023, "Create unique index on SCA license profiles table", CreateUniqueIndexOnScaLicenseProfiles.class) .add(2025_03_024, "Create SCA encountered licenses table", CreateScaEncounteredLicensesTable.class) - .add(2025_03_025, "Create SCA encountered licenses unique index", CreateUniqueIndexOnScaEncounteredLicenses.class); + .add(2025_03_025, "Create SCA encountered licenses unique index", CreateUniqueIndexOnScaEncounteredLicenses.class) + .add(2025_03_026, "Add change_comment to SCA issues releases changes", AddCommentToScaIssuesReleasesChangesTable.class) + .add(2025_03_027, "Drop change_type from SCA issues releases changes", DropChangeTypeFromScaIssuesReleasesChangesTable.class) + + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DropChangeTypeFromScaIssuesReleasesChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DropChangeTypeFromScaIssuesReleasesChangesTable.java new file mode 100644 index 00000000000..602d957ecb1 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202503/DropChangeTypeFromScaIssuesReleasesChangesTable.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202503; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropColumnChange; + +public class DropChangeTypeFromScaIssuesReleasesChangesTable extends DropColumnChange { + static final String TABLE_NAME = "sca_issue_rels_changes"; + static final String COLUMN_NAME = "change_type"; + + public DropChangeTypeFromScaIssuesReleasesChangesTable(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } +} |