]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19556 updated integration tests in UserDismissedMessagesDaoIT
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Thu, 15 Jun 2023 11:00:12 +0000 (13:00 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 20 Jun 2023 13:10:19 +0000 (13:10 +0000)
21 files changed:
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
server/sonar-db-dao/src/it/java/org/sonar/db/mapping/ProjectMappingsDaoIT.java [deleted file]
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/user/UserDismissedMessagesDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingDto.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingsDao.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingsMapper.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/mapping/package-info.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/mapping/ProjectMappingsMapper.xml [deleted file]
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappings.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest/schema.sql [new file with mode: 0644]

index 013ef03f9ecda33bc34ecd211ec50e4bcfd8f4e7..896dd650288ad91f40ec8515686019f856cc53d9 100644 (file)
@@ -79,7 +79,6 @@ public final class SqTables {
     "project_badge_token",
     "project_branches",
     "project_links",
-    "project_mappings",
     "project_measures",
     "project_qprofiles",
     "project_qgates",
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/mapping/ProjectMappingsDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/mapping/ProjectMappingsDaoIT.java
deleted file mode 100644 (file)
index 2e00f7b..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * 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;
-    }
-  }
-}
index 631e5af3e1edb2d41fde9460d6b9179fb6a5c5a4..36562a4257003591a176ba42de173ae5e4a20202 100644 (file)
@@ -1454,18 +1454,6 @@ public class PurgeDaoIT {
     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();
index 1746aa2caceaa23af310691e12560cc468ad0893..075d0dfe2ea0e3a66fe2563a123491544bec5715 100644 (file)
@@ -36,7 +36,7 @@ import static org.sonar.db.ce.CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRAD
 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();
 
index aeb4c6ed446362eba75ebbb9c6b1428e925809db..d350c97108f7cb321734191517aef3988af76f48 100644 (file)
@@ -45,7 +45,6 @@ import org.sonar.db.event.EventComponentChangeDao;
 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;
@@ -149,7 +148,6 @@ public class DaoModule extends Module {
     ProjectBadgeTokenDao.class,
     PortfolioDao.class,
     ProjectLinkDao.class,
-    ProjectMappingsDao.class,
     ProjectQgateAssociationDao.class,
     PropertiesDao.class,
     PurgeDao.class,
index 7acf9c8ad5b68b9367caf702765c84c1f3014465..f1b9fa30b15ac1cf545e34b56518adc95e8b40d0 100644 (file)
@@ -45,7 +45,6 @@ import org.sonar.db.event.EventComponentChangeDao;
 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;
@@ -169,7 +168,6 @@ public class DbClient {
   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;
@@ -257,7 +255,6 @@ public class DbClient {
     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);
@@ -553,10 +550,6 @@ public class DbClient {
     return webhookDeliveryDao;
   }
 
-  public ProjectMappingsDao projectMappingsDao() {
-    return projectMappingsDao;
-  }
-
   public InternalComponentPropertiesDao internalComponentPropertiesDao() {
     return internalComponentPropertiesDao;
   }
index 88c2322862a7e02d3713ecf54d096e4ce636b841..16752dbcb0a502dda106518352a4fad794b663d1 100644 (file)
@@ -76,8 +76,6 @@ import org.sonar.db.issue.IssueDto;
 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;
@@ -231,7 +229,6 @@ public class MyBatis {
     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);
@@ -301,7 +298,6 @@ public class MyBatis {
       ProjectMapper.class,
       ProjectBadgeTokenMapper.class,
       ProjectExportMapper.class,
-      ProjectMappingsMapper.class,
       ProjectQgateAssociationMapper.class,
       PropertiesMapper.class,
       PurgeMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingDto.java
deleted file mode 100644 (file)
index 24606c4..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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;
-  }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingsDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingsDao.java
deleted file mode 100644 (file)
index 14dae4a..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingsMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/ProjectMappingsMapper.java
deleted file mode 100644 (file)
index b04bf1f..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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);
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/mapping/package-info.java
deleted file mode 100644 (file)
index 6235e18..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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;
index 2bd50fd0d8e57870d8360d9b46e4c800f1af70f5..9364e72325b2b9d5bf092a075f5eac6bf8002ccd 100644 (file)
@@ -410,13 +410,6 @@ class PurgeCommands {
     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);
index e82d08d5885f7a07ac73352b1f03ee141057713a..7f00a5af85cd0ac78eea7acfc7196c7c9facaea1 100644 (file)
@@ -241,7 +241,6 @@ public class PurgeDao implements Dao {
     commands.deleteWebhooks(rootUuid);
     commands.deleteWebhookDeliveries(rootUuid);
     commands.deleteLiveMeasures(rootUuid);
-    commands.deleteProjectMappings(rootUuid);
     commands.deleteProjectAlmSettings(rootUuid);
     commands.deletePermissions(rootUuid);
     commands.deleteNewCodePeriods(rootUuid);
index 37d18192b924595386a12931d50952dc61615f0a..d50cf87a01b1fe353c1158f51ba3af1d5f4d2d0d 100644 (file)
@@ -143,8 +143,6 @@ public interface PurgeMapper {
 
   void deleteWebhookDeliveriesByProjectUuid(@Param("projectUuid") String projectUuid);
 
-  void deleteProjectMappingsByProjectUuid(@Param("projectUuid") String projectUuid);
-
   void deleteAppProjectsByAppUuid(@Param("applicationUuid") String applicationUuid);
 
   void deleteAppProjectsByProjectUuid(@Param("projectUuid") String projectUuid);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/mapping/ProjectMappingsMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/mapping/ProjectMappingsMapper.xml
deleted file mode 100644 (file)
index 551eda2..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?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>
index 7e1abf38c5a036c744ba0b7ac35d25284d4ee1f1..03a38b3e3f51b136fed25a7f8a999140d3106d77 100644 (file)
     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>
index 3b55498b1f6c24e7456a881b6baa0cf846bd8517..da1ce6e4ef43944eb246bae4336fb95f3012001d 100644 (file)
@@ -674,17 +674,6 @@ CREATE TABLE "PROJECT_LINKS"(
 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,
index 20a9cff3ad1b18fe6412be0c9b23ee0d51d8d24d..7ddbd751377ce90b39d621027050d92d30b3f9ce 100644 (file)
@@ -55,6 +55,9 @@ public class DbVersion102 implements DbVersion {
       .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)
     ;
   }
 
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappings.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappings.java
new file mode 100644 (file)
index 0000000..894d37a
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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());
+      }
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java
new file mode 100644 (file)
index 0000000..75c58e4
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest/schema.sql
new file mode 100644 (file)
index 0000000..a804385
--- /dev/null
@@ -0,0 +1,10 @@
+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);