aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2020-09-03 15:55:54 +0200
committersonartech <sonartech@sonarsource.com>2020-09-08 20:07:13 +0000
commita6889467a2d97739df4329d41e7969327da2b8f8 (patch)
treeeb70c2ace9acc892124d584069119a9cfab3aba8
parent79960d4a9de4b9dfce800c45b24816d30bd0d4d3 (diff)
downloadsonarqube-a6889467a2d97739df4329d41e7969327da2b8f8.tar.gz
sonarqube-a6889467a2d97739df4329d41e7969327da2b8f8.zip
SONAR-12692 add project_uuid to issues_changes
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java22
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java15
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml5
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml13
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl26
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java7
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java12
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java4
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTable.java62
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTable.java62
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTable.java61
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTable.java39
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTable.java54
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java12
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTable.java51
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTable.java51
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTable.java51
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChanges.java40
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ClobColumnDefTest.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest.java61
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest.java44
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest.java44
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest.java49
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest/schema.sql13
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest/schema.sql14
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest/schema.sql15
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest/schema.sql12
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest/schema.sql53
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest/schema.sql12
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest/schema.sql12
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest/schema.sql12
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest/schema.sql12
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueStorage.java9
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java4
43 files changed, 1139 insertions, 45 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
index 7a7ac7761d1..ce13688d523 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDto.java
@@ -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;
+ }
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
index e26c0195f77..f3ca6235d35 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
@@ -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());
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index a86217c5d83..e9a0af96f6d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -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) {
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
index 285fbdb77e2..7b934fbdb19 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
@@ -13,15 +13,16 @@
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">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index c9cb7aad403..9c854851d61 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -276,18 +276,7 @@
</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">
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 6aeef610ffb..9345fa56fba 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -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");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
index c8840891763..949cb77724b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
@@ -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
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
index f6cf672ba15..6bed05223ad 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDtoTest.java
@@ -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");
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
index 22f2e382d44..61b0116f5dc 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
@@ -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();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
index 036ff6c33ea..b69e6327341 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
@@ -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;
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
index 520b52b04ab..c15459cb881 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
@@ -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();
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
index 6d25d6470bf..17be9cc101f 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
@@ -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
index 00000000000..5261533fa29
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTable.java
@@ -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
index 00000000000..e06a2f25d0b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTable.java
@@ -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
index 00000000000..4e1b5bc8386
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTable.java
@@ -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
index 00000000000..2ba54f4a737
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTable.java
@@ -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
index 00000000000..d1b336c4a46
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTable.java
@@ -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);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
index 9d921d3bd1c..cf4917d8abe 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
@@ -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
index 00000000000..5c3df1e108d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTable.java
@@ -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
index 00000000000..4bb8763515a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTable.java
@@ -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
index 00000000000..3e68fb065da
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTable.java
@@ -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
index 00000000000..f9f2f9b1bbe
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChanges.java
@@ -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());
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ClobColumnDefTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ClobColumnDefTest.java
index 3656b60ba6e..806b05227dd 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ClobColumnDefTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/def/ClobColumnDefTest.java
@@ -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
index 00000000000..2b95c234882
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest.java
@@ -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
index 00000000000..7ccffa8081f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest.java
@@ -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
index 00000000000..b0ccee9ebf8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest.java
@@ -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
index 00000000000..f63fe114d6e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest.java
@@ -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
index 00000000000..774f475b52a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest.java
@@ -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
index 00000000000..ff04a030cdb
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest.java
@@ -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
index 00000000000..d666fb0d090
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest.java
@@ -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
index 00000000000..107edc38252
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest.java
@@ -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
index 00000000000..2a7777bd27d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest.java
@@ -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
index 00000000000..aaed9cd5d0a
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnIssueKeyForIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..46907cf96eb
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnKeeForIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..7eb35b38156
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnProjectUuidOnIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..e712a9619ab
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddPrimaryKeyOnUuidForIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..24310fbc986
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/CreateTmpIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..79ecb88e3e8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeIssueKeyNotNullOnIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..917bb5a92fe
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeProjectUuidNotNullOnIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..66c414690f3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeUuidNotNullOnIssueChangesTableTest/schema.sql
@@ -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
index 00000000000..105176773ed
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/RenameTmpIssueChangesToIssueChangesTest/schema.sql
@@ -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)
+);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueStorage.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueStorage.java
index 348070a0953..28481cb5761 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueStorage.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueStorage.java
@@ -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);
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
index e04ffc28425..6281e3f5147 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
@@ -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();