"project_badge_token",
"project_branches",
"project_links",
- "project_mappings",
"project_measures",
"project_qprofiles",
"project_qgates",
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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.db.mapping;
-
-import java.util.Map;
-import java.util.Objects;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.assertj.core.api.AbstractAssert;
-import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.SequenceUuidFactory;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ProjectMappingsDaoIT {
-
- private static final String EMPTY_STRING = "";
- private static final String A_KEY_TYPE = "a_key_type";
- private static final String A_KEY = "a_key";
- private static final String ANOTHER_KEY = "another_key";
- private static final long DATE = 1_600_000_000_000L;
- private static final String PROJECT_UUID = "123456789";
- private static final String OTHER_PROJECT_UUID = "987654321";
-
- private System2 system2 = mock(System2.class);
-
- @Rule
- public DbTester dbTester = DbTester.create(system2);
-
- private DbSession dbSession = dbTester.getSession();
-
- private ProjectMappingsDao underTest = new ProjectMappingsDao(system2, new SequenceUuidFactory());
-
- @Test
- public void put_throws_IAE_if_key_type_is_null() {
- expectKeyTypeNullOrEmptyIAE(() -> underTest.put(dbSession, null, A_KEY, PROJECT_UUID));
- }
-
- @Test
- public void put_throws_IAE_if_key_is_null() {
- expectKeyNullOrEmptyIAE(() -> underTest.put(dbSession, A_KEY_TYPE, null, PROJECT_UUID));
- }
-
- @Test
- public void put_throws_IAE_if_key_is_empty() {
- expectKeyNullOrEmptyIAE(() -> underTest.put(dbSession, A_KEY_TYPE, EMPTY_STRING, PROJECT_UUID));
- }
-
- @Test
- public void save_throws_IAE_if_project_uuid_is_null() {
- expectValueNullOrEmptyIAE(() -> underTest.put(dbSession, A_KEY_TYPE, A_KEY, null));
- }
-
- @Test
- public void put_throws_IAE_if_project_uuid_is_empty() {
- expectValueNullOrEmptyIAE(() -> underTest.put(dbSession, A_KEY_TYPE, A_KEY, EMPTY_STRING));
- }
-
- @Test
- public void put() {
- when(system2.now()).thenReturn(DATE);
- underTest.put(dbSession, A_KEY_TYPE, A_KEY, PROJECT_UUID);
-
- assertThatProjectMapping(A_KEY_TYPE, A_KEY)
- .hasProjectUuid(PROJECT_UUID)
- .hasCreatedAt(DATE);
- }
-
- @Test
- public void clear() {
- when(system2.now()).thenReturn(DATE);
- underTest.put(dbSession, A_KEY_TYPE, A_KEY, PROJECT_UUID);
-
- assertThatProjectMapping(A_KEY_TYPE, A_KEY)
- .hasProjectUuid(PROJECT_UUID)
- .hasCreatedAt(DATE);
-
- underTest.clear(dbSession, A_KEY_TYPE, A_KEY);
-
- assertThat(underTest.get(dbSession, A_KEY_TYPE, A_KEY)).isEmpty();
- }
-
- @Test
- public void putMultiple() {
- when(system2.now()).thenReturn(DATE);
- underTest.put(dbSession, A_KEY_TYPE, A_KEY, PROJECT_UUID);
- underTest.put(dbSession, A_KEY_TYPE, ANOTHER_KEY, OTHER_PROJECT_UUID);
-
- assertThatProjectMapping(A_KEY_TYPE, A_KEY)
- .hasProjectUuid(PROJECT_UUID)
- .hasCreatedAt(DATE);
-
- assertThatProjectMapping(A_KEY_TYPE, ANOTHER_KEY)
- .hasProjectUuid(OTHER_PROJECT_UUID)
- .hasCreatedAt(DATE);
- }
-
- @Test
- public void get_throws_IAE_when_key_type_is_null() {
- expectKeyTypeNullOrEmptyIAE(() -> underTest.get(dbSession, null, A_KEY));
- }
-
- @Test
- public void get_throws_IAE_when_key_is_null() {
- expectKeyNullOrEmptyIAE(() -> underTest.get(dbSession, A_KEY_TYPE, null));
- }
-
- @Test
- public void get_throws_IAE_when_key_is_empty() {
- expectKeyNullOrEmptyIAE(() -> underTest.get(dbSession, A_KEY_TYPE, EMPTY_STRING));
- }
-
- @Test
- public void get_returns_empty_optional_when_mapping_does_not_exist_in_DB() {
- assertThat(underTest.get(dbSession, A_KEY_TYPE, A_KEY)).isEmpty();
- }
-
- @Test
- public void get_returns_project_uuid_when_mapping_has_project_uuid_stored() {
- underTest.put(dbSession, A_KEY_TYPE, A_KEY, PROJECT_UUID);
-
- assertThat(underTest.get(dbSession, A_KEY_TYPE, A_KEY).get().getProjectUuid()).isEqualTo(PROJECT_UUID);
- }
-
- private void expectKeyTypeNullOrEmptyIAE(ThrowingCallable callback) {
- assertThatThrownBy(callback)
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("key type can't be null nor empty");
- }
-
- private void expectKeyNullOrEmptyIAE(ThrowingCallable callback) {
- assertThatThrownBy(callback)
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("key can't be null nor empty");
- }
-
- private void expectValueNullOrEmptyIAE(ThrowingCallable callback) {
- assertThatThrownBy(callback)
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("projectUuid can't be null nor empty");
- }
-
- private ProjectMappingAssert assertThatProjectMapping(String keyType, String key) {
- return new ProjectMappingAssert(dbTester, dbSession, keyType, key);
- }
-
- private static class ProjectMappingAssert extends AbstractAssert<ProjectMappingAssert, ProjectMapping> {
-
- private ProjectMappingAssert(DbTester dbTester, DbSession dbSession, String internalMappingKeyType, String internalMappingKey) {
- super(asProjectMapping(dbTester, dbSession, internalMappingKeyType, internalMappingKey), ProjectMappingAssert.class);
- }
-
- private static ProjectMapping asProjectMapping(DbTester dbTester, DbSession dbSession, String projectMappingKeyType, String projectMappingKey) {
- Map<String, Object> row = dbTester.selectFirst(
- dbSession,
- "select" +
- " project_uuid as \"projectUuid\", created_at as \"createdAt\"" +
- " from project_mappings" +
- " where key_type='"+projectMappingKeyType+"' and kee='" + projectMappingKey + "'");
- return new ProjectMapping(
- (String) row.get("projectUuid"),
- (Long) row.get("createdAt"));
- }
-
- public void doesNotExist() {
- isNull();
- }
-
-
- public ProjectMappingAssert hasProjectUuid(String expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getProjectUuid(), expected)) {
- failWithMessage("Expected Internal mapping to have column VALUE to be <%s> but was <%s>", true, actual.getProjectUuid());
- }
- return this;
- }
-
- public ProjectMappingAssert hasCreatedAt(long expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getCreatedAt(), expected)) {
- failWithMessage("Expected Internal mapping to have column CREATED_AT to be <%s> but was <%s>", expected, actual.getCreatedAt());
- }
-
- return this;
- }
-
- }
-
- private static final class ProjectMapping {
- private final String projectUuid;
- private final Long createdAt;
-
- public ProjectMapping(@Nullable String projectUuid, @Nullable Long createdAt) {
- this.projectUuid = projectUuid;
- this.createdAt = createdAt;
- }
-
- @CheckForNull
- public String getProjectUuid() {
- return projectUuid;
- }
-
- @CheckForNull
- public Long getCreatedAt() {
- return createdAt;
- }
- }
-}
assertThat(selectAllDeliveryUuids(db, dbSession)).containsOnly("D2");
}
- @Test
- public void deleteProject_deletes_project_mappings() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- dbClient.projectMappingsDao().put(dbSession, "a.key.type", "a.key", project.uuid());
- dbClient.projectMappingsDao().put(dbSession, "a.key.type", "another.key", "D2");
-
- underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
-
- assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "a.key")).isEmpty();
- assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "another.key")).isNotEmpty();
- }
-
@Test
public void deleteProject_deletes_project_alm_settings() {
ProjectDto project = db.components().insertPublicProject().getProjectDto();
public class UserDismissedMessagesDaoIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final UserDismissedMessagesDao underTest = db.getDbClient().userDismissedMessagesDao();
import org.sonar.db.event.EventDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
-import org.sonar.db.mapping.ProjectMappingsDao;
import org.sonar.db.measure.LiveMeasureDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.metric.MetricDao;
ProjectBadgeTokenDao.class,
PortfolioDao.class,
ProjectLinkDao.class,
- ProjectMappingsDao.class,
ProjectQgateAssociationDao.class,
PropertiesDao.class,
PurgeDao.class,
import org.sonar.db.event.EventDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
-import org.sonar.db.mapping.ProjectMappingsDao;
import org.sonar.db.measure.LiveMeasureDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.metric.MetricDao;
private final LiveMeasureDao liveMeasureDao;
private final WebhookDao webhookDao;
private final WebhookDeliveryDao webhookDeliveryDao;
- private final ProjectMappingsDao projectMappingsDao;
private final NewCodePeriodDao newCodePeriodDao;
private final ProjectDao projectDao;
private final PortfolioDao portfolioDao;
liveMeasureDao = getDao(map, LiveMeasureDao.class);
webhookDao = getDao(map, WebhookDao.class);
webhookDeliveryDao = getDao(map, WebhookDeliveryDao.class);
- projectMappingsDao = getDao(map, ProjectMappingsDao.class);
internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class);
newCodePeriodDao = getDao(map, NewCodePeriodDao.class);
projectDao = getDao(map, ProjectDao.class);
return webhookDeliveryDao;
}
- public ProjectMappingsDao projectMappingsDao() {
- return projectMappingsDao;
- }
-
public InternalComponentPropertiesDao internalComponentPropertiesDao() {
return internalComponentPropertiesDao;
}
import org.sonar.db.issue.IssueMapper;
import org.sonar.db.issue.NewCodeReferenceIssueDto;
import org.sonar.db.issue.PrIssueDto;
-import org.sonar.db.mapping.ProjectMappingDto;
-import org.sonar.db.mapping.ProjectMappingsMapper;
import org.sonar.db.measure.LargestBranchNclocDto;
import org.sonar.db.measure.LiveMeasureMapper;
import org.sonar.db.measure.MeasureDto;
confBuilder.loadAlias("AnalysisPropertyValuePerProject", AnalysisPropertyValuePerProject.class);
confBuilder.loadAlias("ProjectAlmKeyAndProject", ProjectAlmKeyAndProject.class);
confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrBranchAnalyzedLanguageCountByProjectDto.class);
- confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class);
confBuilder.loadAlias("ProjectLocDistribution", ProjectLocDistributionDto.class);
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
confBuilder.loadAlias("PushEvent", PushEventDto.class);
ProjectMapper.class,
ProjectBadgeTokenMapper.class,
ProjectExportMapper.class,
- ProjectMappingsMapper.class,
ProjectQgateAssociationMapper.class,
PropertiesMapper.class,
PurgeMapper.class,
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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.db.mapping;
-
-/**
- * Generic purpose way to attach data to a project. For example to store the identifier
- * of the project in a remote system (ALM).
- * The pair (keyType, key) is unique.
- * Data is automatically purged when project is deleted.
- */
-public final class ProjectMappingDto {
- private String uuid;
- private String keyType;
- private String key;
- private String projectUuid;
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- public String getKeyType() {
- return keyType;
- }
-
- public void setKeyType(String keyType) {
- this.keyType = keyType;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getProjectUuid() {
- return projectUuid;
- }
-
- public void setProjectUuid(String projectUuid) {
- this.projectUuid = projectUuid;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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.db.mapping;
-
-import java.util.Optional;
-import javax.annotation.Nullable;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.apache.commons.lang.StringUtils.isNotEmpty;
-
-public class ProjectMappingsDao implements Dao {
-
- public static final String BITBUCKETCLOUD_REPO_MAPPING = "bitbucketcloud.repo";
- private final System2 system2;
- private final UuidFactory uuidFactory;
-
- public ProjectMappingsDao(System2 system2, UuidFactory uuidFactory) {
- this.system2 = system2;
- this.uuidFactory = uuidFactory;
- }
-
- public void put(DbSession dbSession, String keyType, String key, String projectUuid) {
- checkKeyType(keyType);
- checkKey(key);
- checkArgument(isNotEmpty(projectUuid), "projectUuid can't be null nor empty");
-
- ProjectMappingsMapper mapper = getMapper(dbSession);
- mapper.deleteByKey(keyType, key);
- long now = system2.now();
- mapper.put(uuidFactory.create(), keyType, key, projectUuid, now);
- }
-
- public Optional<ProjectMappingDto> get(DbSession dbSession, String keyType, String key) {
- checkKeyType(keyType);
- checkKey(key);
-
- ProjectMappingsMapper mapper = getMapper(dbSession);
- return Optional.ofNullable(mapper.selectByKey(keyType, key));
- }
-
- public void clear(DbSession dbSession, String keyType, String key) {
- checkKeyType(keyType);
- checkKey(key);
- ProjectMappingsMapper mapper = getMapper(dbSession);
- mapper.deleteByKey(keyType, key);
- }
-
- private static void checkKeyType(@Nullable String keyType) {
- checkArgument(keyType != null && !keyType.isEmpty(), "key type can't be null nor empty");
- }
-
- private static void checkKey(@Nullable String key) {
- checkArgument(key != null && !key.isEmpty(), "key can't be null nor empty");
- }
-
- private static ProjectMappingsMapper getMapper(DbSession dbSession) {
- return dbSession.getMapper(ProjectMappingsMapper.class);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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.db.mapping;
-
-import javax.annotation.CheckForNull;
-import org.apache.ibatis.annotations.Param;
-
-public interface ProjectMappingsMapper {
-
- @CheckForNull
- ProjectMappingDto selectByKey(@Param("keyType") String keyType, @Param("key") String key);
-
- void put(@Param("uuid") String uuid, @Param("keyType") String keyType, @Param("key") String key, @Param("projectUuid") String projectUuid, @Param("createdAt") long createdAt);
-
- void deleteByKey(@Param("keyType") String keyType, @Param("key") String key);
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.db.mapping;
-
-import javax.annotation.ParametersAreNonnullByDefault;
profiler.stop();
}
- void deleteProjectMappings(String rootUuid) {
- profiler.start("deleteProjectMappings (project_mappings)");
- purgeMapper.deleteProjectMappingsByProjectUuid(rootUuid);
- session.commit();
- profiler.stop();
- }
-
void deleteApplicationProjectsByProject(String projectUuid) {
profiler.start("deleteApplicationProjectsByProject (app_projects)");
purgeMapper.deleteAppBranchProjectBranchesByProjectUuid(projectUuid);
commands.deleteWebhooks(rootUuid);
commands.deleteWebhookDeliveries(rootUuid);
commands.deleteLiveMeasures(rootUuid);
- commands.deleteProjectMappings(rootUuid);
commands.deleteProjectAlmSettings(rootUuid);
commands.deletePermissions(rootUuid);
commands.deleteNewCodePeriods(rootUuid);
void deleteWebhookDeliveriesByProjectUuid(@Param("projectUuid") String projectUuid);
- void deleteProjectMappingsByProjectUuid(@Param("projectUuid") String projectUuid);
-
void deleteAppProjectsByAppUuid(@Param("applicationUuid") String applicationUuid);
void deleteAppProjectsByProjectUuid(@Param("projectUuid") String projectUuid);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.mapping.ProjectMappingsMapper">
-
- <select id="selectByKey" parameterType="Map" resultType="ProjectMapping">
- select
- uuid as "uuid",
- key_type as "key_type",
- kee as "key",
- project_uuid as projectUuid
- from
- project_mappings
- where
- key_type = #{keyType, jdbcType=VARCHAR}
- and kee = #{key, jdbcType=VARCHAR}
- </select>
-
- <insert id="put" parameterType="Map" useGeneratedKeys="false">
- INSERT INTO project_mappings
- (
- uuid,
- key_type,
- kee,
- project_uuid,
- created_at
- )
- VALUES (
- #{uuid,jdbcType=VARCHAR},
- #{keyType,jdbcType=VARCHAR},
- #{key,jdbcType=VARCHAR},
- #{projectUuid,jdbcType=VARCHAR},
- #{createdAt,jdbcType=BIGINT}
- )
- </insert>
-
- <delete id="deleteByKey" parameterType="Map">
- delete from project_mappings
- where
- key_type=#{keyType,jdbcType=VARCHAR}
- and kee=#{key,jdbcType=VARCHAR}
- </delete>
-
-
-</mapper>
delete from webhook_deliveries where component_uuid=#{projectUuid,jdbcType=VARCHAR}
</delete>
- <delete id="deleteProjectMappingsByProjectUuid">
- delete from project_mappings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
- </delete>
-
<delete id="deleteProjectAlmSettingsByProjectUuid">
delete from project_alm_settings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
</delete>
ALTER TABLE "PROJECT_LINKS" ADD CONSTRAINT "PK_PROJECT_LINKS" PRIMARY KEY("UUID");
CREATE INDEX "PROJECT_LINKS_PROJECT" ON "PROJECT_LINKS"("PROJECT_UUID" NULLS FIRST);
-CREATE TABLE "PROJECT_MAPPINGS"(
- "UUID" CHARACTER VARYING(40) NOT NULL,
- "KEY_TYPE" CHARACTER VARYING(200) NOT NULL,
- "KEE" CHARACTER VARYING(4000) NOT NULL,
- "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
- "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROJECT_MAPPINGS" ADD CONSTRAINT "PK_PROJECT_MAPPINGS" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "KEY_TYPE_KEE" ON "PROJECT_MAPPINGS"("KEY_TYPE" NULLS FIRST, "KEE" NULLS FIRST);
-CREATE INDEX "PROJECT_UUID" ON "PROJECT_MAPPINGS"("PROJECT_UUID" NULLS FIRST);
-
CREATE TABLE "PROJECT_MEASURES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"VALUE" DOUBLE PRECISION,
.add(10_2_009, "Drop index 'ce_queue_main_component' in 'ce_queue' table", DropIndexMainComponentUuidInCeQueue.class)
.add(10_2_010, "Rename 'main_component_uuid' in 'ce_queue' table to 'entity_uuid'", RenameMainComponentUuidInCeQueue.class)
.add(10_2_011, "Create index 'ce_queue_entity_uuid' in 'ce_queue' table", CreateIndexEntityUuidInCeQueue.class)
+ .add(10_2_012, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid'", RenameComponentUuidInUserRoles.class)
+ .add(10_2_013, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class)
+ .add(10_2_014, "Drop 'project_mappings' table", DropTableProjectMappings.class)
;
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+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.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropTableProjectMappings extends DdlChange {
+
+ private static final String TABLE_NAME = "project_mappings";
+
+ public DropTableProjectMappings(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection c = getDatabase().getDataSource().getConnection()) {
+ if (DatabaseUtils.tableExists(TABLE_NAME, c)) {
+ context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build());
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropTableProjectMappingsTest {
+ public static final String TABLE_NAME = "project_mappings";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropTableProjectMappingsTest.class, "schema.sql");
+
+ private final DropTableProjectMappings underTest = new DropTableProjectMappings(db.database());
+
+ @Test
+ public void execute_shouldDropTable() throws SQLException {
+ db.assertTableExists(TABLE_NAME);
+ underTest.execute();
+ db.assertTableDoesNotExist(TABLE_NAME);
+ }
+
+ @Test
+ public void execute_shouldSupportReentrantMigrationExecution() throws SQLException {
+ db.assertTableExists(TABLE_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertTableDoesNotExist(TABLE_NAME);
+ }
+}
--- /dev/null
+CREATE TABLE "PROJECT_MAPPINGS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "KEY_TYPE" CHARACTER VARYING(200) NOT NULL,
+ "KEE" CHARACTER VARYING(4000) NOT NULL,
+ "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROJECT_MAPPINGS" ADD CONSTRAINT "PK_PROJECT_MAPPINGS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "KEY_TYPE_KEE" ON "PROJECT_MAPPINGS"("KEY_TYPE" NULLS FIRST, "KEE" NULLS FIRST);
+CREATE INDEX "PROJECT_UUID" ON "PROJECT_MAPPINGS"("PROJECT_UUID" NULLS FIRST);