CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_REPOSITORY_KEY" NULLS FIRST, "OLD_RULE_KEY" NULLS FIRST);
CREATE INDEX "RULE_UUID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_UUID" NULLS FIRST);
+CREATE TABLE "DEVOPS_PERMS_MAPPING"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "DEVOPS_PLATFORM_ROLE" CHARACTER VARYING(100) NOT NULL,
+ "SONARQUBE_PERMISSION" CHARACTER VARYING(64) NOT NULL,
+ "DEVOPS_PLATFORM" CHARACTER VARYING(40) DEFAULT 'github' NOT NULL
+);
+ALTER TABLE "DEVOPS_PERMS_MAPPING" ADD CONSTRAINT "PK_DEVOPS_PERMS_MAPPING" PRIMARY KEY("UUID");
+CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_DEVOPS_PERMS_MAPPING" ON "DEVOPS_PERMS_MAPPING"("DEVOPS_PLATFORM" NULLS FIRST, "DEVOPS_PLATFORM_ROLE" NULLS FIRST, "SONARQUBE_PERMISSION" NULLS FIRST);
+
CREATE TABLE "DUPLICATIONS_INDEX"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"ANALYSIS_UUID" CHARACTER VARYING(50) NOT NULL,
);
ALTER TABLE "GITHUB_ORGS_GROUPS" ADD CONSTRAINT "PK_GITHUB_ORGS_GROUPS" PRIMARY KEY("GROUP_UUID");
-CREATE TABLE "GITHUB_PERMS_MAPPING"(
- "UUID" CHARACTER VARYING(40) NOT NULL,
- "GITHUB_ROLE" CHARACTER VARYING(100) NOT NULL,
- "SONARQUBE_PERMISSION" CHARACTER VARYING(64) NOT NULL
-);
-ALTER TABLE "GITHUB_PERMS_MAPPING" ADD CONSTRAINT "PK_GITHUB_PERMS_MAPPING" PRIMARY KEY("UUID");
-CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_GITHUB_PERM_MAPPINGS" ON "GITHUB_PERMS_MAPPING"("GITHUB_ROLE" NULLS FIRST, "SONARQUBE_PERMISSION" NULLS FIRST);
-
CREATE TABLE "GROUP_ROLES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"ROLE" CHARACTER VARYING(64) NOT NULL,
--- /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.v107;
+
+import java.sql.SQLException;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.db.MigrationDbTester;
+
+import static java.sql.Types.VARCHAR;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.sonar.server.platform.db.migration.version.v107.AddDevopsPlatformColumnInDevopsPermsMapping.DEVOPS_PLATFORM_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.AddDevopsPlatformColumnInDevopsPermsMapping.DEFAULT_COLUMN_VALUE;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+class AddDevopsPlatformColumnInDevopsPermsMappingIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddDevopsPlatformColumnInDevopsPermsMapping.class);
+
+ private final AddDevopsPlatformColumnInDevopsPermsMapping underTest = new AddDevopsPlatformColumnInDevopsPermsMapping(db.database());
+
+ @Test
+ void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
+ db.assertColumnDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, DEVOPS_PLATFORM_COLUMN_NAME);
+ underTest.execute();
+ assertColumnExists();
+ }
+
+ @Test
+ void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException {
+ underTest.execute();
+ assertColumnExists();
+ underTest.execute();
+ }
+
+ @Test
+ void execute_whenDataAlreadyExists_shouldCreateColumnWithDefaultValue() throws SQLException {
+ db.executeInsert(DEVOPS_PERMS_MAPPING_TABLE_NAME, "uuid", "UUID", "devops_platform_role", "uniqAdmin", "sonarqube_permission", "uniqPermission");
+ underTest.execute();
+ assertDevopsPlatformColumnSetToDefault();
+ assertColumnExists();
+ }
+
+ private void assertDevopsPlatformColumnSetToDefault() {
+ Map<String, Object> selectResult = db.selectFirst("select devops_platform from devops_perms_mapping where uuid = 'UUID'");
+ assertThat(selectResult.get("devops_platform")).isEqualTo(DEFAULT_COLUMN_VALUE);
+ }
+
+ private void assertColumnExists() {
+ db.assertColumnDefinition(DEVOPS_PERMS_MAPPING_TABLE_NAME, DEVOPS_PLATFORM_COLUMN_NAME, VARCHAR, 40, false);
+ }
+
+}
--- /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.v107;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.db.MigrationDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v107.CreatePrimaryKeyConstraintOnDevopsPermsMappingTable.UUID_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+class CreatePrimaryKeyConstraintOnDevopsPermsMappingTableIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreatePrimaryKeyConstraintOnDevopsPermsMappingTable.class);
+ private final CreatePrimaryKeyConstraintOnDevopsPermsMappingTable underTest = new CreatePrimaryKeyConstraintOnDevopsPermsMappingTable(db.database());
+ private static final String PK_DEVOPS_PERMS_MAPPING = "pk_devops_perms_mapping";
+
+ @Test
+ void execute_whenPrimaryKeyDoesNotExist_shouldCreateIt() throws Exception {
+ db.assertNoPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ underTest.execute();
+ db.assertPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME, PK_DEVOPS_PERMS_MAPPING, UUID_COLUMN_NAME);
+ }
+
+ @Test
+ void execute_whenPrimaryKeyAlreadyExists_shouldDoNothing() throws Exception {
+ underTest.execute();
+ underTest.execute();
+ db.assertPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME, PK_DEVOPS_PERMS_MAPPING, UUID_COLUMN_NAME);
+ }
+
+}
\ No newline at end of file
--- /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.v107;
+
+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 org.sonar.server.platform.db.migration.version.v107.AddDevopsPlatformColumnInDevopsPermsMapping.DEVOPS_PLATFORM_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.CreateUniqueIndexOnDevopsPermsMappingTable.DEVOPS_ROLE_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.CreateUniqueIndexOnDevopsPermsMappingTable.INDEX_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.CreateUniqueIndexOnDevopsPermsMappingTable.SONARQUBE_PERMISSION_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+class CreateUniqueIndexOnDevopsPermsMappingTableIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexOnDevopsPermsMappingTable.class);
+ private final DdlChange underTest = new CreateUniqueIndexOnDevopsPermsMappingTable(db.database());
+
+ @Test
+ void execute_givenIndexDoNotExist_shouldCreateIndex() throws Exception {
+ db.assertIndexDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, INDEX_NAME);
+ underTest.execute();
+ db.assertUniqueIndex(DEVOPS_PERMS_MAPPING_TABLE_NAME, INDEX_NAME, DEVOPS_ROLE_COLUMN_NAME, SONARQUBE_PERMISSION_COLUMN_NAME, DEVOPS_PLATFORM_COLUMN_NAME);
+ }
+
+ @Test
+ void execute_givenIndexAlreadyExist_shouldBeReentrant() throws SQLException {
+ underTest.execute();
+ underTest.execute();
+ db.assertUniqueIndex(DEVOPS_PERMS_MAPPING_TABLE_NAME, INDEX_NAME, DEVOPS_ROLE_COLUMN_NAME, SONARQUBE_PERMISSION_COLUMN_NAME, DEVOPS_PLATFORM_COLUMN_NAME);
+ }
+
+}
\ No newline at end of file
--- /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.v107;
+
+import java.sql.SQLException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.db.MigrationDbTester;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.GITHUB_PERMS_MAPPING_TABLE_NAME;
+
+class DropGithubPermsMappingTableIfDevopsPermsMappingTableExistsIT {
+
+ @RegisterExtension
+ public static MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropGithubPermsMappingTableIfDevopsPermsMappingTableExists.class);
+
+ private final DropGithubPermsMappingTableIfDevopsPermsMappingTableExists underTest = new DropGithubPermsMappingTableIfDevopsPermsMappingTableExists(db.database());
+
+ @Test
+ void execute_givenGithubDevopsPermsMappingTableExistsAndDevopsPermsMappingTableDoesNotExist_doNothing() throws SQLException {
+ db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+
+ underTest.execute();
+
+ db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+
+ @Test
+ void execute_givenDevopsPermsMappingTableExistsAndGithubPermsMappingTableDoNotExist_doNothing() throws SQLException {
+ db.executeDdl("CREATE TABLE " + DEVOPS_PERMS_MAPPING_TABLE_NAME + " (id INT PRIMARY KEY)");
+ db.executeDdl("DROP TABLE " + GITHUB_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+
+ underTest.execute();
+
+ db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ }
+
+ @Test
+ void execute_givenDevopsPermsMappingTableExistsAndGithubPermsMappingTableExist_dropGithubPermsMappingTable() throws SQLException {
+ db.executeDdl("CREATE TABLE " + DEVOPS_PERMS_MAPPING_TABLE_NAME + " (id INT PRIMARY KEY)");
+ db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
+
+ underTest.execute();
+
+ db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ }
+
+ @Test
+ void execute_givenDevopsPermsMappingTableDoesNotExistsAndGithubPermsMappingTableDoesNotExist_doNothing() throws SQLException {
+ db.executeDdl("DROP TABLE " + GITHUB_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+
+ underTest.execute();
+
+ db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ }
+
+}
\ No newline at end of file
--- /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.v107;
+
+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 org.sonar.server.platform.db.migration.version.v107.DropIndexUniqGithubPermsMappingInDevopsPermsMappingTable.UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+class DropIndexUniqGithubPermsMappingInDevopsPermsMappingTableIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexUniqGithubPermsMappingInDevopsPermsMappingTable.class);
+ private final DdlChange underTest = new DropIndexUniqGithubPermsMappingInDevopsPermsMappingTable(db.database());
+
+ @Test
+ void execute_givenIndexExists_dropsIndex() throws Exception {
+ db.assertUniqueIndex(DEVOPS_PERMS_MAPPING_TABLE_NAME, UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME, "devops_platform_role", "sonarqube_permission");
+ underTest.execute();
+ db.assertIndexDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME);
+ }
+
+ @Test
+ void execute_is_reentrant() throws Exception {
+ db.assertUniqueIndex(DEVOPS_PERMS_MAPPING_TABLE_NAME, UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME, "devops_platform_role", "sonarqube_permission");
+ underTest.execute();
+ underTest.execute();
+ db.assertIndexDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME);
+ }
+
+}
\ No newline at end of file
--- /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.v107;
+
+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.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
+
+import static org.sonar.server.platform.db.migration.version.v107.DropPrimaryKeyOnDevopsPermsMappingTable.CONSTRAINT_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.DropPrimaryKeyOnDevopsPermsMappingTable.UUID_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+class DropPrimaryKeyOnDevopsPermsMappingTableIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropPrimaryKeyOnDevopsPermsMappingTable.class);
+
+ private final DbPrimaryKeyConstraintFinder dbPrimaryKeyConstraintFinder = new DbPrimaryKeyConstraintFinder(db.database());
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), dbPrimaryKeyConstraintFinder);
+ private final DropPrimaryKeyOnDevopsPermsMappingTable underTest = new DropPrimaryKeyOnDevopsPermsMappingTable(db.database(), dropPrimaryKeySqlGenerator, dbPrimaryKeyConstraintFinder);
+
+ @Test
+ void execute_shouldRemoveExistingPrimaryKey() throws Exception {
+ db.assertPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME, CONSTRAINT_NAME, UUID_COLUMN_NAME);
+ underTest.execute();
+ db.assertNoPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+
+ @Test
+ void execute_when_reentrant_shouldRemoveExistingPrimaryKey() throws Exception {
+ db.assertPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME, CONSTRAINT_NAME, UUID_COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertNoPrimaryKey(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+
+}
\ No newline at end of file
--- /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.v107;
+
+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.RenameTableChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.GITHUB_PERMS_MAPPING_TABLE_NAME;
+
+class RenameGithubPermsMappingTableIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameGithubPermsMappingTable.class);
+ private final RenameTableChange underTest = new RenameGithubPermsMappingTable(db.database());
+
+ @Test
+ void migration_shouldUpdateTableName() throws SQLException {
+ db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ underTest.execute();
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+
+ @Test
+ void migration_is_reentrant() throws SQLException {
+ db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ underTest.execute();
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ underTest.execute();
+ db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
+ db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+}
--- /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.v107;
+
+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.VARCHAR;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubRoleInDevopsPermsMapping.OLD_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubRoleInDevopsPermsMapping.NEW_COLUMN_NAME;
+
+class RenameGithubRoleInDevopsPermsMappingIT {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameGithubRoleInDevopsPermsMapping.class);
+
+ private final RenameGithubRoleInDevopsPermsMapping underTest = new RenameGithubRoleInDevopsPermsMapping(db.database());
+
+ @Test
+ void execute_renameColumn() throws SQLException {
+ db.assertColumnDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, NEW_COLUMN_NAME);
+ db.assertColumnDefinition(DEVOPS_PERMS_MAPPING_TABLE_NAME, OLD_COLUMN_NAME, VARCHAR, 100, false);
+ underTest.execute();
+ db.assertColumnDefinition(DEVOPS_PERMS_MAPPING_TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 100, false);
+ db.assertColumnDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, OLD_COLUMN_NAME);
+ }
+
+ @Test
+ void execute_whenRunTwice_isReentrant() throws SQLException {
+ db.assertColumnDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDefinition(DEVOPS_PERMS_MAPPING_TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 100, false);
+ }
+
+}
--- /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.step;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.RenameTableBuilder;
+
+public abstract class RenameTableChange extends DdlChange {
+
+ protected final String tableName;
+ protected final String newTableName;
+
+ protected RenameTableChange(Database db, String oldTableName, String newTableName) {
+ super(db);
+ this.tableName = oldTableName;
+ this.newTableName = newTableName;
+ }
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (tableExists()) {
+ renameTable(context);
+ }
+ }
+
+ private boolean tableExists() throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.tableExists(tableName, connection);
+ }
+ }
+
+ private void renameTable(Context context) {
+ RenameTableBuilder renameTableBuilder = new RenameTableBuilder(getDialect());
+ renameTableBuilder.setName(tableName);
+ renameTableBuilder.setNewName(newTableName);
+ renameTableBuilder.setAutoGeneratedId(false);
+ context.execute(renameTableBuilder.build());
+ }
+}
--- /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.v107;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.ColumnDef;
+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.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+public class AddDevopsPlatformColumnInDevopsPermsMapping extends DdlChange {
+
+ static final String DEVOPS_PLATFORM_COLUMN_NAME = "devops_platform";
+ @VisibleForTesting
+ static final String DEFAULT_COLUMN_VALUE = "github";
+
+ public AddDevopsPlatformColumnInDevopsPermsMapping(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ if (!DatabaseUtils.tableColumnExists(connection, DEVOPS_PERMS_MAPPING_TABLE_NAME, DEVOPS_PLATFORM_COLUMN_NAME)) {
+ ColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
+ .setColumnName(DEVOPS_PLATFORM_COLUMN_NAME)
+ .setLimit(40)
+ .setIsNullable(false)
+ .setDefaultValue(DEFAULT_COLUMN_VALUE)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), DEVOPS_PERMS_MAPPING_TABLE_NAME)
+ .addColumn(columnDef)
+ .build());
+ }
+ }
+ }
+}
--- /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.v107;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddPrimaryKeyBuilder;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+public class CreatePrimaryKeyConstraintOnDevopsPermsMappingTable extends DdlChange {
+
+ @VisibleForTesting
+ static final String UUID_COLUMN_NAME = "uuid";
+
+ public CreatePrimaryKeyConstraintOnDevopsPermsMappingTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ createPrimaryKey(context);
+ }
+
+ private void createPrimaryKey(Context context) throws SQLException {
+ boolean pkExists = new DbPrimaryKeyConstraintFinder(getDatabase()).findConstraintName(DEVOPS_PERMS_MAPPING_TABLE_NAME).isPresent();
+ if (!pkExists) {
+ context.execute(new AddPrimaryKeyBuilder(DEVOPS_PERMS_MAPPING_TABLE_NAME, UUID_COLUMN_NAME).build());
+ }
+ }
+}
--- /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.v107;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.AddDevopsPlatformColumnInDevopsPermsMapping.DEVOPS_PLATFORM_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+public class CreateUniqueIndexOnDevopsPermsMappingTable extends DdlChange {
+
+ @VisibleForTesting
+ static final String DEVOPS_ROLE_COLUMN_NAME = "devops_platform_role";
+ @VisibleForTesting
+ static final String SONARQUBE_PERMISSION_COLUMN_NAME = "sonarqube_permission";
+ @VisibleForTesting
+ static final String INDEX_NAME = "uniq_devops_perms_mapping";
+
+ public CreateUniqueIndexOnDevopsPermsMappingTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ createUserUuidUniqueIndex(context, connection);
+ }
+ }
+
+ private void createUserUuidUniqueIndex(DdlChange.Context context, Connection connection) {
+ if (!DatabaseUtils.indexExistsIgnoreCase(DEVOPS_PERMS_MAPPING_TABLE_NAME, INDEX_NAME, connection)) {
+ context.execute(new CreateIndexBuilder(getDialect())
+ .setTable(DEVOPS_PERMS_MAPPING_TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn(DEVOPS_PLATFORM_COLUMN_NAME, false)
+ .addColumn(DEVOPS_ROLE_COLUMN_NAME, false)
+ .addColumn(SONARQUBE_PERMISSION_COLUMN_NAME, false)
+ .setUnique(true)
+ .build());
+ }
+ }
+
+}
registry
.add(10_7_000, "Create 'telemetry_metrics_sent' table", CreateTelemetryMetricsSentTable.class)
.add(10_7_001, "sonar.auth.gitlab.userConsentForPermissionProvisioningRequired", AddUserConsentRequiredIfGitlabAutoProvisioningEnabled.class)
- .add(10_7_002, "Migrate SMTP configuration into internal_properties", MigrateSmtpConfiguration.class);
+ .add(10_7_002, "Migrate SMTP configuration into internal_properties", MigrateSmtpConfiguration.class)
+ .add(10_7_003, "Drop 'github_perms_mapping' table if exists and 'devops_perms_mapping' table exists", DropGithubPermsMappingTableIfDevopsPermsMappingTableExists.class)
+ .add(10_7_004, "Rename 'github_perms_mapping' table to 'devops_perms_mapping'", RenameGithubPermsMappingTable.class)
+ .add(10_7_005, "Rename 'github_role' column to 'devops_platform_role' in devops_perms_mapping", RenameGithubRoleInDevopsPermsMapping.class)
+ .add(10_7_006, "Add 'devops_platform' column to 'devops_perms_mapping' table", AddDevopsPlatformColumnInDevopsPermsMapping.class)
+ .add(10_7_007, "Drop constraint on 'uuid' for 'devops_perms_mapping' table", DropPrimaryKeyOnDevopsPermsMappingTable.class)
+ .add(10_7_008, "Create primary key on 'devops_perms_mapping.uuid'", CreatePrimaryKeyConstraintOnDevopsPermsMappingTable.class)
+ .add(10_7_009, "Drop index 'uniq_github_perm_mappings' in the 'devops_perms_mapping' table", DropIndexUniqGithubPermsMappingInDevopsPermsMappingTable.class)
+ .add(10_7_010, "Create uniq index on 'devops_perms_mapping' table for columns 'devops_platform_role', 'sonarqube_permission' and 'devops_platform'",
+ CreateUniqueIndexOnDevopsPermsMappingTable.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.v107;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.GITHUB_PERMS_MAPPING_TABLE_NAME;
+
+/**
+ * Migration should be reentrant.
+ * If migration is rerun from version 103, a new table github_perms_mapping will be created while the table devops_perms_mapping will exist,
+ * the rename from github_perms_mapping to devops_perms_mapping will fail and we will be in an inconstant state with the two tables.
+ * To avoid this state, we need to drop the table github_perms_mapping if the table devops_perms_mapping exists.
+ */
+public class DropGithubPermsMappingTableIfDevopsPermsMappingTableExists extends DdlChange {
+
+ public DropGithubPermsMappingTableIfDevopsPermsMappingTableExists(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ boolean devopsPermsMappingTableExists = DatabaseUtils.tableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME, connection);
+ boolean githubPermsMappingTableExists = DatabaseUtils.tableExists(GITHUB_PERMS_MAPPING_TABLE_NAME, connection);
+ if (devopsPermsMappingTableExists && githubPermsMappingTableExists) {
+ context.execute(new DropTableBuilder(getDialect(), GITHUB_PERMS_MAPPING_TABLE_NAME).build());
+ }
+ }
+ }
+
+}
--- /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.v107;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropIndexChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+public class DropIndexUniqGithubPermsMappingInDevopsPermsMappingTable extends DropIndexChange {
+
+ @VisibleForTesting
+ static final String UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME = "uniq_github_perm_mappings";
+
+ public DropIndexUniqGithubPermsMappingInDevopsPermsMappingTable(Database db) {
+ super(db, UNIQ_GITHUB_PERM_MAPPINGS_INDEX_NAME, DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+}
--- /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.v107;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Optional;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DbPrimaryKeyConstraintFinder;
+import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+public class DropPrimaryKeyOnDevopsPermsMappingTable extends DdlChange {
+
+ @VisibleForTesting
+ static final String UUID_COLUMN_NAME = "uuid";
+ @VisibleForTesting
+ static final String CONSTRAINT_NAME = "pk_github_perms_mapping";
+
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+ private final DbPrimaryKeyConstraintFinder dbConstraintFinder;
+
+ public DropPrimaryKeyOnDevopsPermsMappingTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator, DbPrimaryKeyConstraintFinder dbConstraintFinder) {
+ super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+ this.dbConstraintFinder = dbConstraintFinder;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ Optional<String> constraintName = dbConstraintFinder.findConstraintName(DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ if (constraintName.isPresent() && constraintName.get().equalsIgnoreCase(CONSTRAINT_NAME)) {
+ List<String> statements = dropPrimaryKeySqlGenerator.generate(DEVOPS_PERMS_MAPPING_TABLE_NAME, UUID_COLUMN_NAME, false);
+ context.execute(statements);
+ }
+ }
+
+}
--- /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.v107;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameTableChange;
+
+public class RenameGithubPermsMappingTable extends RenameTableChange {
+
+ static final String DEVOPS_PERMS_MAPPING_TABLE_NAME = "devops_perms_mapping";
+
+ static final String GITHUB_PERMS_MAPPING_TABLE_NAME = "github_perms_mapping";
+
+ protected RenameGithubPermsMappingTable(Database db) {
+ super(db, GITHUB_PERMS_MAPPING_TABLE_NAME, DEVOPS_PERMS_MAPPING_TABLE_NAME);
+ }
+}
--- /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.v107;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
+
+public class RenameGithubRoleInDevopsPermsMapping extends RenameVarcharColumnChange {
+
+ @VisibleForTesting
+ static final String OLD_COLUMN_NAME = "github_role";
+ @VisibleForTesting
+ static final String NEW_COLUMN_NAME = "devops_platform_role";
+
+ public RenameGithubRoleInDevopsPermsMapping(Database db) {
+ super(db, DEVOPS_PERMS_MAPPING_TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+ }
+}