From: Simon Brandhof Date: Tue, 21 May 2013 14:37:17 +0000 (+0200) Subject: SONAR-4305 migrate db tables from violations/reviews to issues X-Git-Tag: 3.6~323 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=714ba2eebc1084830dfa38b093583624b6fa07ff;p=sonarqube.git SONAR-4305 migrate db tables from violations/reviews to issues --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java index e45a749a33d..cd6907ca66e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java @@ -141,8 +141,8 @@ public class IssueTrackingDecorator implements Decorator { issue.setStatus(ref.getStatus()); issue.setAssignee(ref.getAssignee()); issue.setAuthorLogin(ref.getAuthorLogin()); - if (ref.getAttributes() != null) { - issue.setAttributes(KeyValueFormat.parse(ref.getAttributes())); + if (ref.getIssueAttributes() != null) { + issue.setAttributes(KeyValueFormat.parse(ref.getIssueAttributes())); } // fields to update with current values diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index de545172be5..c79b4837172 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -52,7 +52,7 @@ public final class IssueDto { private String assignee; private String authorLogin; private String actionPlanKey; - private String attributes; + private String issueAttributes; // functional dates private Date issueCreationDate; @@ -220,14 +220,14 @@ public final class IssueDto { return this; } - public String getAttributes() { - return attributes; + public String getIssueAttributes() { + return issueAttributes; } - public IssueDto setAttributes(@Nullable String s) { + public IssueDto setIssueAttributes(@Nullable String s) { Preconditions.checkArgument(s == null || s.length() <= 4000, "Issue attributes must not exceed 4000 characters: " + s); - this.attributes = s; + this.issueAttributes = s; return this; } @@ -326,7 +326,7 @@ public final class IssueDto { .setRuleId(ruleId) .setResourceId(componentId) .setActionPlanKey(issue.actionPlanKey()) - .setAttributes(issue.attributes() != null ? KeyValueFormat.format(issue.attributes()) : "") + .setIssueAttributes(issue.attributes() != null ? KeyValueFormat.format(issue.attributes()) : "") .setAuthorLogin(issue.authorLogin()) .setIssueCreationDate(issue.creationDate()) .setIssueCloseDate(issue.closeDate()) @@ -351,7 +351,7 @@ public final class IssueDto { .setReporter(issue.reporter()) .setAssignee(issue.assignee()) .setActionPlanKey(issue.actionPlanKey()) - .setAttributes(issue.attributes() != null ? KeyValueFormat.format(issue.attributes()) : "") + .setIssueAttributes(issue.attributes() != null ? KeyValueFormat.format(issue.attributes()) : "") .setAuthorLogin(issue.authorLogin()) .setIssueCreationDate(issue.creationDate()) .setIssueCloseDate(issue.closeDate()) @@ -370,7 +370,7 @@ public final class IssueDto { issue.setSeverity(severity); issue.setReporter(reporter); issue.setAssignee(assignee); - issue.setAttributes(KeyValueFormat.parse(Objects.firstNonNull(attributes, ""))); + issue.setAttributes(KeyValueFormat.parse(Objects.firstNonNull(issueAttributes, ""))); issue.setComponentKey(componentKey); issue.setManualSeverity(manualSeverity); issue.setRuleKey(RuleKey.of(ruleRepo, ruleKey)); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index aafefbd4286..39fdd04cd98 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -32,7 +32,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 397; + public static final int LAST_VERSION = 399; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 9717a2417cf..4edb2f7a599 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -21,7 +21,7 @@ i.reporter as reporter, i.assignee as assignee, i.author_login as authorLogin, - i.attributes as attributes, + i.issue_attributes as issueAttributes, i.issue_creation_date as issueCreationDate, i.issue_update_date as issueUpdateDate, i.issue_close_date as issueCloseDate, @@ -69,11 +69,11 @@ INSERT INTO issues (kee, resource_id, rule_id, action_plan_key, severity, manual_severity, message, line, effort_to_fix, status, - resolution, checksum, reporter, assignee, author_login, attributes, issue_creation_date, issue_update_date, + resolution, checksum, reporter, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, issue_close_date, created_at, updated_at) VALUES (#{kee}, #{resourceId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{message}, #{line}, #{effortToFix}, #{status}, - #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{attributes}, #{issueCreationDate}, + #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{issueAttributes}, #{issueCreationDate}, #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) @@ -85,11 +85,11 @@ INSERT INTO issues (id, kee, resource_id, rule_id, action_plan_key, severity, manual_severity, message, line, effort_to_fix, status, - resolution, checksum, reporter, assignee, author_login, attributes, issue_creation_date, issue_update_date, + resolution, checksum, reporter, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, issue_close_date, created_at, updated_at) VALUES (#{id}, #{kee}, #{resourceId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{message}, #{line}, #{effortToFix}, #{status}, - #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{attributes}, #{issueCreationDate}, + #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{issueAttributes}, #{issueCreationDate}, #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) @@ -110,7 +110,7 @@ reporter=#{reporter}, assignee=#{assignee}, author_login=#{authorLogin}, - attributes=#{attributes}, + issue_attributes=#{issueAttributes}, issue_creation_date=#{issueCreationDate}, issue_update_date=#{issueUpdateDate}, issue_close_date=#{issueCloseDate}, diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 6b3fcd5313f..a6aaa812b52 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -162,6 +162,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('394'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('395'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('396'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('397'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('398'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('399'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 640817337a5..79018bd010c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -533,7 +533,7 @@ CREATE TABLE "ISSUES" ( "ASSIGNEE" VARCHAR(40), "AUTHOR_LOGIN" VARCHAR(100), "ACTION_PLAN_KEY" VARCHAR(50) NULL, - "ATTRIBUTES" VARCHAR(4000), + "ISSUE_ATTRIBUTES" VARCHAR(4000), "ISSUE_CREATION_DATE" TIMESTAMP, "ISSUE_CLOSE_DATE" TIMESTAMP, "ISSUE_UPDATE_DATE" TIMESTAMP, diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index cfb30567f21..fe83068bf2e 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -62,7 +62,7 @@ public class IssueDaoTest extends AbstractDaoTestCase { assertThat(issue.getAuthorLogin()).isEqualTo("karadoc"); assertThat(issue.getReporter()).isEqualTo("arthur"); assertThat(issue.getAssignee()).isEqualTo("perceval"); - assertThat(issue.getAttributes()).isEqualTo("JIRA=FOO-1234"); + assertThat(issue.getIssueAttributes()).isEqualTo("JIRA=FOO-1234"); assertThat(issue.getIssueCreationDate()).isNotNull(); assertThat(issue.getIssueUpdateDate()).isNotNull(); assertThat(issue.getIssueCloseDate()).isNotNull(); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java index 9598b8c796d..a935fbcdcbd 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java @@ -44,7 +44,7 @@ public class IssueDtoTest { for (int i = 0; i < 4500; i++) { s.append('a'); } - new IssueDto().setAttributes(s.toString()); + new IssueDto().setIssueAttributes(s.toString()); } @Test @@ -68,7 +68,7 @@ public class IssueDtoTest { .setManualSeverity(true) .setReporter("arthur") .setAssignee("perceval") - .setAttributes("key=value") + .setIssueAttributes("key=value") .setAuthorLogin("pierre") .setIssueCreationDate(createdAt) .setIssueUpdateDate(updatedAt) diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java index d606a87080d..942514f5411 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java @@ -51,7 +51,7 @@ public class IssueMapperTest extends AbstractDaoTestCase { dto.setAuthorLogin("morgan"); dto.setAssignee("karadoc"); dto.setActionPlanKey("current_sprint"); - dto.setAttributes("JIRA=FOO-1234"); + dto.setIssueAttributes("JIRA=FOO-1234"); dto.setChecksum("123456789"); dto.setMessage("the message"); @@ -84,7 +84,7 @@ public class IssueMapperTest extends AbstractDaoTestCase { dto.setAuthorLogin("morgan"); dto.setAssignee("karadoc"); dto.setActionPlanKey("current_sprint"); - dto.setAttributes("JIRA=FOO-1234"); + dto.setIssueAttributes("JIRA=FOO-1234"); dto.setChecksum("123456789"); dto.setMessage("the message"); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml index f960ecd1b62..99469f9ac16 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml @@ -18,7 +18,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" action_plan_key="ABC" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" @@ -42,7 +42,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" action_plan_key="ABC" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" @@ -66,7 +66,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" action_plan_key="ABC" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml index 3d7bd96af21..1536bfcd739 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml index 5655372b58e..ca8d6ea634f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -42,7 +42,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -68,7 +68,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml index f25c1c9e8ea..e0ab0887a43 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="[null]" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml index 34f07c20209..72522e55360 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml @@ -16,7 +16,7 @@ reporter="user" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -40,7 +40,7 @@ reporter="[null]" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml index 9b6f20c96ca..be585789722 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -40,7 +40,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-13" issue_update_date="2013-04-13" issue_close_date="2013-04-13" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml index 3d6ad15c5a0..986c069e9e4 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-17" issue_update_date="2013-04-17" issue_close_date="2013-04-17" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-18" issue_update_date="2013-04-18" issue_close_date="2013-04-18" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml index d01f5342d87..853f580260f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="perceval" author_login="karadoc" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml index ded6b072043..8ab824158e0 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -42,7 +42,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -68,7 +68,7 @@ reporter="arthur" assignee="[null]" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml index 816742b954b..8c885378061 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml index 371d3da3f4f..aa6105074d7 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -40,7 +40,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -64,7 +64,7 @@ reporter="arthur" assignee="[null]" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml index d2af6661a9e..746d55ec021 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml index 3d7bd96af21..1536bfcd739 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml index 12f7036120e..2314297dc66 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml @@ -16,7 +16,7 @@ reporter="user" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -40,7 +40,7 @@ reporter="[null]" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -64,7 +64,7 @@ reporter="[null]" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml index 41a97ef98b8..2e5e66e3bbb 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="arthur" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="henry" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml index b27051ff207..4de78ef752e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="arthur" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-17" issue_close_date="2013-04-17" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="henry" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-18" issue_close_date="2013-04-18" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml index d84b71fa09b..4af4496b6ee 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="arthur" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-15" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -40,7 +40,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-14" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -64,7 +64,7 @@ reporter="arthur" assignee="henry" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml index 9dae4080973..ae7bf813659 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="arthur" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -40,7 +40,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -64,7 +64,7 @@ reporter="arthur" assignee="henry" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml index b510a5c447a..963dfcfa98d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml @@ -17,7 +17,7 @@ reporter="arthur" assignee="arthur" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -41,7 +41,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -67,7 +67,7 @@ reporter="arthur" assignee="henry" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml index 769bae1454d..0fe27358625 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml @@ -16,7 +16,7 @@ reporter="arthur" assignee="arthur" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-17" issue_close_date="2013-04-17" @@ -40,7 +40,7 @@ reporter="arthur" assignee="perceval" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -64,7 +64,7 @@ reporter="arthur" assignee="henry" author_login="[null]" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-04-16" issue_update_date="2013-04-18" issue_close_date="2013-04-18" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml index 69e5160f962..9bf0949ff96 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml @@ -15,7 +15,7 @@ reporter="emmerik" author_login="morgan" assignee="karadoc" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-05-18" issue_update_date="2013-05-19" issue_close_date="2013-05-20" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml index 57bc88451ea..7b426decdde 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml @@ -34,7 +34,7 @@ reporter="emmerik" author_login="morgan" assignee="karadoc" - attributes="JIRA=FOO-1234" + issue_attributes="JIRA=FOO-1234" issue_creation_date="2013-05-18" issue_update_date="2013-05-19" issue_close_date="2013-05-20" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml index 06ee1af1b50..f6f06e40abd 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml @@ -34,7 +34,7 @@ reporter="[null]" author_login="[null]" assignee="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="[null]" issue_update_date="[null]" issue_close_date="[null]" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml index 97ca9b21656..aa41626b8df 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml @@ -11,7 +11,7 @@ created_at="[null]" updated_at="[null]" reporter="emmerik" - attributes="foo=bar" + issue_attributes="foo=bar" action_plan_key="[null]" issue_creation_date="2013-05-18" issue_update_date="2013-05-18" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml index 862d14f2b75..d7a35807753 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml @@ -16,7 +16,7 @@ created_at="2013-05-18" updated_at="2013-05-18" reporter="emmerik" - attributes="foo=bar" + issue_attributes="foo=bar" action_plan_key="[null]" issue_creation_date="2013-05-18 00:00:00.0" issue_update_date="2013-05-18 00:00:00.0" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues.xml index 4d8e2449c57..d3460496f19 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues.xml @@ -16,7 +16,7 @@ created_at="2010-01-01" updated_at="2011-02-02" reporter="emmerik" - attributes="foo=bar" + issue_attributes="foo=bar" action_plan_key="[null]" issue_creation_date="2010-01-01" issue_update_date="2010-02-02" diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml index 5bf87b320ac..4f5cf5e326f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml @@ -34,7 +34,7 @@ reporter="user" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" @@ -58,7 +58,7 @@ reporter="[null]" assignee="user" author_login="[null]" - attributes="[null]" + issue_attributes="[null]" issue_creation_date="2013-04-16" issue_update_date="2013-04-16" issue_close_date="2013-04-16" diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb index 2733202a82e..febc7422cac 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb @@ -40,7 +40,7 @@ class CreateIssues < ActiveRecord::Migration t.column :assignee, :string, :null => true, :limit => 40 t.column :author_login, :string, :null => true, :limit => 100 t.column :action_plan_key, :string, :null => true, :limit => 50 - t.column :attributes, :string, :null => true, :limit => 4000 + t.column :issue_attributes, :string, :null => true, :limit => 4000 # functional dates t.column :issue_creation_date, :datetime, :null => true diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/398_delete_review_duplications.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/398_delete_review_duplications.rb new file mode 100644 index 00000000000..d6b39a8469b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/398_delete_review_duplications.rb @@ -0,0 +1,42 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# Sonar 3.6 +# See SONAR-4305 +# +class DeleteReviewDuplications < ActiveRecord::Migration + + class Review < ActiveRecord::Base + end + + def self.up + duplicated_ids = ActiveRecord::Base.connection.select_rows('select rule_failure_permanent_id from reviews group by rule_failure_permanent_id having count(*) > 1') + say_with_time "Removing #{duplicated_ids.size} duplicated reviews" do + duplicated_ids.each do |id| + reviews = Review.find(:all, :conditions => {:rule_failure_permanent_id => id}) + # delete all reviews except the last one + reviews[0...-1].each do |review| + Review.delete(review.id) + end + end + end + end +end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/399_migrate_violations_to_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/399_migrate_violations_to_issues.rb new file mode 100644 index 00000000000..69662da4dfb --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/399_migrate_violations_to_issues.rb @@ -0,0 +1,163 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# Sonar 3.6 +# See SONAR-4305 +# +class MigrateViolationsToIssues < ActiveRecord::Migration + + class RuleFailure < ActiveRecord::Base + end + + class Issue < ActiveRecord::Base + end + + class IssueChange < ActiveRecord::Base + end + + class User < ActiveRecord::Base + end + + class ActionPlan < ActiveRecord::Base + end + + PRIORITY_TO_SEVERITY = {1 => 'INFO', 2 => 'MINOR', 3 => 'MAJOR', 4 => 'CRITICAL', 5 => 'BLOCKER'} + + def self.up + # TODO another migration to delete duplications in reviews + truncate_issues + + violation_ids = ActiveRecord::Base.connection.select_rows('select id from rule_failures') + + say_with_time "Migrating #{violation_ids.size} violations to issues" do + logins_by_id = User.all.inject({}) do |result, user| + result[user.id]=user.login + result + end + + plans_by_id = ActionPlan.all.inject({}) do |result, plan| + result[plan.id]=plan.kee + result + end + + violation_ids.each_slice(999) do |ids| + violations = ActiveRecord::Base.connection.select_rows(sql_select_violation(ids)) + ActiveRecord::Base.transaction do + violations.each do |violation| + issue_key = new_key + review_id = violation[0] + created_at = violation[7] + resource_id = violation[1] + if resource_id.present? + issue = Issue.new( + :kee => issue_key, + :resource_id => violation[1], + :rule_id => violation[2], + :severity => PRIORITY_TO_SEVERITY[violation[3].to_i], + :message => violation[4], + :line => violation[5], + :effort_to_fix => violation[6], + :resolution => violation[13], + :checksum => violation[8], + :author_login => nil, + :issue_attributes => violation[15], + :issue_creation_date => created_at, + :issue_close_date => nil, + :created_at => created_at + ) + if review_id.present? + # has review + issue.status=violation[11] + issue.issue_update_date=violation[16] + issue.updated_at=violation[16] + issue.severity=violation[12] + issue.manual_severity=violation[14] + issue.reporter=logins_by_id[violation[9].to_i] if violation[9].present? + issue.assignee=logins_by_id[violation[10].to_i] if violation[10].present? + + plan_id = select_plan_id(review_id) + issue.action_plan_key=plans_by_id[plan_id.to_i] if plan_id + + review_comments = select_review_comments(review_id) + review_comments.each do |review_comment| + user_id = review_comment[2] + login = logins_by_id[user_id.to_i] + if login + IssueChange.create( + :kee => new_key, + :issue_key => issue_key, + :user_login => login, + :change_type => 'comment', + :change_data => review_comment[3], + :created_at => review_comment[0], + :updated_at => review_comment[1] + ) + end + end + + else + # does not have review + issue.status='OPEN' + issue.issue_update_date=created_at + issue.updated_at=created_at + issue.manual_severity=false + end + issue.save + end + end + end + end + end + + #drop_table('rule_failures') + #drop_table('reviews') + #drop_table('review_comments') + #drop_table('action_plans_reviews') + end + + def self.truncate_issues + ActiveRecord::Base.connection.execute('truncate table issues') + ActiveRecord::Base.connection.execute('truncate table issue_changes') + end + + def self.sql_select_violation(ids) + "select rev.id, s.project_id, rf.rule_id, rf.failure_level, rf.message, rf.line, rf.cost, rf.created_at, + rf.checksum, + rev.user_id, rev.assignee_id, rev.status, rev.severity, rev.resolution, rev.manual_severity, rev.data, + rev.updated_at + from rule_failures rf + inner join snapshots s on s.id=rf.snapshot_id + left join reviews rev on rev.rule_failure_permanent_id=rf.permanent_id + where rf.id in (#{ids.join(',')})" + end + + def self.new_key + Java::JavaUtil::UUID.randomUUID().toString() + end + + def self.select_plan_id(review_id) + ActiveRecord::Base.connection.select_value("select action_plan_id from action_plans_reviews where review_id=#{review_id}") + end + + def self.select_review_comments(review_id) + ActiveRecord::Base.connection.select_rows "select created_at, updated_at, user_id, review_text from review_comments where review_id=#{review_id}" + end +end \ No newline at end of file