@@ -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; | |||
} | |||
} |
@@ -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()); |
@@ -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) { |
@@ -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"> |
@@ -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"> |
@@ -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"); |
@@ -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 |
@@ -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"); | |||
} | |||
} |
@@ -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(); |
@@ -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; |
@@ -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(); | |||
} |
@@ -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: |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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) | |||
; | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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 |
@@ -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"); | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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"); |
@@ -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"); |
@@ -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"); |
@@ -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) | |||
); |
@@ -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"); |
@@ -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) | |||
); |
@@ -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) | |||
); |
@@ -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) | |||
); |
@@ -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) | |||
); |
@@ -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); | |||
} | |||
} |
@@ -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(); |