From 1457934dc1e472cfd7d22fe098ee8bc2a1141511 Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 22 Feb 2022 16:00:47 +0100 Subject: [PATCH] SONAR-7496 drop unused columns on Issues table --- .../projectanalysis/issue/IssueLifecycle.java | 1 - .../util/cache/ProtobufIssueDiskCache.java | 2 - .../projectexport/issue/ExportIssuesStep.java | 13 ++--- .../src/main/protobuf/issue_cache.proto | 1 - .../src/main/protobuf/project_dump.proto | 2 +- .../issue/IssueLifecycleTest.java | 19 ------- .../issue/ExportIssuesStepTest.java | 2 - .../java/org/sonar/db/issue/IssueDto.java | 17 ------ .../org/sonar/db/issue/IssueMapper.xml | 7 +-- server/sonar-db-dao/src/schema/schema-sq.ddl | 3 - .../java/org/sonar/db/issue/IssueDaoTest.java | 2 - .../java/org/sonar/db/issue/IssueDtoTest.java | 25 ++------ .../org/sonar/db/issue/IssueMapperTest.java | 4 -- .../MigrationConfigurationModule.java | 2 + .../version/v94/AbstractDropColumn.java | 57 +++++++++++++++++++ .../db/migration/version/v94/DbVersion94.java | 35 ++++++++++++ .../v94/DropActionPlanKeyIssueColumn.java | 32 +++++++++++ .../v94/DropIssuesAttributesIssueColumn.java | 33 +++++++++++ .../version/v94/DropReporterIssueColumn.java | 33 +++++++++++ .../migration/version/v94/package-info.java | 24 ++++++++ .../version/v94/DbVersion94Test.java | 41 +++++++++++++ .../v94/DropActionPlanKeyIssueColumnTest.java | 55 ++++++++++++++++++ .../DropIssuesAttributesIssueColumnTest.java | 55 ++++++++++++++++++ .../v94/DropReporterIssueColumnTest.java | 56 ++++++++++++++++++ .../schema.sql | 37 ++++++++++++ .../schema.sql | 36 ++++++++++++ .../DropReporterIssueColumnTest/schema.sql | 38 +++++++++++++ .../sonar/server/issue/IssueFieldsSetter.java | 12 ---- .../server/issue/IssueFieldsSetterTest.java | 31 ---------- .../issue/index/IssueIteratorFactoryTest.java | 6 +- .../server/issue/WebIssueStorageTest.java | 4 -- .../org/sonar/core/issue/DefaultIssue.java | 36 ++++-------- .../sonar/core/issue/DefaultIssueTest.java | 23 -------- .../main/java/org/sonar/api/issue/Issue.java | 8 +++ 34 files changed, 565 insertions(+), 187 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/AbstractDropColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumn.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/package-info.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94Test.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest/schema.sql diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycle.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycle.java index b57b06cbd00..9c369e4c511 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycle.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycle.java @@ -214,7 +214,6 @@ public class IssueLifecycle { toIssue.setAssigneeUuid(fromIssue.assignee()); toIssue.setAuthorLogin(fromIssue.authorLogin()); toIssue.setTags(fromIssue.tags()); - toIssue.setAttributes(fromIssue.attributes()); toIssue.setEffort(debtCalculator.calculate(toIssue)); toIssue.setOnDisabledRule(fromIssue.isOnDisabledRule()); toIssue.setSelectedAt(fromIssue.selectedAt()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java index 32abede0c89..452751ba1ce 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java @@ -112,7 +112,6 @@ public class ProtobufIssueDiskCache implements DiskCache { defaultIssue.setResolution(next.hasResolution() ? next.getResolution() : null); defaultIssue.setAssigneeUuid(next.hasAssigneeUuid() ? next.getAssigneeUuid() : null); defaultIssue.setChecksum(next.hasChecksum() ? next.getChecksum() : null); - defaultIssue.setAttributes(next.getAttributesMap()); defaultIssue.setAuthorLogin(next.hasAuthorLogin() ? next.getAuthorLogin() : null); next.getCommentsList().forEach(c -> defaultIssue.addComment(toDefaultIssueComment(c))); defaultIssue.setTags(ImmutableSet.copyOf(TAGS_SPLITTER.split(next.getTags()))); @@ -163,7 +162,6 @@ public class ProtobufIssueDiskCache implements DiskCache { ofNullable(defaultIssue.resolution()).ifPresent(builder::setResolution); ofNullable(defaultIssue.assignee()).ifPresent(builder::setAssigneeUuid); ofNullable(defaultIssue.checksum()).ifPresent(builder::setChecksum); - ofNullable(defaultIssue.attributes()).ifPresent(builder::putAllAttributes); ofNullable(defaultIssue.authorLogin()).ifPresent(builder::setAuthorLogin); defaultIssue.defaultIssueComments().forEach(c -> builder.addComments(toProtoComment(c))); ofNullable(defaultIssue.tags()).ifPresent(t -> builder.setTags(String.join(TAGS_SEPARATOR, t))); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java index 4aff16330fb..0351bd6c1a0 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStep.java @@ -55,7 +55,7 @@ public class ExportIssuesStep implements ComputationStep { " i.kee, r.uuid, r.plugin_rule_key, r.plugin_name, i.issue_type," + " i.component_uuid, i.message, i.line, i.checksum, i.status," + " i.resolution, i.severity, i.manual_severity, i.gap, effort," + - " i.assignee, i.author_login, i.tags, i.issue_attributes, i.issue_creation_date," + + " i.assignee, i.author_login, i.tags, i.issue_creation_date," + " i.issue_update_date, i.issue_close_date, i.locations, i.project_uuid" + " from issues i" + " join rules r on r.uuid = i.rule_uuid and r.status <> ?" + @@ -140,11 +140,10 @@ public class ExportIssuesStep implements ComputationStep { .setAssignee(emptyIfNull(rs, 16)) .setAuthor(emptyIfNull(rs, 17)) .setTags(emptyIfNull(rs, 18)) - .setAttributes(emptyIfNull(rs, 19)) - .setIssueCreatedAt(rs.getLong(20)) - .setIssueUpdatedAt(rs.getLong(21)) - .setIssueClosedAt(rs.getLong(22)) - .setProjectUuid(rs.getString(24)); + .setIssueCreatedAt(rs.getLong(19)) + .setIssueUpdatedAt(rs.getLong(20)) + .setIssueClosedAt(rs.getLong(21)) + .setProjectUuid(rs.getString(23)); setLocations(builder, rs, issueUuid); return builder.build(); } @@ -158,7 +157,7 @@ public class ExportIssuesStep implements ComputationStep { private static void setLocations(ProjectDump.Issue.Builder builder, ResultSet rs, String issueUuid) throws SQLException { try { - byte[] bytes = rs.getBytes(23); + byte[] bytes = rs.getBytes(22); if (bytes != null) { // fail fast, ensure we can read data from DB DbIssues.Locations.parseFrom(bytes); diff --git a/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto b/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto index 29bce80c281..dbd6942998a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto +++ b/server/sonar-ce-task-projectanalysis/src/main/protobuf/issue_cache.proto @@ -49,7 +49,6 @@ message Issue { optional string resolution = 18; optional string assigneeUuid = 19; optional string checksum = 20; - map attributes = 21; optional string authorLogin = 22; optional string tags = 23; optional sonarqube.db.issues.Locations locations = 24; diff --git a/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto b/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto index 170f8a48b6e..358d1041e0b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto +++ b/server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto @@ -114,7 +114,7 @@ message Issue { string author = 16; string tags = 17; - string attributes = 18; + // issue dates int64 issue_created_at = 19; int64 issue_updated_at = 20; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycleTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycleTest.java index 5982891b32d..c1f1e06bfff 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycleTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueLifecycleTest.java @@ -19,7 +19,6 @@ */ package org.sonar.ce.task.projectanalysis.issue; -import com.google.common.collect.ImmutableMap; import java.util.Date; import org.junit.Rule; import org.junit.Test; @@ -415,22 +414,4 @@ public class IssueLifecycleTest { assertThat(raw.isChanged()).isTrue(); } - - @Test - public void mergeExistingOpenIssue_with_attributes() { - DefaultIssue raw = new DefaultIssue() - .setNew(true) - .setKey("RAW_KEY") - .setRuleKey(XOO_X1); - DefaultIssue base = new DefaultIssue() - .setKey("BASE_KEY") - .setResolution(RESOLUTION_FIXED) - .setStatus(STATUS_CLOSED) - .setSeverity(BLOCKER) - .setAttributes(ImmutableMap.of("JIRA", "SONAR-01")); - - underTest.mergeExistingOpenIssue(raw, base); - - assertThat(raw.attributes()).containsEntry("JIRA", "SONAR-01"); - } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java index 8b39c16f368..2a3214ae047 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java @@ -219,7 +219,6 @@ public class ExportIssuesStepTest { .setAssigneeUuid("assignee-uuid") .setAuthorLogin("author") .setTagsString("tags") - .setIssueAttributes("attributes") .setIssueCreationTime(963L) .setIssueUpdateTime(852L) .setIssueCloseTime(741L); @@ -252,7 +251,6 @@ public class ExportIssuesStepTest { assertThat(issue.getAssignee()).isEqualTo(issueDto.getAssigneeUuid()); assertThat(issue.getAuthor()).isEqualTo(issueDto.getAuthorLogin()); assertThat(issue.getTags()).isEqualTo(issueDto.getTagsString()); - assertThat(issue.getAttributes()).isEqualTo(issueDto.getIssueAttributes()); assertThat(issue.getIssueCreatedAt()).isEqualTo(issueDto.getIssueCreationTime()); assertThat(issue.getIssueUpdatedAt()).isEqualTo(issueDto.getIssueUpdateTime()); assertThat(issue.getIssueClosedAt()).isEqualTo(issueDto.getIssueCloseTime()); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index 1bc4e5f0b60..a4a97c4c7de 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -20,7 +20,6 @@ package org.sonar.db.issue; import com.google.common.base.Joiner; -import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; @@ -37,7 +36,6 @@ import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; -import org.sonar.api.utils.KeyValueFormat; import org.sonar.core.issue.DefaultIssue; import org.sonar.db.component.ComponentDto; import org.sonar.db.protobuf.DbIssues; @@ -71,7 +69,6 @@ public final class IssueDto implements Serializable { private String assigneeUuid; private String assigneeLogin; private String authorLogin; - private String issueAttributes; private String securityStandards; private byte[] locations; private long createdAt; @@ -135,7 +132,6 @@ public final class IssueDto implements Serializable { .setModuleUuidPath(issue.moduleUuidPath()) .setProjectUuid(issue.projectUuid()) .setProjectKey(issue.projectKey()) - .setIssueAttributes(KeyValueFormat.format(issue.attributes())) .setAuthorLogin(issue.authorLogin()) .setIssueCreationDate(issue.creationDate()) .setIssueCloseDate(issue.closeDate()) @@ -175,7 +171,6 @@ public final class IssueDto implements Serializable { .setChecksum(issue.checksum()) .setManualSeverity(issue.manualSeverity()) .setAssigneeUuid(issue.assignee()) - .setIssueAttributes(KeyValueFormat.format(issue.attributes())) .setAuthorLogin(issue.authorLogin()) .setRuleKey(issue.ruleKey().repository(), issue.ruleKey().rule()) .setExternal(issue.isFromExternalRuleEngine()) @@ -365,17 +360,6 @@ public final class IssueDto implements Serializable { return this; } - @CheckForNull - public String getIssueAttributes() { - return issueAttributes; - } - - public IssueDto setIssueAttributes(@Nullable String s) { - checkArgument(s == null || s.length() <= 4000, "Value is too long for issue attributes: %s", s); - this.issueAttributes = s; - return this; - } - public IssueDto setSecurityStandards(@Nullable String s) { this.securityStandards = s; return this; @@ -751,7 +735,6 @@ public final class IssueDto implements Serializable { issue.setChecksum(checksum); issue.setSeverity(severity); issue.setAssigneeUuid(assigneeUuid); - issue.setAttributes(KeyValueFormat.parse(MoreObjects.firstNonNull(issueAttributes, ""))); issue.setComponentKey(componentKey); issue.setComponentUuid(componentUuid); issue.setModuleUuid(moduleUuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml index 6f96b1ff854..5a64c24b5ea 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml @@ -20,7 +20,6 @@ i.assignee as assigneeUuid, i.author_login as authorLogin, i.tags as tagsString, - i.issue_attributes as issueAttributes, i.issue_creation_date as issueCreationTime, i.issue_update_date as issueUpdateTime, i.issue_close_date as issueCloseTime, @@ -59,7 +58,6 @@ i.assignee, i.author_login, i.tags, - i.issue_attributes, i.issue_creation_date, i.issue_update_date, i.issue_close_date, @@ -109,7 +107,7 @@ INSERT INTO issues (kee, rule_uuid, severity, manual_severity, message, line, locations, gap, effort, status, tags, - resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, + resolution, checksum, assignee, author_login, issue_creation_date, issue_update_date, issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type, quick_fix_available) VALUES ( #{kee,jdbcType=VARCHAR}, @@ -122,7 +120,6 @@ #{checksum,jdbcType=VARCHAR}, #{assigneeUuid,jdbcType=VARCHAR}, #{authorLogin,jdbcType=VARCHAR}, - #{issueAttributes,jdbcType=VARCHAR}, #{issueCreationTime,jdbcType=BIGINT},#{issueUpdateTime,jdbcType=BIGINT}, #{issueCloseTime,jdbcType=BIGINT}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{componentUuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, @@ -161,7 +158,6 @@ author_login=#{authorLogin,jdbcType=VARCHAR}, tags=#{tagsString,jdbcType=VARCHAR}, project_uuid=#{projectUuid,jdbcType=VARCHAR}, - issue_attributes=#{issueAttributes,jdbcType=VARCHAR}, issue_creation_date=#{issueCreationTime,jdbcType=BIGINT}, issue_update_date=#{issueUpdateTime,jdbcType=BIGINT}, issue_close_date=#{issueCloseTime,jdbcType=BIGINT}, @@ -190,7 +186,6 @@ tags=#{tagsString,jdbcType=VARCHAR}, component_uuid=#{componentUuid,jdbcType=VARCHAR}, project_uuid=#{projectUuid,jdbcType=VARCHAR}, - issue_attributes=#{issueAttributes,jdbcType=VARCHAR}, issue_creation_date=#{issueCreationTime,jdbcType=BIGINT}, issue_update_date=#{issueUpdateTime,jdbcType=BIGINT}, issue_close_date=#{issueCloseTime,jdbcType=BIGINT}, diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index cea68962a96..7d0350a8626 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -411,11 +411,8 @@ CREATE TABLE "ISSUES"( "STATUS" CHARACTER VARYING(20), "RESOLUTION" CHARACTER VARYING(20), "CHECKSUM" CHARACTER VARYING(1000), - "REPORTER" CHARACTER VARYING(255), "ASSIGNEE" CHARACTER VARYING(255), "AUTHOR_LOGIN" CHARACTER VARYING(255), - "ACTION_PLAN_KEY" CHARACTER VARYING(50), - "ISSUE_ATTRIBUTES" CHARACTER VARYING(4000), "EFFORT" INTEGER, "CREATED_AT" BIGINT, "UPDATED_AT" BIGINT, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 23210072dcf..094d5023745 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -93,7 +93,6 @@ public class IssueDaoTest { assertThat(issue.getChecksum()).isEqualTo("123456789"); assertThat(issue.getAuthorLogin()).isEqualTo("morgan"); assertThat(issue.getAssigneeUuid()).isEqualTo("karadoc"); - assertThat(issue.getIssueAttributes()).isEqualTo("JIRA=FOO-1234"); assertThat(issue.getIssueCreationDate()).isNotNull(); assertThat(issue.getIssueUpdateDate()).isNotNull(); assertThat(issue.getIssueCloseDate()).isNotNull(); @@ -488,7 +487,6 @@ public class IssueDaoTest { dto.setSeverity("BLOCKER"); dto.setAuthorLogin("morgan"); dto.setAssigneeUuid("karadoc"); - dto.setIssueAttributes("JIRA=FOO-1234"); dto.setChecksum("123456789"); dto.setMessage("the message"); dto.setCreatedAt(1_440_000_000_000L); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java index a709ea2620e..bd153ec25ce 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java @@ -39,20 +39,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; public class IssueDtoTest { - - @Test - public void set_data_check_maximal_length() { - assertThatThrownBy(() -> { - StringBuilder s = new StringBuilder(4500); - for (int i = 0; i < 4500; i++) { - s.append('a'); - } - new IssueDto().setIssueAttributes(s.toString()); - }) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Value is too long for issue attributes:"); - } - @Test public void set_issue_fields() { Date createdAt = DateUtils.addDays(new Date(), -5); @@ -80,7 +66,6 @@ public class IssueDtoTest { .setMessage("message") .setManualSeverity(true) .setAssigneeUuid("perceval") - .setIssueAttributes("key=value") .setAuthorLogin("pierre") .setIssueCreationDate(createdAt) .setIssueUpdateDate(updatedAt) @@ -106,7 +91,6 @@ public class IssueDtoTest { assertThat(issue.message()).isEqualTo("message"); assertThat(issue.manualSeverity()).isTrue(); assertThat(issue.assignee()).isEqualTo("perceval"); - assertThat(issue.attribute("key")).isEqualTo("value"); assertThat(issue.authorLogin()).isEqualTo("pierre"); assertThat(issue.creationDate()).isEqualTo(DateUtils.truncate(createdAt, Calendar.SECOND)); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(updatedAt, Calendar.SECOND)); @@ -177,10 +161,10 @@ public class IssueDtoTest { assertThat(issueDto).extracting(IssueDto::isManualSeverity, IssueDto::getChecksum, IssueDto::getAssigneeUuid, IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey, IssueDto::getModuleUuid, - IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey, IssueDto::getIssueAttributes, + IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey, IssueDto::getRuleUuid) .containsExactly(true, "123", "123", true, "123", "componentKey", "moduleUuid", - "path/to/module/uuid", "123", "projectKey", "key=value", "ruleUuid"); + "path/to/module/uuid", "123", "projectKey", "ruleUuid"); assertThat(issueDto.isQuickFixAvailable()).isTrue(); assertThat(issueDto.isNewCodeReferenceIssue()).isTrue(); @@ -210,9 +194,9 @@ public class IssueDtoTest { assertThat(issueDto).extracting(IssueDto::isManualSeverity, IssueDto::getChecksum, IssueDto::getAssigneeUuid, IssueDto::isExternal, IssueDto::getComponentUuid, IssueDto::getComponentKey, IssueDto::getModuleUuid, - IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey, IssueDto::getIssueAttributes) + IssueDto::getModuleUuidPath, IssueDto::getProjectUuid, IssueDto::getProjectKey) .containsExactly(true, "123", "123", true, "123", "componentKey", "moduleUuid", - "path/to/module/uuid", "123", "projectKey", "key=value"); + "path/to/module/uuid", "123", "projectKey"); assertThat(issueDto.isQuickFixAvailable()).isTrue(); assertThat(issueDto.isNewCodeReferenceIssue()).isTrue(); @@ -241,7 +225,6 @@ public class IssueDtoTest { .setModuleUuidPath("path/to/module/uuid") .setProjectUuid("123") .setProjectKey("projectKey") - .setAttribute("key", "value") .setAuthorLogin("admin") .setCreationDate(dateNow) .setCloseDate(dateNow) 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 913af6ec668..b50f7de1d43 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 @@ -102,7 +102,6 @@ public class IssueMapperTest { assertThat(result.getSeverity()).isEqualTo("BLOCKER"); assertThat(result.getAuthorLogin()).isEqualTo("morgan"); assertThat(result.getAssigneeUuid()).isEqualTo("karadoc"); - assertThat(result.getIssueAttributes()).isEqualTo("JIRA=FOO-1234"); assertThat(result.getChecksum()).isEqualTo("123456789"); assertThat(result.getMessage()).isEqualTo("the message"); assertThat(result.getIssueCreationTime()).isEqualTo(1_401_000_000_000L); @@ -132,7 +131,6 @@ public class IssueMapperTest { update.setSeverity("BLOCKER"); update.setAuthorLogin("morgan"); update.setAssigneeUuid("karadoc"); - update.setIssueAttributes("JIRA=FOO-1234"); update.setChecksum("123456789"); update.setMessage("the message"); @@ -161,7 +159,6 @@ public class IssueMapperTest { assertThat(result.getSeverity()).isEqualTo("BLOCKER"); assertThat(result.getAuthorLogin()).isEqualTo("morgan"); assertThat(result.getAssigneeUuid()).isEqualTo("karadoc"); - assertThat(result.getIssueAttributes()).isEqualTo("JIRA=FOO-1234"); assertThat(result.getChecksum()).isEqualTo("123456789"); assertThat(result.getMessage()).isEqualTo("the message"); assertThat(result.getIssueCreationTime()).isEqualTo(1_550_000_000_000L); @@ -538,7 +535,6 @@ public class IssueMapperTest { .setSeverity("BLOCKER") .setAuthorLogin("morgan") .setAssigneeUuid("karadoc") - .setIssueAttributes("JIRA=FOO-1234") .setChecksum("123456789") .setMessage("the message") .setIssueCreationTime(1_401_000_000_000L) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index a6e8762c030..2561b5aa59b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -32,6 +32,7 @@ import org.sonar.server.platform.db.migration.version.v90.DbVersion90; import org.sonar.server.platform.db.migration.version.v91.DbVersion91; import org.sonar.server.platform.db.migration.version.v92.DbVersion92; import org.sonar.server.platform.db.migration.version.v93.DbVersion93; +import org.sonar.server.platform.db.migration.version.v94.DbVersion94; public class MigrationConfigurationModule extends Module { @Override @@ -44,6 +45,7 @@ public class MigrationConfigurationModule extends Module { DbVersion91.class, DbVersion92.class, DbVersion93.class, + DbVersion94.class, // migration steps MigrationStepRegistryImpl.class, diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/AbstractDropColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/AbstractDropColumn.java new file mode 100644 index 00000000000..be598019140 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/AbstractDropColumn.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public abstract class AbstractDropColumn extends DdlChange { + + private final String tableName; + private final String columnName; + + protected AbstractDropColumn(Database db, String tableName, String columnName) { + super(db); + this.tableName = tableName; + this.columnName = columnName; + } + + @Override + public void execute(DdlChange.Context context) throws SQLException { + if (!checkIfUseManagedColumnExists()) { + return; + } + + context.execute(new DropColumnsBuilder(getDatabase().getDialect(), tableName, columnName).build()); + } + + private boolean checkIfUseManagedColumnExists() throws SQLException { + try (var connection = getDatabase().getDataSource().getConnection()) { + if (DatabaseUtils.tableColumnExists(connection, tableName, columnName)) { + return true; + } + } + return false; + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java new file mode 100644 index 00000000000..2d72af9b026 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; +import org.sonar.server.platform.db.migration.version.DbVersion; + +public class DbVersion94 implements DbVersion { + @Override + public void addSteps(MigrationStepRegistry registry) { + registry + .add(6301, "Drop unused Issues Column REPORTER", DropReporterIssueColumn.class) + .add(6302, "Drop unused Issues Column ACTION_PLAN_KEY", DropActionPlanKeyIssueColumn.class) + .add(6303, "Drop unused Issues Column ISSUE_ATTRIBUTES", DropIssuesAttributesIssueColumn.class) + + ; + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumn.java new file mode 100644 index 00000000000..9ba82a50b66 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumn.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import org.sonar.db.Database; + +public class DropActionPlanKeyIssueColumn extends AbstractDropColumn { + + public static final String TABLE_NAME = "issues"; + public static final String COLUMN_NAME = "action_plan_key"; + + public DropActionPlanKeyIssueColumn(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumn.java new file mode 100644 index 00000000000..973631039e9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumn.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import org.sonar.db.Database; + +public class DropIssuesAttributesIssueColumn extends AbstractDropColumn{ + + public static final String TABLE_NAME = "issues"; + public static final String COLUMN_NAME = "issue_attributes"; + + public DropIssuesAttributesIssueColumn(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumn.java new file mode 100644 index 00000000000..90493089189 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumn.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import org.sonar.db.Database; + +public class DropReporterIssueColumn extends AbstractDropColumn { + + public static final String TABLE_NAME = "issues"; + public static final String COLUMN_NAME = "reporter"; + + public DropReporterIssueColumn(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/package-info.java new file mode 100644 index 00000000000..b593ed7972f --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v94/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.platform.db.migration.version.v94; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94Test.java new file mode 100644 index 00000000000..b5782987b3d --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DbVersion94Test.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import org.junit.Test; + +import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty; +import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; + +public class DbVersion94Test { + + private final DbVersion94 underTest = new DbVersion94(); + + @Test + public void migrationNumber_starts_at_6301() { + verifyMinimumMigrationNumber(underTest, 6301); + } + + @Test + public void verify_migration_count() { + verifyMigrationNotEmpty(underTest); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest.java new file mode 100644 index 00000000000..e935d8d69ff --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropActionPlanKeyIssueColumnTest { + + private static final String COLUMN_NAME = "action_plan_key"; + private static final String TABLE_NAME = "issues"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropActionPlanKeyIssueColumnTest.class, "schema.sql"); + + private final DdlChange underTest = new DropActionPlanKeyIssueColumn(db.database()); + + @Test + public void migration_should_drop_action_plan_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + // re-entrant + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest.java new file mode 100644 index 00000000000..a8f284019da --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIssuesAttributesIssueColumnTest { + + private static final String COLUMN_NAME = "issue_attributes"; + private static final String TABLE_NAME = "issues"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropIssuesAttributesIssueColumnTest.class, "schema.sql"); + + private final DdlChange underTest = new DropIssuesAttributesIssueColumn(db.database()); + + @Test + public void migration_should_drop_action_plan_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true); + underTest.execute(); + // re-entrant + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest.java new file mode 100644 index 00000000000..a0b4618ec09 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.v94; + +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import java.sql.SQLException; +import java.sql.Types; + +public class DropReporterIssueColumnTest { + + private static final String COLUMN_NAME = "reporter"; + private static final String TABLE_NAME = "issues"; + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropReporterIssueColumnTest.class, "schema.sql"); + + private final DdlChange underTest = new DropReporterIssueColumn(db.database()); + + @Test + public void migration_should_drop_action_plan_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, true); + underTest.execute(); + // re-entrant + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest/schema.sql new file mode 100644 index 00000000000..f3934afa6ae --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropActionPlanKeyIssueColumnTest/schema.sql @@ -0,0 +1,37 @@ +CREATE TABLE "ISSUES"( + "KEE" CHARACTER VARYING(50) NOT NULL, + "RULE_UUID" CHARACTER VARYING(40), + "SEVERITY" CHARACTER VARYING(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" CHARACTER VARYING(4000), + "LINE" INTEGER, + "GAP" DOUBLE PRECISION, + "STATUS" CHARACTER VARYING(20), + "RESOLUTION" CHARACTER VARYING(20), + "CHECKSUM" CHARACTER VARYING(1000), + "ASSIGNEE" CHARACTER VARYING(255), + "AUTHOR_LOGIN" CHARACTER VARYING(255), + "ACTION_PLAN_KEY" CHARACTER VARYING(50), + "ISSUE_ATTRIBUTES" CHARACTER VARYING(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" CHARACTER VARYING(4000), + "COMPONENT_UUID" CHARACTER VARYING(50), + "PROJECT_UUID" CHARACTER VARYING(50), + "LOCATIONS" BINARY LARGE OBJECT, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN, + "QUICK_FIX_AVAILABLE" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE" NULLS FIRST); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID" NULLS FIRST); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE" NULLS FIRST); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID" NULLS FIRST); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION" NULLS FIRST); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT" NULLS FIRST); +CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID" NULLS FIRST); \ No newline at end of file diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest/schema.sql new file mode 100644 index 00000000000..17635b54148 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropIssuesAttributesIssueColumnTest/schema.sql @@ -0,0 +1,36 @@ +CREATE TABLE "ISSUES"( + "KEE" CHARACTER VARYING(50) NOT NULL, + "RULE_UUID" CHARACTER VARYING(40), + "SEVERITY" CHARACTER VARYING(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" CHARACTER VARYING(4000), + "LINE" INTEGER, + "GAP" DOUBLE PRECISION, + "STATUS" CHARACTER VARYING(20), + "RESOLUTION" CHARACTER VARYING(20), + "CHECKSUM" CHARACTER VARYING(1000), + "ASSIGNEE" CHARACTER VARYING(255), + "AUTHOR_LOGIN" CHARACTER VARYING(255), + "ISSUE_ATTRIBUTES" CHARACTER VARYING(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" CHARACTER VARYING(4000), + "COMPONENT_UUID" CHARACTER VARYING(50), + "PROJECT_UUID" CHARACTER VARYING(50), + "LOCATIONS" BINARY LARGE OBJECT, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN, + "QUICK_FIX_AVAILABLE" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE" NULLS FIRST); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID" NULLS FIRST); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE" NULLS FIRST); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID" NULLS FIRST); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION" NULLS FIRST); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT" NULLS FIRST); +CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest/schema.sql new file mode 100644 index 00000000000..5a11bc22d72 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v94/DropReporterIssueColumnTest/schema.sql @@ -0,0 +1,38 @@ +CREATE TABLE "ISSUES"( + "KEE" CHARACTER VARYING(50) NOT NULL, + "RULE_UUID" CHARACTER VARYING(40), + "SEVERITY" CHARACTER VARYING(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" CHARACTER VARYING(4000), + "LINE" INTEGER, + "GAP" DOUBLE PRECISION, + "STATUS" CHARACTER VARYING(20), + "RESOLUTION" CHARACTER VARYING(20), + "CHECKSUM" CHARACTER VARYING(1000), + "REPORTER" CHARACTER VARYING(255), + "ASSIGNEE" CHARACTER VARYING(255), + "AUTHOR_LOGIN" CHARACTER VARYING(255), + "ACTION_PLAN_KEY" CHARACTER VARYING(50), + "ISSUE_ATTRIBUTES" CHARACTER VARYING(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" CHARACTER VARYING(4000), + "COMPONENT_UUID" CHARACTER VARYING(50), + "PROJECT_UUID" CHARACTER VARYING(50), + "LOCATIONS" BINARY LARGE OBJECT, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN, + "QUICK_FIX_AVAILABLE" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE" NULLS FIRST); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID" NULLS FIRST); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE" NULLS FIRST); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID" NULLS FIRST); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION" NULLS FIRST); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT" NULLS FIRST); +CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID" NULLS FIRST); \ No newline at end of file diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java index 1f0ddb37dd7..2d85d30ab16 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java @@ -302,18 +302,6 @@ public class IssueFieldsSetter { return setEffort(issue, currentEffort, context); } - public boolean setAttribute(DefaultIssue issue, String key, @Nullable String value, IssueChangeContext context) { - String oldValue = issue.attribute(key); - if (!Objects.equals(oldValue, value)) { - issue.setFieldChange(context, key, oldValue, value); - issue.setAttribute(key, value); - issue.setUpdateDate(context.date()); - issue.setChanged(true); - return true; - } - return false; - } - public boolean setTags(DefaultIssue issue, Collection tags, IssueChangeContext context) { Set newTags = RuleTagFormat.validate(tags); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java index 28bb4ff34df..2ab5b815ed0 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java @@ -342,37 +342,6 @@ public class IssueFieldsSetterTest { assertThat(issue.mustSendNotifications()).isFalse(); } - @Test - public void set_new_attribute_value() { - boolean updated = underTest.setAttribute(issue, "JIRA", "FOO-123", context); - assertThat(updated).isTrue(); - assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123"); - assertThat(issue.currentChange().diffs()).hasSize(1); - assertThat(issue.currentChange().get("JIRA").oldValue()).isNull(); - assertThat(issue.currentChange().get("JIRA").newValue()).isEqualTo("FOO-123"); - assertThat(issue.mustSendNotifications()).isFalse(); - } - - @Test - public void unset_attribute() { - issue.setAttribute("JIRA", "FOO-123"); - boolean updated = underTest.setAttribute(issue, "JIRA", null, context); - assertThat(updated).isTrue(); - assertThat(issue.attribute("JIRA")).isNull(); - assertThat(issue.currentChange().diffs()).hasSize(1); - assertThat(issue.currentChange().get("JIRA").oldValue()).isEqualTo("FOO-123"); - assertThat(issue.currentChange().get("JIRA").newValue()).isNull(); - assertThat(issue.mustSendNotifications()).isFalse(); - } - - @Test - public void not_update_attribute() { - issue.setAttribute("JIRA", "FOO-123"); - boolean updated = underTest.setAttribute(issue, "JIRA", "FOO-123", context); - assertThat(updated).isFalse(); - assertThat(issue.mustSendNotifications()).isFalse(); - } - @Test public void set_gap_to_fix() { boolean updated = underTest.setGap(issue, 3.14, context); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index f67e112e74e..b43eb7bc89c 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -63,7 +63,6 @@ public class IssueIteratorFactoryTest { .setMessage(null) .setLine(444) .setRuleUuid(rule.getUuid()) - .setIssueAttributes("JIRA=http://jira.com") .setTags(List.of("tag1", "tag2", "tag3")) .setCreatedAt(1400000000000L) .setUpdatedAt(1400000000000L) @@ -108,15 +107,12 @@ public class IssueIteratorFactoryTest { t -> t .setAssigneeUuid("uuid-of-guy1") .setAuthorLogin("guy2") - .setRuleUuid(rule.getUuid()) - .setIssueAttributes("JIRA=http://jira.com") .setEffort(10L) .setType(1)); IssueDto moduleIssue = dbTester.issues().insert(rule, project, module, t -> t .setAssigneeUuid("uuid-of-guy2") .setAuthorLogin("guy2") - .setRuleUuid(rule.getUuid()) - .setIssueAttributes("JIRA=http://jira.com")); + .setRuleUuid(rule.getUuid())); IssueDto dirIssue = dbTester.issues().insert(rule, project, directory); IssueDto projectIssue = dbTester.issues().insert(rule, project, project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java index 8aa563d94ee..6e1fac26ae2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java @@ -106,7 +106,6 @@ public class WebIssueStorageTest { .setResolution("OPEN") .setStatus("OPEN") .setSeverity("BLOCKER") - .setAttribute("foo", "bar") .addComment(comment) .setCreationDate(date) .setUpdateDate(date) @@ -151,7 +150,6 @@ public class WebIssueStorageTest { .setResolution("OPEN") .setStatus("OPEN") .setSeverity("BLOCKER") - .setAttribute("foo", "bar") .setCreationDate(date) .setUpdateDate(date) .setCloseDate(date); @@ -179,7 +177,6 @@ public class WebIssueStorageTest { .setResolution("FIXED") .setStatus("RESOLVED") .setSeverity("MAJOR") - .setAttribute("fox", "bax") .setCreationDate(DateUtils.addDays(date, 1)) .setUpdateDate(DateUtils.addDays(date, 1)) .setCloseDate(DateUtils.addDays(date, 1)) @@ -198,7 +195,6 @@ public class WebIssueStorageTest { .containsEntry("CHECKSUM", updated.checksum()) .containsEntry("COMPONENT_UUID", issue.componentUuid()) .containsEntry("EFFORT", updated.effortInMinutes()) - .containsEntry("ISSUE_ATTRIBUTES", "fox=bax") .containsEntry("ISSUE_TYPE", 3L) .containsEntry("KEE", issue.key()) .containsEntry("LINE", (long) updated.line()) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index 6ea5ecbde85..198bc25d418 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -22,7 +22,6 @@ package org.sonar.core.issue; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.io.Serializable; import java.util.ArrayList; @@ -75,7 +74,6 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. private String resolution; private String assigneeUuid; private String checksum; - private Map attributes = null; private String authorLogin = null; private List comments = null; private Set tags = null; @@ -475,37 +473,23 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + /** + * @deprecated since 9.4, attribute was already not returning any element since 5.2 + */ + @Deprecated @Override @CheckForNull public String attribute(String key) { - return attributes == null ? null : attributes.get(key); - } - - public DefaultIssue setAttribute(String key, @Nullable String value) { - if (attributes == null) { - attributes = new HashMap<>(); - } - if (value == null) { - attributes.remove(key); - } else { - attributes.put(key, value); - } - return this; + return null; } + /** + * @deprecated since 9.4, attribute was already not returning any element since 5.2 + */ + @Deprecated @Override public Map attributes() { - return attributes == null ? Collections.emptyMap() : ImmutableMap.copyOf(attributes); - } - - public DefaultIssue setAttributes(@Nullable Map map) { - if (map != null) { - if (attributes == null) { - attributes = new HashMap<>(); - } - attributes.putAll(map); - } - return this; + return new HashMap<>(); } @Override diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java index 1d0eebe493a..97797a5a496 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java @@ -116,29 +116,6 @@ public class DefaultIssueTest { assertThat(issue.selectedAt()).isNull(); } - @Test - public void test_attributes() { - assertThat(issue.attribute("foo")).isNull(); - issue.setAttribute("foo", "bar"); - assertThat(issue.attribute("foo")).isEqualTo("bar"); - issue.setAttribute("foo", "newbar"); - assertThat(issue.attribute("foo")).isEqualTo("newbar"); - issue.setAttribute("foo", null); - assertThat(issue.attribute("foo")).isNull(); - } - - @Test - public void setAttributes_should_not_clear_existing_values() { - issue.setAttributes(ImmutableMap.of("1", "one")); - assertThat(issue.attribute("1")).isEqualTo("one"); - - issue.setAttributes(ImmutableMap.of("2", "two")); - assertThat(issue.attributes()).containsOnly(entry("1", "one"), entry("2", "two")); - - issue.setAttributes(null); - assertThat(issue.attributes()).containsOnly(entry("1", "one"), entry("2", "two")); - } - @Test public void fail_on_empty_status() { try { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java index 692885f5f37..12ce624cbf4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java @@ -179,6 +179,10 @@ public interface Issue extends Serializable { @CheckForNull Date closeDate(); + /** + * @deprecated since 9.4, attribute was already not returning any element since 5.2 + */ + @Deprecated @CheckForNull String attribute(String key); @@ -186,6 +190,10 @@ public interface Issue extends Serializable { * Empty on batch side since version 5.2. Attributes are moved to server's Compute Engine. No use-case for keeping them * on batch side for now */ + /** + * @deprecated since 9.4, attribute was already not returning any element since 5.2 + */ + @Deprecated Map attributes(); /** -- 2.39.5