]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12692 add project_uuid to issues_changes
authorPierre <pierre.guillot@sonarsource.com>
Thu, 3 Sep 2020 13:55:54 +0000 (15:55 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 8 Sep 2020 20:07:13 +0000 (20:07 +0000)
43 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.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/issue/IssueChangeDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTable.java [new file with mode: 0644]
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/MakeIssueKeyNotNullOnIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChanges.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ClobColumnDefTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueStorage.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java

index 7a7ac7761d1e83c2a61f0dcd60a4a40c6b54a956..ce13688d5238fb578164e5429346c90f92c079e7 100644 (file)
@@ -43,6 +43,9 @@ public final class IssueChangeDto implements Serializable {
   private String uuid;
   private String kee;
   private String issueKey;
+  private String projectUuid;
+
+
   /**
    * The column USER_LOGIN hasn't been renamed to USER_UUID because we don't know yet the cost of renaming a column on a table that can contain huge number of data
    */
@@ -58,7 +61,11 @@ public final class IssueChangeDto implements Serializable {
   @Nullable
   private Long issueChangeCreationDate;
 
-  public static IssueChangeDto of(DefaultIssueComment comment) {
+  public IssueChangeDto() {
+    // nothing to do
+  }
+
+  public static IssueChangeDto of(DefaultIssueComment comment, String projectUuid) {
     IssueChangeDto dto = newDto(comment.issueKey());
     dto.setKey(comment.key());
     dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
@@ -66,16 +73,18 @@ public final class IssueChangeDto implements Serializable {
     dto.setUserUuid(comment.userUuid());
     Date createdAt = requireNonNull(comment.createdAt(), "Comment created at must not be null");
     dto.setIssueChangeCreationDate(createdAt.getTime());
+    dto.setProjectUuid(projectUuid);
     return dto;
   }
 
-  public static IssueChangeDto of(String issueKey, FieldDiffs diffs) {
+  public static IssueChangeDto of(String issueKey, FieldDiffs diffs, String projectUuid) {
     IssueChangeDto dto = newDto(issueKey);
     dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
     dto.setChangeData(diffs.toEncodedString());
     dto.setUserUuid(diffs.userUuid());
     Date createdAt = requireNonNull(diffs.creationDate(), "Diffs created at must not be null");
     dto.setIssueChangeCreationDate(createdAt.getTime());
+    dto.setProjectUuid(projectUuid);
     return dto;
   }
 
@@ -195,4 +204,13 @@ public final class IssueChangeDto implements Serializable {
       .setCreationDate(new Date(getIssueChangeCreationDate()))
       .setIssueKey(issueKey);
   }
+
+  public String getProjectUuid() {
+    return projectUuid;
+  }
+
+  public IssueChangeDto setProjectUuid(String projectUuid) {
+    this.projectUuid = projectUuid;
+    return this;
+  }
 }
index e26c0195f7771a21bf4470d7f0fcf438a1139edc..f3ca6235d3593f87df932299ff15325c6efca8d9 100644 (file)
@@ -90,6 +90,7 @@ public class IssueTesting {
       .setChangeData("data_" + randomAlphanumeric(40))
       .setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE)
       .setUserUuid("userUuid_" + randomAlphanumeric(40))
+      .setProjectUuid(issue.getProjectUuid())
       .setIssueChangeCreationDate(nextLong())
       .setCreatedAt(nextLong())
       .setUpdatedAt(nextLong());
index a86217c5d83019f3c5c879d1e01e6427fd03c1a2..e9a0af96f6da33e287069ea8cd414a0577d1a4c8 100644 (file)
@@ -29,6 +29,7 @@ import java.util.function.Predicate;
 import javax.annotation.Nullable;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
+import org.sonar.api.utils.TimeUtils;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.util.stream.MoreCollectors;
@@ -181,12 +182,26 @@ public class PurgeDao implements Dao {
     PurgeProfiler profiler = new PurgeProfiler();
     PurgeMapper purgeMapper = mapper(session);
     PurgeCommands purgeCommands = new PurgeCommands(session, profiler, system2);
+    long start = System2.INSTANCE.now();
 
     session.getMapper(BranchMapper.class).selectByProjectUuid(uuid).stream()
       .filter(branch -> !uuid.equals(branch.getUuid()))
       .forEach(branch -> deleteRootComponent(branch.getUuid(), purgeMapper, purgeCommands));
 
     deleteRootComponent(uuid, purgeMapper, purgeCommands);
+
+    logProfiling(profiler, start);
+  }
+
+  private static void logProfiling(PurgeProfiler profiler, long start) {
+    long duration = System.currentTimeMillis() - start;
+    LOG.info("");
+    LOG.info(" -------- Profiling for project deletion: " + TimeUtils.formatDuration(duration) + " --------");
+    LOG.info("");
+    profiler.dump(duration, LOG);
+    LOG.info("");
+    LOG.info(" -------- End of profiling for project deletion--------");
+    LOG.info("");
   }
 
   private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) {
index 285fbdb77e2eee8f1a628b8294319eb5f24a717f..7b934fbdb19bdb1340a3bc0cb73282c249346103 100644 (file)
     c.change_data as changeData,
     c.created_at as createdAt,
     c.updated_at as updatedAt,
+    c.project_uuid as projectUuid,
     c.issue_change_creation_date as issueChangeCreationDate
   </sql>
 
   <insert id="insert" useGeneratedKeys="false" parameterType="IssueChange">
     INSERT INTO issue_changes (kee, uuid, issue_key, user_login, change_type, change_data, created_at, updated_at,
-    issue_change_creation_date)
+    issue_change_creation_date, project_uuid)
     VALUES (#{kee,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{issueKey,jdbcType=VARCHAR}, #{userUuid,jdbcType=VARCHAR},
     #{changeType,jdbcType=VARCHAR}, #{changeData,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT},
-    #{updatedAt,jdbcType=BIGINT}, #{issueChangeCreationDate,jdbcType=BIGINT})
+    #{updatedAt,jdbcType=BIGINT}, #{issueChangeCreationDate,jdbcType=BIGINT}, #{projectUuid,jdbcType=VARCHAR})
   </insert>
 
   <delete id="delete" parameterType="string">
index c9cb7aad403c9d306c227416c8841e368be32dc8..9c854851d61faf57597ad7cdb9694391518e9899 100644 (file)
   </delete>
 
   <delete id="deleteIssueChangesByProjectUuid" parameterType="map">
-    delete from issue_changes ic
-    where
-      exists (select 1 from issues i where i.kee=ic.issue_key and i.project_uuid = #{projectUuid,jdbcType=VARCHAR})
-  </delete>
-
-  <!-- Mssql -->
-  <delete id="deleteIssueChangesByProjectUuid" databaseId="mssql" parameterType="map">
-    delete issue_changes from issue_changes
-    inner join issues on
-      issue_changes.issue_key=issues.kee
-    where
-      issues.project_uuid = #{projectUuid,jdbcType=VARCHAR}
+    delete from issue_changes where project_uuid = #{projectUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteIssuesByProjectUuid" parameterType="map">
index 6aeef610ffb23ef11ef6ab44332ff417f5a4eb20..9345fa56fba341a54f1bd2dc9c64cf2558fcb53e 100644 (file)
@@ -82,7 +82,7 @@ CREATE TABLE "ANALYSIS_PROPERTIES"(
     "ANALYSIS_UUID" VARCHAR(40) NOT NULL,
     "KEE" VARCHAR(512) NOT NULL,
     "TEXT_VALUE" VARCHAR(4000),
-    "CLOB_VALUE" CLOB(2147483647),
+    "CLOB_VALUE" CLOB,
     "IS_EMPTY" BOOLEAN NOT NULL,
     "CREATED_AT" BIGINT NOT NULL
 );
@@ -107,7 +107,7 @@ CREATE TABLE "CE_ACTIVITY"(
     "EXECUTION_TIME_MS" BIGINT,
     "ANALYSIS_UUID" VARCHAR(50),
     "ERROR_MESSAGE" VARCHAR(1000),
-    "ERROR_STACKTRACE" CLOB(2147483647),
+    "ERROR_STACKTRACE" CLOB,
     "ERROR_TYPE" VARCHAR(20),
     "WORKER_UUID" VARCHAR(40),
     "CREATED_AT" BIGINT NOT NULL,
@@ -297,7 +297,7 @@ CREATE INDEX "EVENTS_COMPONENT_UUID" ON "EVENTS"("COMPONENT_UUID");
 CREATE TABLE "FILE_SOURCES"(
     "PROJECT_UUID" VARCHAR(50) NOT NULL,
     "FILE_UUID" VARCHAR(50) NOT NULL,
-    "LINE_HASHES" CLOB(2147483647),
+    "LINE_HASHES" CLOB,
     "LINE_HASHES_VERSION" INTEGER,
     "DATA_HASH" VARCHAR(50),
     "SRC_HASH" VARCHAR(50),
@@ -357,7 +357,7 @@ CREATE TABLE "INTERNAL_PROPERTIES"(
     "KEE" VARCHAR(20) NOT NULL,
     "IS_EMPTY" BOOLEAN NOT NULL,
     "TEXT_VALUE" VARCHAR(4000),
-    "CLOB_VALUE" CLOB(2147483647),
+    "CLOB_VALUE" CLOB,
     "CREATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "INTERNAL_PROPERTIES" ADD CONSTRAINT "PK_INTERNAL_PROPERTIES" PRIMARY KEY("KEE");
@@ -371,11 +371,13 @@ CREATE TABLE "ISSUE_CHANGES"(
     "CHANGE_DATA" CLOB,
     "CREATED_AT" BIGINT,
     "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL
 );
 ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
 CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
 CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
+CREATE INDEX "ISSUE_CHANGES_PROJECT_UUID" ON "ISSUE_CHANGES"("PROJECT_UUID");
 
 CREATE TABLE "ISSUES"(
     "KEE" VARCHAR(50) NOT NULL,
@@ -713,7 +715,7 @@ CREATE TABLE "PROPERTIES"(
     "PROP_KEY" VARCHAR(512) NOT NULL,
     "IS_EMPTY" BOOLEAN NOT NULL,
     "TEXT_VALUE" VARCHAR(4000),
-    "CLOB_VALUE" CLOB(2147483647),
+    "CLOB_VALUE" CLOB,
     "CREATED_AT" BIGINT NOT NULL,
     "COMPONENT_UUID" VARCHAR(40),
     "UUID" VARCHAR(40) NOT NULL,
@@ -727,7 +729,7 @@ CREATE TABLE "QPROFILE_CHANGES"(
     "RULES_PROFILE_UUID" VARCHAR(255) NOT NULL,
     "CHANGE_TYPE" VARCHAR(20) NOT NULL,
     "USER_UUID" VARCHAR(255),
-    "CHANGE_DATA" CLOB(2147483647),
+    "CHANGE_DATA" CLOB,
     "CREATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "QPROFILE_CHANGES" ADD CONSTRAINT "PK_QPROFILE_CHANGES" PRIMARY KEY("KEE");
@@ -788,7 +790,7 @@ CREATE TABLE "RULES"(
     "PLUGIN_CONFIG_KEY" VARCHAR(200),
     "PLUGIN_NAME" VARCHAR(255) NOT NULL,
     "SCOPE" VARCHAR(20) NOT NULL,
-    "DESCRIPTION" CLOB(2147483647),
+    "DESCRIPTION" CLOB,
     "PRIORITY" INTEGER,
     "STATUS" VARCHAR(40),
     "LANGUAGE" VARCHAR(20),
@@ -813,7 +815,7 @@ CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME"
 
 CREATE TABLE "RULES_METADATA"(
     "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "NOTE_DATA" CLOB(2147483647),
+    "NOTE_DATA" CLOB,
     "NOTE_USER_UUID" VARCHAR(255),
     "NOTE_CREATED_AT" BIGINT,
     "NOTE_UPDATED_AT" BIGINT,
@@ -822,7 +824,7 @@ CREATE TABLE "RULES_METADATA"(
     "REMEDIATION_BASE_EFFORT" VARCHAR(20),
     "TAGS" VARCHAR(4000),
     "AD_HOC_NAME" VARCHAR(200),
-    "AD_HOC_DESCRIPTION" CLOB(2147483647),
+    "AD_HOC_DESCRIPTION" CLOB,
     "AD_HOC_SEVERITY" VARCHAR(10),
     "AD_HOC_TYPE" TINYINT,
     "CREATED_AT" BIGINT NOT NULL,
@@ -966,8 +968,8 @@ CREATE TABLE "WEBHOOK_DELIVERIES"(
     "SUCCESS" BOOLEAN NOT NULL,
     "HTTP_STATUS" INTEGER,
     "DURATION_MS" BIGINT NOT NULL,
-    "PAYLOAD" CLOB(2147483647) NOT NULL,
-    "ERROR_STACKTRACE" CLOB(2147483647),
+    "PAYLOAD" CLOB NOT NULL,
+    "ERROR_STACKTRACE" CLOB,
     "CREATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
index c88408917634cf7c1701c68e51d327ed9da7eec4..949cb77724b329aa15a7609a2e03a88353267b32 100644 (file)
@@ -133,16 +133,17 @@ public class IssueChangeDaoTest {
       .setIssueKey(issue.getKey())
       .setCreatedAt(1_500_000_000_000L)
       .setUpdatedAt(1_501_000_000_000L)
-      .setIssueChangeCreationDate(1_502_000_000_000L);
+      .setIssueChangeCreationDate(1_502_000_000_000L)
+      .setProjectUuid("project_uuid");
 
     underTest.insert(db.getSession(), changeDto);
     db.getSession().commit();
 
     assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList(issue.getKey())))
       .extracting(IssueChangeDto::getKey, IssueChangeDto::getUuid, IssueChangeDto::getIssueKey, IssueChangeDto::getChangeData, IssueChangeDto::getChangeType,
-        IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt)
+        IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt, IssueChangeDto::getProjectUuid)
       .containsExactlyInAnyOrder(
-        tuple("EFGH", "uuid", issue.getKey(), "Some text", TYPE_COMMENT, 1_502_000_000_000L, 1_500_000_000_000L, 1_501_000_000_000L));
+        tuple("EFGH", "uuid", issue.getKey(), "Some text", TYPE_COMMENT, 1_502_000_000_000L, 1_500_000_000_000L, 1_501_000_000_000L, "project_uuid"));
   }
 
   @Test
index f6cf672ba156d1a216380441fa52781d4747b799..6bed05223adef9b199f8edc299c57a48ff623b13 100644 (file)
@@ -33,7 +33,7 @@ public class IssueChangeDtoTest {
   public void create_from_comment() {
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
 
-    IssueChangeDto dto = IssueChangeDto.of(comment);
+    IssueChangeDto dto = IssueChangeDto.of(comment, "project_uuid");
 
     assertThat(dto.getChangeData()).isEqualTo("the comment");
     assertThat(dto.getChangeType()).isEqualTo("comment");
@@ -42,6 +42,7 @@ public class IssueChangeDtoTest {
     assertThat(dto.getIssueChangeCreationDate()).isNotNull();
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
     assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
+    assertThat(dto.getProjectUuid()).isEqualTo("project_uuid");
   }
 
   @Test
@@ -49,7 +50,7 @@ public class IssueChangeDtoTest {
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
     comment.setCreatedAt(parseDate("2015-01-13"));
 
-    IssueChangeDto dto = IssueChangeDto.of(comment);
+    IssueChangeDto dto = IssueChangeDto.of(comment, "project_uuid");
 
     assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
   }
@@ -61,7 +62,7 @@ public class IssueChangeDtoTest {
     diffs.setUserUuid("user_uuid");
     diffs.setCreationDate(parseDate("2015-01-13"));
 
-    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
+    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs, "project_uuid");
 
     assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
     assertThat(dto.getChangeType()).isEqualTo("diff");
@@ -70,6 +71,7 @@ public class IssueChangeDtoTest {
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
     assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
     assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
+    assertThat(dto.getProjectUuid()).isEqualTo("project_uuid");
   }
 
   @Test
@@ -79,7 +81,7 @@ public class IssueChangeDtoTest {
     diffs.setUserUuid("user_uuid");
     diffs.setCreationDate(parseDate("2015-01-13"));
 
-    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
+    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs, "project_uuid");
 
     assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
   }
@@ -149,7 +151,7 @@ public class IssueChangeDtoTest {
   @Test
   public void to_string() {
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
-    IssueChangeDto dto = IssueChangeDto.of(comment);
+    IssueChangeDto dto = IssueChangeDto.of(comment, "project_uuid");
     assertThat(dto.toString()).contains("ABCDE");
   }
 }
index 22f2e382d4403f1a104f836eda61b57ed40a2bd0..61b0116f5dc5a773ef1481d3724edddd94e8bb03 100644 (file)
@@ -48,6 +48,7 @@ public class IssueChangeMapperTest {
     dto.setCreatedAt(1_500_000_000_000L);
     dto.setUpdatedAt(1_500_000_000_000L);
     dto.setIssueChangeCreationDate(1_500_000_000_000L);
+    dto.setProjectUuid("project_uuid");
     underTest.insert(dto);
     dbTester.getSession().commit();
 
@@ -69,6 +70,7 @@ public class IssueChangeMapperTest {
     dto.setCreatedAt(1_500_000_000_000L);
     dto.setUpdatedAt(1_500_000_000_000L);
     dto.setIssueChangeCreationDate(1_500_000_000_000L);
+    dto.setProjectUuid("project_uuid");
 
     underTest.insert(dto);
     dbTester.getSession().commit();
index 036ff6c33ead8e20e588184ad2f153f1d855f60d..b69e6327341c830a99a438c436a301e09e3b264d 100644 (file)
@@ -478,7 +478,7 @@ public class IssueMapperTest {
     diffs.setDiff("status", previousStatus, nextStatus);
     IntStream.range(0, random.nextInt(3)).forEach(i -> diffs.setDiff("key_a" + i, "old_" + i, "new_" + i));
 
-    IssueChangeDto changeDto = IssueChangeDto.of(issue.getKey(), diffs);
+    IssueChangeDto changeDto = IssueChangeDto.of(issue.getKey(), diffs, issue.getProjectUuid());
     changeDto.setUuid(Uuids.createFast());
     dbTester.getDbClient().issueChangeDao().insert(dbSession, changeDto);
     return changeDto;
index 520b52b04ab857a3343c7b7bf985e4e862aa7bb6..c15459cb881d224c210ae209309fef7d31134867 100644 (file)
@@ -224,13 +224,13 @@ public class IssueDbTester {
   }
 
   public IssueChangeDto insertComment(IssueDto issueDto, @Nullable UserDto user, String text) {
-    IssueChangeDto issueChangeDto = IssueChangeDto.of(DefaultIssueComment.create(issueDto.getKey(), user == null ? null : user.getUuid(), text));
+    IssueChangeDto issueChangeDto = IssueChangeDto.of(DefaultIssueComment.create(issueDto.getKey(), user == null ? null : user.getUuid(), text), issueDto.getProjectUuid());
     issueChangeDto.setUuid(Uuids.create());
     return insertChange(issueChangeDto);
   }
 
   public void insertFieldDiffs(IssueDto issueDto, FieldDiffs... diffs) {
-    Arrays.stream(diffs).forEach(diff -> db.getDbClient().issueChangeDao().insert(db.getSession(), IssueChangeDto.of(issueDto.getKey(), diff)
+    Arrays.stream(diffs).forEach(diff -> db.getDbClient().issueChangeDao().insert(db.getSession(), IssueChangeDto.of(issueDto.getKey(), diff, issueDto.getProjectUuid())
     .setUuid(Uuids.createFast())));
     db.commit();
   }
index 6d25d6470bf0b37c9af0798f9d106fb133191ed8..17be9cc101f6afa47953651a9445e260ed7dbdaa 100644 (file)
@@ -48,9 +48,8 @@ public class ClobColumnDef extends AbstractColumnDef {
       case MsSql.ID:
         return "NVARCHAR (MAX)";
       case Oracle.ID:
-        return "CLOB";
       case H2.ID:
-        return "CLOB(2147483647)";
+        return "CLOB";
       case PostgreSql.ID:
         return "TEXT";
       default:
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTable.java
new file mode 100644 (file)
index 0000000..5261533
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnIssueKeyForIssueChangesTable extends DdlChange {
+
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_issue_key";
+
+  public AddIndexOnIssueKeyForIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists()) {
+      context.execute(new CreateIndexBuilder()
+        .setUnique(false)
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("issue_key")
+          .setIsNullable(false)
+          .setLimit(UUID_VARCHAR_SIZE)
+          .build())
+        .build());
+    }
+  }
+
+  private boolean indexExists() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTable.java
new file mode 100644 (file)
index 0000000..e06a2f2
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_VARCHAR_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnKeeForIssueChangesTable extends DdlChange {
+
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_kee";
+
+  public AddIndexOnKeeForIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists()) {
+      context.execute(new CreateIndexBuilder()
+        .setUnique(false)
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("kee")
+          .setIsNullable(true)
+          .setLimit(UUID_VARCHAR_SIZE)
+          .build())
+        .build());
+    }
+  }
+
+  private boolean indexExists() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTable.java
new file mode 100644 (file)
index 0000000..4e1b5bc
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnProjectUuidOnIssueChangesTable extends DdlChange {
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_project_uuid";
+
+  public AddIndexOnProjectUuidOnIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists()) {
+      context.execute(new CreateIndexBuilder()
+        .setUnique(false)
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("project_uuid")
+          .setIsNullable(true)
+          .setLimit(UUID_SIZE)
+          .build())
+        .build());
+    }
+  }
+
+  private boolean indexExists() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTable.java
new file mode 100644 (file)
index 0000000..2ba54f4
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidForIssueChangesTable extends DdlChange {
+
+  private static final String TABLE = "issue_changes";
+
+  public AddPrimaryKeyOnUuidForIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder(TABLE, "uuid").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTable.java
new file mode 100644 (file)
index 0000000..d1b336c
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.db.dialect.MsSql;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class CreateTmpIssueChangesTable extends DdlChange {
+
+  public CreateTmpIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+
+    String query;
+    if (getDatabase().getDialect().getId().equals(MsSql.ID)) {
+      query = "SELECT ic.uuid, ic.kee, ic.issue_key, ic.user_login, ic.change_type, " +
+        "ic.change_data, ic.created_at, ic.updated_at, ic.issue_change_creation_date, i.project_uuid " +
+        "INTO tmp_issue_changes " +
+        "FROM issue_changes AS ic inner join issues i on i.kee = ic.issue_key";
+    } else {
+      query = "create table tmp_issue_changes " +
+        "(uuid, kee, issue_key, user_login, change_type, change_data, created_at, updated_at, issue_change_creation_date, project_uuid)" +
+        "as (" +
+        "SELECT ic.uuid, ic.kee, ic.issue_key, ic.user_login, ic.change_type, ic.change_data, ic.created_at, ic.updated_at, ic.issue_change_creation_date, i.project_uuid " +
+        "FROM issue_changes ic " +
+        "inner join issues i on i.kee = ic.issue_key " +
+        ")";
+    }
+
+    context.execute(query);
+  }
+}
index 9d921d3bd1cef1881e32aa415ff7a8a8ac55e886..cf4917d8abe31801165706a4f69f09217a25a6a2 100644 (file)
@@ -21,8 +21,10 @@ package org.sonar.server.platform.db.migration.version.v85;
 
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
+import org.sonar.server.platform.db.migration.version.v84.issuechanges.DropIssueChangesTable;
 
 public class DbVersion85 implements DbVersion {
+
   @Override
   public void addSteps(MigrationStepRegistry registry) {
     registry
@@ -32,6 +34,16 @@ public class DbVersion85 implements DbVersion {
       .add(4003, "Drop unused variation values columns in 'project_measures' table", DropUnusedVariationsInProjectMeasures.class)
       .add(4004, "Drop unused periods in 'snapshots' table", DropUnusedPeriodsInSnapshots.class)
       .add(4005, "Drop orphan favorites from 'properties' table", DropOrphanFavoritesFromProperties.class)
+      .add(4006, "create 'tmp_issue_changes' table", CreateTmpIssueChangesTable.class)
+      .add(4007, "drop 'issue_changes' table", DropIssueChangesTable.class)
+      .add(4008, "rename 'tmp_issue_changes' table to 'issue_changes'", RenameTmpIssueChangesToIssueChanges.class)
+      .add(4009, "Make 'issueKey' not nullable for 'issue_changes' table", MakeIssueKeyNotNullOnIssueChangesTable.class)
+      .add(4010, "Make 'uuid' not nullable for 'issue_changes' table", MakeUuidNotNullOnIssueChangesTable.class)
+      .add(4011, "Make 'project_uuid' not nullable for 'issue_changes' table", MakeProjectUuidNotNullOnIssueChangesTable.class)
+      .add(4012, "add PK table to 'issue_changes'", AddPrimaryKeyOnUuidForIssueChangesTable.class)
+      .add(4013, "add index on 'issue_key' for table 'issue_changes'", AddIndexOnIssueKeyForIssueChangesTable.class)
+      .add(4014, "add index on 'kee' for table 'issue_changes'", AddIndexOnKeeForIssueChangesTable.class)
+      .add(4015, "add index on 'project_uuid' for table 'issue_changes'", AddIndexOnProjectUuidOnIssueChangesTable.class)
 
     ;
   }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTable.java
new file mode 100644 (file)
index 0000000..5c3df1e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeIssueKeyNotNullOnIssueChangesTable extends DdlChange {
+
+  private static final String TABLE = "issue_changes";
+
+  private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("issue_key")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
+    .build();
+
+  public MakeIssueKeyNotNullOnIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(columnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTable.java
new file mode 100644 (file)
index 0000000..4bb8763
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeProjectUuidNotNullOnIssueChangesTable extends DdlChange {
+
+  private static final String TABLE = "issue_changes";
+
+  private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("project_uuid")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
+    .build();
+
+  public MakeProjectUuidNotNullOnIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(columnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTable.java
new file mode 100644 (file)
index 0000000..3e68fb0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeUuidNotNullOnIssueChangesTable extends DdlChange {
+
+  private static final String TABLE = "issue_changes";
+
+  private static final VarcharColumnDef columnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public MakeUuidNotNullOnIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(columnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChanges.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChanges.java
new file mode 100644 (file)
index 0000000..f9f2f9b
--- /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.RenameTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class RenameTmpIssueChangesToIssueChanges extends DdlChange {
+
+  public RenameTmpIssueChangesToIssueChanges(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new RenameTableBuilder(getDialect())
+      .setName("tmp_issue_changes").setNewName("issue_changes")
+      .setAutoGeneratedId(false)
+      .build());
+  }
+}
index 3656b60ba6e999a931e3f78421caca01ca190176..806b05227dd64f425dcaa543da5b8ce4759cf6a5 100644 (file)
@@ -63,7 +63,7 @@ public class ClobColumnDefTest {
 
   @Test
   public void generate_sql_type_on_h2() {
-    assertThat(underTest.generateSqlType(new H2())).isEqualTo("CLOB(2147483647)");
+    assertThat(underTest.generateSqlType(new H2())).isEqualTo("CLOB");
   }
 
   @Test
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..2b95c23
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.DdlChange;
+
+public class AddIndexOnIssueKeyForIssueChangesTableTest {
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_issue_key";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnIssueKeyForIssueChangesTableTest.class, "schema.sql");
+
+  DdlChange underTest = new AddIndexOnIssueKeyForIssueChangesTable(db.database());
+
+  @Test
+  public void add_index() throws SQLException {
+    underTest.execute();
+    db.assertIndex(TABLE_NAME, INDEX_NAME, "issue_key");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..7ccffa8
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.DdlChange;
+
+public class AddIndexOnKeeForIssueChangesTableTest {
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_kee";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnKeeForIssueChangesTableTest.class, "schema.sql");
+
+  DdlChange underTest = new AddIndexOnKeeForIssueChangesTable(db.database());
+
+  @Test
+  public void add_index() throws SQLException {
+    underTest.execute();
+    db.assertIndex(TABLE_NAME, INDEX_NAME, "kee");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..b0ccee9
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.DdlChange;
+
+public class AddIndexOnProjectUuidOnIssueChangesTableTest {
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_project_uuid";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnProjectUuidOnIssueChangesTableTest.class, "schema.sql");
+
+  DdlChange underTest = new AddIndexOnProjectUuidOnIssueChangesTable(db.database());
+
+  @Test
+  public void add_index() throws SQLException {
+    underTest.execute();
+    db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid");
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..f63fe11
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidForIssueChangesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidForIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddPrimaryKeyOnUuidForIssueChangesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("issue_changes", "pk_issue_changes", "uuid");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..774f475
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.BIGINT;
+import static java.sql.Types.CLOB;
+import static java.sql.Types.VARCHAR;
+
+public class CreateTmpIssueChangesTableTest {
+
+  private static final String TABLE_NAME = "tmp_issue_changes";
+
+  @Rule
+  public CoreDbTester dbTester = CoreDbTester.createForSchema(CreateTmpIssueChangesTableTest.class, "schema.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private CreateTmpIssueChangesTable underTest = new CreateTmpIssueChangesTable(dbTester.database());
+
+  @Test
+  public void table_has_been_created() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertTableExists(TABLE_NAME);
+    dbTester.assertColumnDefinition(TABLE_NAME, "uuid", VARCHAR, 40, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "kee", VARCHAR, 50, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "issue_key", VARCHAR, 50, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "user_login", VARCHAR, 255, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "change_type", VARCHAR, 20, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "change_data", CLOB, null, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, null, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, null, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "issue_change_creation_date", BIGINT, null, true);
+    dbTester.assertColumnDefinition(TABLE_NAME, "project_uuid", VARCHAR, 50, true);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..ff04a03
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeIssueKeyNotNullOnIssueChangesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeIssueKeyNotNullOnIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeIssueKeyNotNullOnIssueChangesTable(db.database());
+
+  @Test
+  public void issue_key_column_is_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("issue_changes", "issue_key", VARCHAR, 50, false);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..d666fb0
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeProjectUuidNotNullOnIssueChangesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectUuidNotNullOnIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeProjectUuidNotNullOnIssueChangesTable(db.database());
+
+  @Test
+  public void issue_key_column_is_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("issue_changes", "project_uuid", VARCHAR, 50, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..107edc3
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeUuidNotNullOnIssueChangesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeUuidNotNullOnIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeUuidNotNullOnIssueChangesTable(db.database());
+
+  @Test
+  public void uuid_column_is_not_null() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("issue_changes", "uuid", VARCHAR, 40, false);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest.java
new file mode 100644 (file)
index 0000000..2a7777b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class RenameTmpIssueChangesToIssueChangesTest {
+
+  private static final String OLD_TABLE_NAME = "tmp_issue_changes";
+  private static final String NEW_TABLE_NAME = "issue_changes";
+
+  @Rule
+  public CoreDbTester dbTester = CoreDbTester.createForSchema(RenameTmpIssueChangesToIssueChangesTest.class, "schema.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private final RenameTmpIssueChangesToIssueChanges underTest = new RenameTmpIssueChangesToIssueChanges(dbTester.database());
+
+  @Test
+  public void table_has_been_renamed() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertTableDoesNotExist(OLD_TABLE_NAME);
+    dbTester.assertTableExists(NEW_TABLE_NAME);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..aaed9cd
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
+ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..46907cf
--- /dev/null
@@ -0,0 +1,14 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
+ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
+CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..7eb35b3
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
+ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
+CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
+CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..e712a96
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..24310fb
--- /dev/null
@@ -0,0 +1,53 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
+ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
+CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
+CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
+
+CREATE TABLE "ISSUES"(
+    "KEE" VARCHAR(50) NOT NULL,
+    "RULE_UUID" VARCHAR(40),
+    "SEVERITY" VARCHAR(10),
+    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+    "MESSAGE" VARCHAR(4000),
+    "LINE" INTEGER,
+    "GAP" DOUBLE,
+    "STATUS" VARCHAR(20),
+    "RESOLUTION" VARCHAR(20),
+    "CHECKSUM" VARCHAR(1000),
+    "REPORTER" VARCHAR(255),
+    "ASSIGNEE" VARCHAR(255),
+    "AUTHOR_LOGIN" VARCHAR(255),
+    "ACTION_PLAN_KEY" VARCHAR(50),
+    "ISSUE_ATTRIBUTES" VARCHAR(4000),
+    "EFFORT" INTEGER,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CREATION_DATE" BIGINT,
+    "ISSUE_UPDATE_DATE" BIGINT,
+    "ISSUE_CLOSE_DATE" BIGINT,
+    "TAGS" VARCHAR(4000),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROJECT_UUID" VARCHAR(50),
+    "LOCATIONS" BLOB,
+    "ISSUE_TYPE" TINYINT,
+    "FROM_HOTSPOT" BOOLEAN
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
+CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..79ecb88
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40),
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50),
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..917bb5a
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(40)
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..66c4146
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40),
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest/schema.sql
new file mode 100644 (file)
index 0000000..1051767
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "TMP_ISSUE_CHANGES"(
+    "UUID" VARCHAR(40),
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50),
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
+    "PROJECT_UUID" VARCHAR(50)
+);
index 348070a095311029af211cfdca696545eb7c82e1..28481cb57617655526856c4c93153e1ccb79dbf9 100644 (file)
@@ -30,21 +30,24 @@ public class IssueStorage {
   public void insertChanges(IssueChangeMapper mapper, DefaultIssue issue, UuidFactory uuidFactory) {
     for (DefaultIssueComment comment : issue.defaultIssueComments()) {
       if (comment.isNew()) {
-        IssueChangeDto changeDto = IssueChangeDto.of(comment);
+        IssueChangeDto changeDto = IssueChangeDto.of(comment, issue.projectUuid());
         changeDto.setUuid(uuidFactory.create());
+        changeDto.setProjectUuid(issue.projectUuid());
         mapper.insert(changeDto);
       }
     }
     FieldDiffs diffs = issue.currentChange();
     if (issue.isCopied()) {
       for (FieldDiffs d : issue.changes()) {
-        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), d);
+        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), d, issue.projectUuid());
         changeDto.setUuid(uuidFactory.create());
+        changeDto.setProjectUuid(issue.projectUuid());
         mapper.insert(changeDto);
       }
     } else if (!issue.isNew() && diffs != null) {
-      IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs);
+      IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs, issue.projectUuid());
       changeDto.setUuid(uuidFactory.create());
+      changeDto.setProjectUuid(issue.projectUuid());
       mapper.insert(changeDto);
     }
   }
index e04ffc28425205452e0cc839afee7cf4382be19a..6281e3f5147cb53f3a78273a13354a4d2d208552 100644 (file)
@@ -294,6 +294,7 @@ public class SearchActionTest {
         .setChangeData("*My comment*")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
         .setUserUuid(john.getUuid())
+        .setProjectUuid(project.projectUuid())
         .setIssueChangeCreationDate(parseDateTime("2014-09-09T12:00:00+0000").getTime()));
     dbClient.issueChangeDao().insert(session,
       new IssueChangeDto()
@@ -303,6 +304,7 @@ public class SearchActionTest {
         .setChangeData("Another comment")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
         .setUserUuid(fabrice.getUuid())
+        .setProjectUuid(project.projectUuid())
         .setIssueChangeCreationDate(parseDateTime("2014-09-10T12:00:00+0000").getTime()));
     session.commit();
     indexIssues();
@@ -331,6 +333,7 @@ public class SearchActionTest {
         .setChangeData("*My comment*")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
         .setUserUuid(john.getUuid())
+        .setProjectUuid(project.projectUuid())
         .setCreatedAt(parseDateTime("2014-09-09T12:00:00+0000").getTime()));
     dbClient.issueChangeDao().insert(session,
       new IssueChangeDto()
@@ -340,6 +343,7 @@ public class SearchActionTest {
         .setChangeData("Another comment")
         .setChangeType(IssueChangeDto.TYPE_COMMENT)
         .setUserUuid(fabrice.getUuid())
+        .setProjectUuid(project.projectUuid())
         .setCreatedAt(parseDateTime("2014-09-10T19:10:03+0000").getTime()));
     session.commit();
     indexIssues();