]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13696 drop PROJECT_ALM_BINDINGS table
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 10 Aug 2020 21:03:27 +0000 (16:03 -0500)
committersonartech <sonartech@sonarsource.com>
Fri, 14 Aug 2020 20:16:19 +0000 (20:16 +0000)
24 files changed:
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.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/alm/ProjectAlmBindingDao.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingDto.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingMapper.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
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/alm/ProjectAlmBindingMapper.xml [deleted file]
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
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-dao/src/test/java/org/sonar/db/alm/ProjectAlmBindingDaoTest.java [deleted file]
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/AlmDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindings.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindingsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindingsTest/schema.sql [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java

index b99c49f65362cfef2ca8498ff662202d4dbba36b..6c6f9df6e4fc87c259f78150085fe4b84ca72917 100644 (file)
@@ -93,7 +93,6 @@ public final class SqTables {
     "perm_tpl_characteristics",
     "plugins",
     "projects",
-    "project_alm_bindings",
     "project_alm_settings",
     "project_branches",
     "project_links",
index aa3ffa7667daa1398700056f7216af882446620a..9a89ca6b2674e237679041aa39a19e9d32f14fc6 100644 (file)
@@ -25,7 +25,6 @@ import java.util.List;
 import org.sonar.core.platform.Module;
 import org.sonar.db.alm.AlmAppInstallDao;
 import org.sonar.db.alm.OrganizationAlmBindingDao;
-import org.sonar.db.alm.ProjectAlmBindingDao;
 import org.sonar.db.alm.pat.AlmPatDao;
 import org.sonar.db.alm.setting.AlmSettingDao;
 import org.sonar.db.alm.setting.ProjectAlmSettingDao;
@@ -124,7 +123,6 @@ public class DaoModule extends Module {
     AlmSettingDao.class,
     AlmPatDao.class,
     ProjectAlmSettingDao.class,
-    ProjectAlmBindingDao.class,
     InternalComponentPropertiesDao.class,
     InternalPropertiesDao.class,
     IssueChangeDao.class,
index 24718f69174dfdb563270e455d13aa18c6157a22..022e0c4dc392aebb69581332c7f2fb748dd9fa68 100644 (file)
@@ -23,7 +23,6 @@ import java.util.IdentityHashMap;
 import java.util.Map;
 import org.sonar.db.alm.AlmAppInstallDao;
 import org.sonar.db.alm.OrganizationAlmBindingDao;
-import org.sonar.db.alm.ProjectAlmBindingDao;
 import org.sonar.db.alm.pat.AlmPatDao;
 import org.sonar.db.alm.setting.AlmSettingDao;
 import org.sonar.db.alm.setting.ProjectAlmSettingDao;
@@ -108,7 +107,6 @@ public class DbClient {
   private final AlmSettingDao almSettingDao;
   private final AlmPatDao almPatDao;
   private final ProjectAlmSettingDao projectAlmSettingDao;
-  private final ProjectAlmBindingDao projectAlmBindingDao;
   private final InternalComponentPropertiesDao internalComponentPropertiesDao;
   private final InternalPropertiesDao internalPropertiesDao;
   private final SnapshotDao snapshotDao;
@@ -180,7 +178,6 @@ public class DbClient {
     almSettingDao = getDao(map, AlmSettingDao.class);
     almPatDao = getDao(map, AlmPatDao.class);
     projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class);
-    projectAlmBindingDao = getDao(map, ProjectAlmBindingDao.class);
     schemaMigrationDao = getDao(map, SchemaMigrationDao.class);
     authorizationDao = getDao(map, AuthorizationDao.class);
     organizationDao = getDao(map, OrganizationDao.class);
@@ -271,10 +268,6 @@ public class DbClient {
     return projectAlmSettingDao;
   }
 
-  public ProjectAlmBindingDao projectAlmBindingsDao() {
-    return projectAlmBindingDao;
-  }
-
   public SchemaMigrationDao schemaMigrationDao() {
     return schemaMigrationDao;
   }
index 8d31e0f973577d8616831a3c9ea69dbf8a29f856..bc390ff1fb1e605f9550d93cd273d01b9c98ff3b 100644 (file)
@@ -36,8 +36,6 @@ import org.apache.ibatis.session.TransactionIsolationLevel;
 import org.sonar.api.Startable;
 import org.sonar.db.alm.AlmAppInstallMapper;
 import org.sonar.db.alm.OrganizationAlmBindingMapper;
-import org.sonar.db.alm.ProjectAlmBindingDto;
-import org.sonar.db.alm.ProjectAlmBindingMapper;
 import org.sonar.db.alm.pat.AlmPatMapper;
 import org.sonar.db.alm.setting.AlmSettingMapper;
 import org.sonar.db.alm.setting.ProjectAlmSettingMapper;
@@ -203,7 +201,6 @@ public class MyBatis implements Startable {
     confBuilder.loadAlias("PermissionTemplateUser", PermissionTemplateUserDto.class);
     confBuilder.loadAlias("Plugin", PluginDto.class);
     confBuilder.loadAlias("PrIssue", PrIssueDto.class);
-    confBuilder.loadAlias("ProjectAlmBinding", ProjectAlmBindingDto.class);
     confBuilder.loadAlias("ProjectQgateAssociation", ProjectQgateAssociationDto.class);
     confBuilder.loadAlias("Project", ProjectDto.class);
     confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class);
@@ -269,7 +266,6 @@ public class MyBatis implements Startable {
       PermissionTemplateCharacteristicMapper.class,
       PermissionTemplateMapper.class,
       PluginMapper.class,
-      ProjectAlmBindingMapper.class,
       ProjectAlmSettingMapper.class,
       ProjectLinkMapper.class,
       ProjectMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingDao.java
deleted file mode 100644 (file)
index c0d2044..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.alm;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-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;
-import static org.sonar.db.DatabaseUtils.executeLargeInputs;
-
-public class ProjectAlmBindingDao implements Dao {
-
-  private final System2 system2;
-  private final UuidFactory uuidFactory;
-
-  public ProjectAlmBindingDao(System2 system2, UuidFactory uuidFactory) {
-    this.system2 = system2;
-    this.uuidFactory = uuidFactory;
-  }
-
-  public void insertOrUpdate(DbSession dbSession, ALM alm, String repoId, String projectUuid, @Nullable String githubSlug, String url) {
-    checkAlm(alm);
-    checkRepoId(repoId);
-    checkArgument(isNotEmpty(projectUuid), "projectUuid can't be null nor empty");
-    checkArgument(isNotEmpty(url), "url can't be null nor empty");
-
-    ProjectAlmBindingMapper mapper = getMapper(dbSession);
-    long now = system2.now();
-
-    if (mapper.update(alm.getId(), repoId, projectUuid, githubSlug, url, now) == 0) {
-      mapper.insert(uuidFactory.create(), alm.getId(), repoId, projectUuid, githubSlug, url, now);
-    }
-  }
-
-  public Optional<ProjectAlmBindingDto> selectByProjectUuid(DbSession session, String projectUuid) {
-    return Optional.ofNullable(getMapper(session).selectByProjectUuid(projectUuid));
-  }
-
-  /**
-   * Gets a list of bindings by their repo_id. The result does NOT contain {@code null} values for bindings not found, so
-   * the size of result may be less than the number of ids.
-   * <p>Results may be in a different order as input ids.</p>
-   */
-  public List<ProjectAlmBindingDto> selectByRepoIds(final DbSession session, ALM alm, Collection<String> repoIds) {
-    return executeLargeInputs(repoIds, partitionedIds -> getMapper(session).selectByRepoIds(alm.getId(), partitionedIds));
-  }
-
-  public Optional<ProjectAlmBindingDto> selectByRepoId(final DbSession session, ALM alm, String repoId) {
-    return Optional.ofNullable(getMapper(session).selectByRepoId(alm.getId(), repoId));
-  }
-
-  public Optional<String> findProjectKey(DbSession dbSession, ALM alm, String repoId) {
-    checkAlm(alm);
-    checkRepoId(repoId);
-
-    ProjectAlmBindingMapper mapper = getMapper(dbSession);
-    return Optional.ofNullable(mapper.selectProjectKey(alm.getId(), repoId));
-  }
-
-  private static void checkAlm(@Nullable ALM alm) {
-    Objects.requireNonNull(alm, "alm can't be null");
-  }
-
-  private static void checkRepoId(@Nullable String repoId) {
-    checkArgument(isNotEmpty(repoId), "repoId can't be null nor empty");
-  }
-
-  private static ProjectAlmBindingMapper getMapper(DbSession dbSession) {
-    return dbSession.getMapper(ProjectAlmBindingMapper.class);
-  }
-
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingDto.java
deleted file mode 100644 (file)
index ce9f2e1..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.alm;
-
-import java.util.Arrays;
-
-/**
- * DTO is used only for select, hence no setters (MyBatis populates field by reflection).
- */
-public class ProjectAlmBindingDto {
-  private String uuid;
-  private String rawAlmId;
-  private String repoId;
-  private String projectUuid;
-  private String githubSlug;
-  private String url;
-
-  public ALM getAlm() {
-    return Arrays.stream(ALM.values())
-      .filter(a -> a.getId().equals(rawAlmId))
-      .findAny()
-      .orElseThrow(() -> new IllegalStateException("ALM id " + rawAlmId + " is invalid"));
-  }
-
-  public String getRepoId() {
-    return repoId;
-  }
-
-  public String getProjectUuid() {
-    return projectUuid;
-  }
-
-  public String getGithubSlug() {
-    return githubSlug;
-  }
-
-  public String getUrl() {
-    return url;
-  }
-
-  public String getUuid() {
-    return uuid;
-  }
-
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ProjectAlmBindingMapper.java
deleted file mode 100644 (file)
index ddf722a..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.alm;
-
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.ibatis.annotations.Param;
-
-public interface ProjectAlmBindingMapper {
-
-  int bindingCount(@Param("almId") String almId, @Param("repoId") String repoId);
-
-  void insert(@Param("uuid") String uuid, @Param("almId") String almId, @Param("repoId") String repoId, @Param("projectUuid") String projectUuid,
-    @Nullable @Param("githubSlug") String githubSlug, @Param("url") String url, @Param("now") long now);
-
-  int update(@Param("almId") String almId, @Param("repoId") String repoId, @Param("projectUuid") String projectUuid,
-    @Nullable @Param("githubSlug") String githubSlug, @Param("url") String url, @Param("now") long now);
-
-  List<ProjectAlmBindingDto> selectByRepoIds(@Param("almId") String almId, @Param("repoIds") List<String> repoIds);
-
-  ProjectAlmBindingDto selectByRepoId(@Param("almId") String almId, @Param("repoId") String repoId);
-
-  ProjectAlmBindingDto selectByProjectUuid(@Param("projectUuid") String projectUuid);
-
-  @CheckForNull
-  String selectProjectKey(@Param("almId") String almId, @Param("repoId") String repoId);
-}
index e4426e519b748dd5d7836e2fbf992ded17d884d9..03e1b31e89db63188ef1544db352a20a6ae4d39f 100644 (file)
@@ -392,10 +392,6 @@ public class ComponentDao implements Dao {
     return mapper(dbSession).selectPrivateProjectsWithNcloc(organizationUuid);
   }
 
-  public Optional<ComponentDto> selectByAlmIdAndAlmRepositoryId(DbSession dbSession, String almId, String almRepositoryId) {
-    return Optional.ofNullable(mapper(dbSession).selectByAlmIdAndAlmRepositoryId(almId, almRepositoryId));
-  }
-
   public boolean existAnyOfComponentsWithQualifiers(DbSession session, Collection<String> componentKeys, Set<String> qualifiers) {
     if (!componentKeys.isEmpty()) {
       List<Boolean> result = new LinkedList<>();
index 3081461ed4c73ced8145b1afe5b56b9158682347..3604655853de768735a327ec4d73c9e1de009efb 100644 (file)
@@ -42,9 +42,6 @@ public interface ComponentMapper {
   @CheckForNull
   ComponentDto selectByUuid(String uuid);
 
-  @CheckForNull
-  ComponentDto selectByAlmIdAndAlmRepositoryId(@Param("almId") String almId, @Param("almRepositoryId") String almRepositoryId);
-
   /**
    * Return sub project of component keys
    */
index cba1d524e1d5e1ba47c5f9f3d52dd64a114c67c1..3d28191d9b12ed31bc0196450694fbaeceef0b0c 100644 (file)
@@ -399,13 +399,6 @@ class PurgeCommands {
     profiler.stop();
   }
 
-  void deleteProjectAlmBindings(String rootUuid) {
-    profiler.start("deleteProjectAlmBindings (project_alm_bindings)");
-    purgeMapper.deleteProjectAlmBindingsByProjectUuid(rootUuid);
-    session.commit();
-    profiler.stop();
-  }
-
   public void deleteProjectAlmSettings(String rootUuid) {
     profiler.start("deleteProjectAlmSettings (project_alm_settings)");
     purgeMapper.deleteProjectAlmSettingsByProjectUuid(rootUuid);
index 3b51bd337f1c16b65c5401e5956f9b1b2a8deee7..16d0df3ffc67845eecbf2086f1a00bf28d4f6439 100644 (file)
@@ -202,7 +202,6 @@ public class PurgeDao implements Dao {
     commands.deleteWebhookDeliveries(rootUuid);
     commands.deleteLiveMeasures(rootUuid);
     commands.deleteProjectMappings(rootUuid);
-    commands.deleteProjectAlmBindings(rootUuid);
     commands.deleteProjectAlmSettings(rootUuid);
     commands.deletePermissions(rootUuid);
     commands.deleteNewCodePeriods(rootUuid);
index 1ce7f336a0b428fa09756158509ba4dcfd173413..5e068e4cac9328a796c5060aed389549b76c4422 100644 (file)
@@ -139,8 +139,6 @@ public interface PurgeMapper {
 
   void deleteProjectMappingsByProjectUuid(@Param("projectUuid") String projectUuid);
 
-  void deleteProjectAlmBindingsByProjectUuid(@Param("projectUuid") String projectUuid);
-
   void deleteBranchByUuid(@Param("uuid") String uuid);
 
   void deleteLiveMeasuresByProjectUuid(@Param("projectUuid") String projectUuid);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/ProjectAlmBindingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/ProjectAlmBindingMapper.xml
deleted file mode 100644 (file)
index 0f4d89b..0000000
+++ /dev/null
@@ -1,105 +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.alm.ProjectAlmBindingMapper">
-
-  <sql id="columns">
-    uuid,
-    alm_id as rawAlmId,
-    repo_id as repoId,
-    project_uuid as projectUuid,
-    github_slug as githubSlug,
-    url
-  </sql>
-
-  <select id="bindingCount" parameterType="Map" resultType="int">
-    select
-      count(*) as count
-    from
-      project_alm_bindings
-    where
-      alm_id = #{almId, jdbcType=VARCHAR}
-      and repo_id = #{repoId, jdbcType=VARCHAR}
-  </select>
-
-  <insert id="insert" parameterType="Map" useGeneratedKeys="false">
-    insert into project_alm_bindings
-    (
-      uuid,
-      alm_id,
-      repo_id,
-      project_uuid,
-      github_slug,
-      url,
-      created_at,
-      updated_at
-    )
-    values (
-      #{uuid, jdbcType=VARCHAR},
-      #{almId, jdbcType=VARCHAR},
-      #{repoId, jdbcType=VARCHAR},
-      #{projectUuid, jdbcType=VARCHAR},
-      #{githubSlug, jdbcType=VARCHAR},
-      #{url, jdbcType=VARCHAR},
-      #{now, jdbcType=BIGINT},
-      #{now, jdbcType=BIGINT}
-    )
-  </insert>
-
-  <update id="update" parameterType="map">
-    update project_alm_bindings
-    set
-      project_uuid = #{projectUuid, jdbcType=VARCHAR},
-      github_slug = #{githubSlug, jdbcType=VARCHAR},
-      url = #{url, jdbcType=VARCHAR},
-      updated_at = #{now, jdbcType=BIGINT}
-    where
-      alm_id = #{almId, jdbcType=VARCHAR}
-      and repo_id = #{repoId, jdbcType=VARCHAR}
-  </update>
-
-  <select id="selectByRepoIds" parameterType="map" resultType="ProjectAlmBinding">
-    select
-      <include refid="columns"/>
-    from
-      project_alm_bindings
-    where
-      alm_id = #{almId, jdbcType=VARCHAR}
-      and repo_id in
-    <foreach collection="repoIds" open="(" close=")" item="repoId" separator=",">
-      #{repoId,jdbcType=VARCHAR}
-    </foreach>
-  </select>
-
-  <select id="selectByRepoId" parameterType="map" resultType="ProjectAlmBinding">
-    select
-      <include refid="columns"/>
-    from
-      project_alm_bindings
-    where
-      alm_id = #{almId, jdbcType=VARCHAR}
-      and repo_id = #{repoId, jdbcType=VARCHAR}
-  </select>
-
-  <select id="selectByProjectUuid" parameterType="map" resultType="ProjectAlmBinding">
-    select
-      <include refid="columns"/>
-    from
-      project_alm_bindings
-    where
-      project_uuid = #{projectUuid, jdbcType=VARCHAR}
-  </select>
-
-  <select id="selectProjectKey" parameterType="Map" resultType="String">
-    select
-      p.kee as projectKey
-    from
-      project_alm_bindings b
-    inner join projects p
-      on b.project_uuid = p.uuid
-    where
-      alm_id = #{almId, jdbcType=VARCHAR}
-      and repo_id = #{repoId, jdbcType=VARCHAR}
-  </select>
-
-</mapper>
index 1694f814ea0827f126ca0de3d35ba0aaae76b27e..89de35765863728b66c11e49d51b4cb9010a8855 100644 (file)
       p.uuid=#{uuid,jdbcType=VARCHAR}
   </select>
 
-  <select id="selectByAlmIdAndAlmRepositoryId" resultType="Component">
-    select
-    <include refid="componentColumns"/>
-    from
-    components p
-    inner join
-    project_alm_bindings pab on pab.project_uuid = p.uuid
-    where
-    pab.alm_id = #{almId,jdbcType=VARCHAR} and pab.repo_id = #{almRepositoryId,jdbcType=VARCHAR}
-  </select>
-
   <select id="selectByProjectUuid" parameterType="string" resultType="Component">
     select
     <include refid="componentColumns"/>
index 478aa74c9ab09ded2f6bbd243d155bd63f0efb71..7172ba7bba9e579a513b35cc025cf3335707b3b0 100644 (file)
     delete from project_alm_settings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
 
-  <delete id="deleteProjectAlmBindingsByProjectUuid">
-    delete from project_alm_bindings where project_uuid=#{projectUuid,jdbcType=VARCHAR}
-  </delete>
-
   <delete id="deleteBranchByUuid">
     delete from project_branches where uuid=#{uuid,jdbcType=VARCHAR}
   </delete>
index 594cb26a21f5397445131372582edbdacee3c1f8..edcf04907a7046aa09e3d42c83221d1a12631662 100644 (file)
@@ -605,20 +605,6 @@ CREATE TABLE "PLUGINS"(
 ALTER TABLE "PLUGINS" ADD CONSTRAINT "PK_PLUGINS" PRIMARY KEY("UUID");
 CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS"("KEE");
 
-CREATE TABLE "PROJECT_ALM_BINDINGS"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "ALM_ID" VARCHAR(40) NOT NULL,
-    "REPO_ID" VARCHAR(256) NOT NULL,
-    "PROJECT_UUID" VARCHAR(40) NOT NULL,
-    "GITHUB_SLUG" VARCHAR(256),
-    "URL" VARCHAR(2000) NOT NULL,
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROJECT_ALM_BINDINGS" ADD CONSTRAINT "PK_PROJECT_ALM_BINDINGS" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "PROJECT_ALM_BINDINGS_ALM_REPO" ON "PROJECT_ALM_BINDINGS"("ALM_ID", "REPO_ID");
-CREATE UNIQUE INDEX "PROJECT_ALM_BINDINGS_PROJECT" ON "PROJECT_ALM_BINDINGS"("PROJECT_UUID");
-
 CREATE TABLE "PROJECT_ALM_SETTINGS"(
     "UUID" VARCHAR(40) NOT NULL,
     "ALM_SETTING_UUID" VARCHAR(40) NOT NULL,
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/ProjectAlmBindingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/ProjectAlmBindingDaoTest.java
deleted file mode 100644 (file)
index 61a28c3..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.alm;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import javax.annotation.Nullable;
-import org.assertj.core.api.AbstractAssert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.project.ProjectDto;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.db.alm.ALM.BITBUCKETCLOUD;
-import static org.sonar.db.alm.ALM.GITHUB;
-
-public class ProjectAlmBindingDaoTest {
-
-  private static final String A_UUID = "abcde1234";
-  private static final String ANOTHER_UUID = "xyz789";
-  private static final String EMPTY_STRING = "";
-
-  private static final String A_REPO = "my_repo";
-  private static final String ANOTHER_REPO = "another_repo";
-
-  private static final String A_GITHUB_SLUG = null;
-  private static final String ANOTHER_GITHUB_SLUG = "example/foo";
-
-  private static final String A_URL = "foo url";
-  private static final String ANOTHER_URL = "bar url";
-
-  private static final long DATE = 1_600_000_000_000L;
-  private static final long DATE_LATER = 1_700_000_000_000L;
-
-  private System2 system2 = mock(System2.class);
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-  @Rule
-  public DbTester dbTester = DbTester.create(system2);
-  private DbClient dbClient = dbTester.getDbClient();
-  private DbSession dbSession = dbTester.getSession();
-
-  private UuidFactory uuidFactory = mock(UuidFactory.class);
-  private ProjectAlmBindingDao underTest = new ProjectAlmBindingDao(system2, uuidFactory);
-
-  @Test
-  public void insert_throws_NPE_if_alm_is_null() {
-    expectAlmNPE();
-
-    underTest.insertOrUpdate(dbSession, null, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-  }
-
-  @Test
-  public void insert_throws_IAE_if_repo_id_is_null() {
-    expectRepoIdNullOrEmptyIAE();
-
-    underTest.insertOrUpdate(dbSession, GITHUB, null, A_UUID, A_GITHUB_SLUG, A_URL);
-  }
-
-  @Test
-  public void insert_throws_IAE_if_repo_id_is_empty() {
-    expectRepoIdNullOrEmptyIAE();
-
-    underTest.insertOrUpdate(dbSession, GITHUB, EMPTY_STRING, A_UUID, A_GITHUB_SLUG, A_URL);
-  }
-
-  @Test
-  public void insert_throws_IAE_if_project_uuid_is_null() {
-    expectProjectUuidNullOrEmptyIAE();
-
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, null, A_GITHUB_SLUG, A_URL);
-  }
-
-  @Test
-  public void insert_throws_IAE_if_project_uuid_is_empty() {
-    expectProjectUuidNullOrEmptyIAE();
-
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, EMPTY_STRING, A_GITHUB_SLUG, A_URL);
-  }
-
-  @Test
-  public void insert_throws_IAE_if_url_is_null() {
-    expectUrlNullOrEmptyIAE();
-
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, null);
-  }
-
-  @Test
-  public void insert_throws_IAE_if_url_is_empty() {
-    expectUrlNullOrEmptyIAE();
-
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, EMPTY_STRING);
-  }
-
-  @Test
-  public void insert() {
-    when(system2.now()).thenReturn(DATE);
-    when(uuidFactory.create()).thenReturn("uuid1");
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-
-    assertThatProjectAlmBinding(GITHUB, A_REPO)
-      .hasProjectUuid(A_UUID)
-      .hasGithubSlug(A_GITHUB_SLUG)
-      .hasUrl(A_URL)
-      .hasCreatedAt(DATE)
-      .hasUpdatedAt(DATE);
-  }
-
-  @Test
-  public void update() {
-    when(system2.now()).thenReturn(DATE);
-    when(uuidFactory.create()).thenReturn("uuid1");
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-
-    when(system2.now()).thenReturn(DATE_LATER);
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, ANOTHER_UUID, ANOTHER_GITHUB_SLUG, ANOTHER_URL);
-
-    assertThatProjectAlmBinding(GITHUB, A_REPO)
-      .hasProjectUuid(ANOTHER_UUID)
-      .hasGithubSlug(ANOTHER_GITHUB_SLUG)
-      .hasUrl(ANOTHER_URL)
-      .hasCreatedAt(DATE)
-      .hasUpdatedAt(DATE_LATER);
-  }
-
-  @Test
-  public void insert_multiple() {
-    when(system2.now()).thenReturn(DATE);
-    when(uuidFactory.create()).thenReturn("uuid1").thenReturn("uuid2");
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-    underTest.insertOrUpdate(dbSession, GITHUB, ANOTHER_REPO, ANOTHER_UUID, ANOTHER_GITHUB_SLUG, ANOTHER_URL);
-
-    assertThatProjectAlmBinding(GITHUB, A_REPO)
-      .hasProjectUuid(A_UUID)
-      .hasGithubSlug(A_GITHUB_SLUG)
-      .hasUrl(A_URL)
-      .hasCreatedAt(DATE)
-      .hasUpdatedAt(DATE);
-
-    assertThatProjectAlmBinding(GITHUB, ANOTHER_REPO)
-      .hasProjectUuid(ANOTHER_UUID)
-      .hasGithubSlug(ANOTHER_GITHUB_SLUG)
-      .hasUrl(ANOTHER_URL)
-      .hasCreatedAt(DATE)
-      .hasUpdatedAt(DATE);
-  }
-
-  @Test
-  public void select_by_repo_id() {
-    when(system2.now()).thenReturn(DATE);
-    when(uuidFactory.create())
-      .thenReturn("uuid1")
-      .thenReturn("uuid2")
-      .thenReturn("uuid3");
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-    underTest.insertOrUpdate(dbSession, GITHUB, ANOTHER_REPO, ANOTHER_UUID, null, ANOTHER_URL);
-    underTest.insertOrUpdate(dbSession, BITBUCKETCLOUD, ANOTHER_REPO, "foo", null, "http://foo");
-
-    assertThat(underTest.selectByRepoId(dbSession, GITHUB, "foo")).isNotPresent();
-
-    Optional<ProjectAlmBindingDto> dto = underTest.selectByRepoId(dbSession, GITHUB, A_REPO);
-    assertThat(dto).isPresent();
-    assertThat(dto.get().getUuid()).isEqualTo("uuid1");
-    assertThat(dto.get().getAlm()).isEqualTo(GITHUB);
-    assertThat(dto.get().getRepoId()).isEqualTo(A_REPO);
-    assertThat(dto.get().getProjectUuid()).isEqualTo(A_UUID);
-    assertThat(dto.get().getUrl()).isEqualTo(A_URL);
-    assertThat(dto.get().getGithubSlug()).isEqualTo(A_GITHUB_SLUG);
-  }
-
-  @Test
-  public void select_by_project_uuid() {
-    when(system2.now()).thenReturn(DATE);
-    when(uuidFactory.create())
-      .thenReturn("uuid1")
-      .thenReturn("uuid2")
-      .thenReturn("uuid3");
-    underTest.insertOrUpdate(dbSession, BITBUCKETCLOUD, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-    underTest.insertOrUpdate(dbSession, BITBUCKETCLOUD, ANOTHER_REPO, ANOTHER_UUID, null, ANOTHER_URL);
-    underTest.insertOrUpdate(dbSession, GITHUB, ANOTHER_REPO, "foo", null, "http://foo");
-
-    assertThat(underTest.selectByProjectUuid(dbSession, "missing")).isNotPresent();
-
-    Optional<ProjectAlmBindingDto> dto = underTest.selectByProjectUuid(dbSession, A_UUID);
-    assertThat(dto).isPresent();
-    assertThat(dto.get().getUuid()).isEqualTo("uuid1");
-    assertThat(dto.get().getAlm()).isEqualTo(BITBUCKETCLOUD);
-    assertThat(dto.get().getRepoId()).isEqualTo(A_REPO);
-    assertThat(dto.get().getProjectUuid()).isEqualTo(A_UUID);
-    assertThat(dto.get().getUrl()).isEqualTo(A_URL);
-    assertThat(dto.get().getGithubSlug()).isEqualTo(A_GITHUB_SLUG);
-  }
-
-  @Test
-  public void select_by_repo_ids() {
-    when(system2.now()).thenReturn(DATE);
-    when(uuidFactory.create())
-      .thenReturn("uuid1")
-      .thenReturn("uuid2")
-      .thenReturn("uuid3");
-
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
-    underTest.insertOrUpdate(dbSession, GITHUB, ANOTHER_REPO, ANOTHER_UUID, null, ANOTHER_URL);
-    underTest.insertOrUpdate(dbSession, BITBUCKETCLOUD, ANOTHER_REPO, "foo", null, "http://foo");
-
-    assertThat(underTest.selectByRepoIds(dbSession, GITHUB, Arrays.asList(A_REPO, ANOTHER_REPO, "foo")))
-      .extracting(ProjectAlmBindingDto::getUuid, ProjectAlmBindingDto::getAlm, ProjectAlmBindingDto::getRepoId, ProjectAlmBindingDto::getProjectUuid,
-        ProjectAlmBindingDto::getUrl, ProjectAlmBindingDto::getGithubSlug)
-      .containsExactlyInAnyOrder(
-        tuple("uuid1", GITHUB, A_REPO, A_UUID, A_URL, A_GITHUB_SLUG),
-        tuple("uuid2", GITHUB, ANOTHER_REPO, ANOTHER_UUID, ANOTHER_URL, null));
-  }
-
-  @Test
-  public void findProjectKey_throws_NPE_when_alm_is_null() {
-    expectAlmNPE();
-
-    underTest.findProjectKey(dbSession, null, A_REPO);
-  }
-
-  @Test
-  public void findProjectKey_throws_IAE_when_repo_id_is_null() {
-    expectRepoIdNullOrEmptyIAE();
-
-    underTest.findProjectKey(dbSession, GITHUB, null);
-  }
-
-  @Test
-  public void findProjectKey_throws_IAE_when_repo_id_is_empty() {
-    expectRepoIdNullOrEmptyIAE();
-
-    underTest.findProjectKey(dbSession, GITHUB, EMPTY_STRING);
-  }
-
-  @Test
-  public void findProjectKey_returns_empty_when_entry_does_not_exist_in_DB() {
-    assertThat(underTest.findProjectKey(dbSession, GITHUB, A_REPO)).isEmpty();
-  }
-
-  @Test
-  public void findProjectKey_returns_projectKey_when_entry_exists() {
-    String projectKey = randomAlphabetic(10);
-    ProjectDto project = createProject(projectKey);
-    when(uuidFactory.create()).thenReturn("uuid1");
-    underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, project.getUuid(), A_GITHUB_SLUG, A_URL);
-
-    assertThat(underTest.findProjectKey(dbSession, GITHUB, A_REPO)).contains(projectKey);
-  }
-
-  private void expectAlmNPE() {
-    expectedException.expect(NullPointerException.class);
-    expectedException.expectMessage("alm can't be null");
-  }
-
-  private void expectRepoIdNullOrEmptyIAE() {
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("repoId can't be null nor empty");
-  }
-
-  private void expectProjectUuidNullOrEmptyIAE() {
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("projectUuid can't be null nor empty");
-  }
-
-  private void expectUrlNullOrEmptyIAE() {
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("url can't be null nor empty");
-  }
-
-  private ProjectAlmBindingAssert assertThatProjectAlmBinding(ALM alm, String repoId) {
-    return new ProjectAlmBindingAssert(dbTester, dbSession, alm, repoId);
-  }
-
-  private static class ProjectAlmBindingAssert extends AbstractAssert<ProjectAlmBindingAssert, ProjectAlmBinding> {
-
-    private ProjectAlmBindingAssert(DbTester dbTester, DbSession dbSession, ALM alm, String repoId) {
-      super(asProjectAlmBinding(dbTester, dbSession, alm, repoId), ProjectAlmBindingAssert.class);
-    }
-
-    private static ProjectAlmBinding asProjectAlmBinding(DbTester dbTester, DbSession dbSession, ALM alm, String repoId) {
-      List<Map<String, Object>> rows = dbTester.select(
-        dbSession,
-        "select" +
-          " project_uuid as \"projectUuid\", github_slug as \"githubSlug\", url as \"url\", " +
-          " created_at as \"createdAt\", updated_at as \"updatedAt\"" +
-          " from project_alm_bindings" +
-          " where alm_id='" + alm.getId() + "' and repo_id='" + repoId + "'");
-      if (rows.isEmpty()) {
-        return null;
-      }
-      if (rows.size() > 1) {
-        throw new IllegalStateException("Unique index violation");
-      }
-      return new ProjectAlmBinding(
-        (String) rows.get(0).get("projectUuid"),
-        (String) rows.get(0).get("githubSlug"),
-        (String) rows.get(0).get("url"),
-        (Long) rows.get(0).get("createdAt"),
-        (Long) rows.get(0).get("updatedAt"));
-    }
-
-    public void doesNotExist() {
-      isNull();
-    }
-
-    ProjectAlmBindingAssert hasProjectUuid(String expected) {
-      isNotNull();
-
-      if (!Objects.equals(actual.projectUuid, expected)) {
-        failWithMessage("Expected Project ALM Binding to have column PROJECT_UUID to be <%s> but was <%s>", expected, actual.projectUuid);
-      }
-      return this;
-    }
-
-    ProjectAlmBindingAssert hasGithubSlug(String expected) {
-      isNotNull();
-
-      if (!Objects.equals(actual.githubSlug, expected)) {
-        failWithMessage("Expected Project ALM Binding to have column GITHUB_SLUG to be <%s> but was <%s>", expected, actual.githubSlug);
-      }
-      return this;
-    }
-
-    ProjectAlmBindingAssert hasUrl(String expected) {
-      isNotNull();
-
-      if (!Objects.equals(actual.url, expected)) {
-        failWithMessage("Expected Project ALM Binding to have column URL to be <%s> but was <%s>", expected, actual.url);
-      }
-      return this;
-    }
-
-    ProjectAlmBindingAssert hasCreatedAt(long expected) {
-      isNotNull();
-
-      if (!Objects.equals(actual.createdAt, expected)) {
-        failWithMessage("Expected Project ALM Binding to have column CREATED_AT to be <%s> but was <%s>", expected, actual.createdAt);
-      }
-
-      return this;
-    }
-
-    ProjectAlmBindingAssert hasUpdatedAt(long expected) {
-      isNotNull();
-
-      if (!Objects.equals(actual.updatedAt, expected)) {
-        failWithMessage("Expected Project ALM Binding to have column UPDATED_AT to be <%s> but was <%s>", expected, actual.updatedAt);
-      }
-
-      return this;
-    }
-
-  }
-
-  private static final class ProjectAlmBinding {
-    private final String projectUuid;
-    private final String githubSlug;
-    private final String url;
-    private final Long createdAt;
-    private final Long updatedAt;
-
-    ProjectAlmBinding(@Nullable String projectUuid, @Nullable String githubSlug, @Nullable String url, @Nullable Long createdAt, @Nullable Long updatedAt) {
-      this.projectUuid = projectUuid;
-      this.githubSlug = githubSlug;
-      this.url = url;
-      this.createdAt = createdAt;
-      this.updatedAt = updatedAt;
-    }
-  }
-
-  private ProjectDto createProject(String projectKey) {
-    return dbTester.components().insertPrivateProjectDto(c -> c.setDbKey(projectKey));
-  }
-}
index 4bc0fa7c1c762846b83341f92b4993b98261d807..e6a9ef9331457d105b34ab8a3ff2d802bc16b18a 100644 (file)
@@ -1226,23 +1226,6 @@ public class PurgeDaoTest {
     assertThat(dbClient.projectMappingsDao().get(dbSession, "a.key.type", "another.key")).isNotEmpty();
   }
 
-  @Test
-  public void deleteProject_deletes_project_alm_bindings() {
-    ALM alm = ALM.GITHUB;
-    String repoId = "123";
-    String otherRepoId = repoId + "-foo";
-
-    ComponentDto project = db.components().insertPublicProject();
-    ComponentDto otherProject = db.components().insertPublicProject();
-    dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, repoId, project.uuid(), null, "foo");
-    dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, otherRepoId, otherProject.uuid(), null, "bar");
-
-    underTest.deleteProject(dbSession, project.uuid());
-
-    assertThat(dbClient.projectAlmBindingsDao().findProjectKey(dbSession, alm, repoId)).isEmpty();
-    assertThat(dbClient.projectAlmBindingsDao().findProjectKey(dbSession, alm, otherRepoId)).isNotEmpty();
-  }
-
   @Test
   public void deleteProject_deletes_project_alm_settings() {
     ProjectDto project = db.components().insertPublicProjectDto();
index 4605e5e83a01dd52a94b87481ad96f35d4fc2a22..596e0c446114095acc57412b802ed9d0dc006692 100644 (file)
@@ -46,13 +46,6 @@ public class AlmDbTester {
     return db.getDbClient().organizationAlmBindingDao().selectByOrganization(db.getSession(), organization).get();
   }
 
-  public ProjectAlmBindingDto insertProjectAlmBinding(ALM alm, ComponentDto componentDto, String repositoryUuid) {
-    db.getDbClient().projectAlmBindingsDao().insertOrUpdate(db.getSession(), alm, repositoryUuid, componentDto.uuid(),
-      "some_org/some_repo", "http://alm/some_org_some_repo");
-    db.commit();
-    return db.getDbClient().projectAlmBindingsDao().selectByProjectUuid(db.getSession(), componentDto.uuid()).get();
-  }
-
   @SafeVarargs
   public final AlmAppInstallDto insertAlmAppInstall(Consumer<AlmAppInstallDto>... dtoPopulators) {
     AlmAppInstallDto dto = new AlmAppInstallDto()
index d9d78d829dbd96b5c8ce4eb5218b19080d8e5117..cb31b3548221f46a981625471eaf767f6709acf7 100644 (file)
@@ -27,6 +27,8 @@ public class DbVersion85 implements DbVersion {
   public void addSteps(MigrationStepRegistry registry) {
     registry
       .add(4000, "Delete 'project_alm_settings' orphans", DeleteProjectAlmSettingsOrphans.class)
-      .add(4001, "Drop 'period', 'value_warning' columns from 'quality_gates_conditions' table", DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.class);
+      .add(4001, "Drop 'period', 'value_warning' columns from 'quality_gates_conditions' table", DropPeriodAndValueWarningColumnsFromQualityGateConditionsTable.class)
+      .add(4001, "Drop 'project_alm_bindings' table", DropProjectAlmBindings.class)
+    ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindings.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindings.java
new file mode 100644 (file)
index 0000000..45cbe59
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropProjectAlmBindings extends DdlChange {
+  private static final String TABLE_NAME = "project_alm_bindings";
+
+  public DropProjectAlmBindings(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("project_alm_bindings_alm_repo").build());
+    context.execute(new DropIndexBuilder(getDialect()).setTable(TABLE_NAME).setName("project_alm_bindings_project").build());
+    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/v85/DropProjectAlmBindingsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindingsTest.java
new file mode 100644 (file)
index 0000000..6adcd26
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropProjectAlmBindingsTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropProjectAlmBindingsTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropProjectAlmBindings(db.database());
+
+  @Test
+  public void drops_table() throws SQLException {
+    insertData();
+    db.assertTableExists("project_alm_bindings");
+    underTest.execute();
+    db.assertTableDoesNotExist("project_alm_bindings");
+  }
+
+  private void insertData() {
+    db.executeInsert("project_alm_bindings",
+      "uuid", "uuid1",
+      "alm_id", "alm1",
+      "repo_id", "repo1",
+      "project_uuid", "project1",
+      "url", "url1",
+      "created_at", 123L,
+      "updated_at", 456L
+    );
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindingsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/DropProjectAlmBindingsTest/schema.sql
new file mode 100644 (file)
index 0000000..aac315b
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "PROJECT_ALM_BINDINGS"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "ALM_ID" VARCHAR(40) NOT NULL,
+    "REPO_ID" VARCHAR(256) NOT NULL,
+    "PROJECT_UUID" VARCHAR(40) NOT NULL,
+    "GITHUB_SLUG" VARCHAR(256),
+    "URL" VARCHAR(2000) NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROJECT_ALM_BINDINGS" ADD CONSTRAINT "PK_PROJECT_ALM_BINDINGS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "PROJECT_ALM_BINDINGS_ALM_REPO" ON "PROJECT_ALM_BINDINGS"("ALM_ID", "REPO_ID");
+CREATE UNIQUE INDEX "PROJECT_ALM_BINDINGS_PROJECT" ON "PROJECT_ALM_BINDINGS"("PROJECT_UUID");
index c48578ffd390f6adc86400eb69aeccf4882b2830..e5e321f178eb124dd7f0eac6fbc50efe93c05f3d 100644 (file)
@@ -42,7 +42,6 @@ import org.sonar.api.web.UserRole;
 import org.sonar.api.web.page.Page;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.alm.ProjectAlmBindingDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.LiveMeasureDto;
@@ -166,7 +165,6 @@ public class ComponentAction implements NavigationWsAction {
         json.beginObject();
         boolean isFavourite = isFavourite(session, rootProject);
         writeComponent(json, component, org, analysis.orElse(null), isFavourite);
-        writeAlmDetails(json, session, rootProject);
         writeProfiles(json, session, component);
         writeQualityGate(json, session, org, rootProject);
         if (userSession.hasComponentPermission(ADMIN, component) ||
@@ -192,17 +190,6 @@ public class ComponentAction implements NavigationWsAction {
     }
   }
 
-  private void writeAlmDetails(JsonWriter json, DbSession session, ComponentDto component) {
-    Optional<ProjectAlmBindingDto> bindingOpt = dbClient.projectAlmBindingsDao().selectByProjectUuid(session, component.uuid());
-    bindingOpt.ifPresent(b -> {
-      String almId = b.getAlm().getId();
-      json.name("alm").beginObject()
-        .prop("key", almId)
-        .prop("url", b.getUrl())
-        .endObject();
-    });
-  }
-
   private static void writeToJson(JsonWriter json, QualityProfile profile, boolean deleted) {
     json.beginObject()
       .prop("key", profile.getQpKey())