Skip to content

Instantly share code, notes, and snippets.

@4EverBuilder
Created January 23, 2012 12:09
Show Gist options
  • Save 4EverBuilder/1662779 to your computer and use it in GitHub Desktop.
Save 4EverBuilder/1662779 to your computer and use it in GitHub Desktop.
SQL To get Redmine CSV export. Can be imported to JIRA
{
"field.subject" : "summary",
"project.lead" : "YOUR USERNAME",
"field.category" : "components",
"value.status.Closed" : "6",
"value.status.New" : "3",
"date.import.format" : "yyyy-MM-dd",
"value.status.Feedback" : "3",
"field.tracker" : "issuetype",
"project.name" : "Project",
"field.version" : "fixVersions",
"field.status" : "status",
"field.description" : "comment",
"value.status.Resolved" : "5",
"field.start_date" : "created",
"value.status.QA" : "3",
"user.email.suffix" : "@your_domain.com",
"field.reporter" : "reporter",
"value.status.Assigned" : "3",
"date.fields" : "start_date",
"field.id" : "issue-id",
"value.status.Not a bug" : "6",
"project.key" : "YOUR PROJECT KEY",
"mapfromcsv" : "false",
"value.status.Rejected" : "3",
"field.assignee" : "assignee"
}
SELECT
I.id
, I.subject
, T.name as tracker
, CONCAT('Legacy Redmine Link: http://YOUR_REDMINE_INSTALL/issues/' , I.Id , '\n\n\n' , I.description , '\n\n\n' ,
(SELECT IFNULL(GROUP_CONCAT( CONCAT('On ' , j.created_on , ' ' , (SELECT CONCAT(uj.firstname , ' ' , uj.lastname) FROM users uj WHERE u.id = j.user_id LIMIT 1) , ' wrote :' , j.notes , '\n\n\n' )) , ' ') FROM journals j WHERE j.journalized_id = I.id AND j.journalized_type = 'Issue' AND TRIM(j.notes) != '' )
) as description
, C.name as category
, S.name as status
, u.login as assignee
, u2.login as reporter
, V.name as version
, I.start_date
FROM
issues I LEFT JOIN users u ON I.assigned_to_id = u.id
LEFT JOIN users u2 ON I.author_id = u2.id
LEFT JOIN issue_categories C ON C.id = I.category_id
LEFT JOIN versions V ON V.id = I.fixed_version_id
, issue_statuses S , trackers T
WHERE
I.project_id = 1
AND S.id = I.status_id
AND T.id = I.tracker_id
ORDER BY 1;
@mrscylla
Copy link

mrscylla commented Oct 7, 2020

Added attachments and comments:

SELECT 
  issues.id [Issue Key]
, issues.subject 
, trackers.name as tracker 
, issues.description	
, statuses.name as status	
, assignee.login as assignee	
, author.login as reporter	
, versions.name as version	
, issues.start_date	
, prioritys.name priority
, issues.created_on
, issues.updated_on
, issues.start_date
, issues.estimated_hours
, issues.parent_id relation
, attachments.[attachment 1], attachments.[attachment 2], attachments.[attachment 3], attachments.[attachment 4], attachments.[attachment 5], attachments.[attachment 6], attachments.[attachment 7], attachments.[attachment 8], attachments.[attachment 9], attachments.[attachment 10]
, comments.[comment 1], comments.[comment 2], comments.[comment 3], comments.[comment 4], comments.[comment 5], comments.[comment 6], comments.[comment 7], comments.[comment 8], comments.[comment 9], comments.[comment 10]
FROM issues
LEFT JOIN users assignee 
ON issues.assigned_to_id = assignee.id
LEFT JOIN users author 
ON issues.author_id = author.id
LEFT JOIN versions versions
ON versions.id = issues.fixed_version_id
LEFT JOIN issue_statuses statuses
ON statuses.id = issues.status_id
LEFT JOIN trackers
ON trackers.id = issues.tracker_id
LEFT JOIN enumerations prioritys
ON prioritys.id = issues.priority_id and prioritys.type ='IssuePriority'
LEFT JOIN (select issue_id, [attachment 1], [attachment 2], [attachment 3], [attachment 4], [attachment 5], [attachment 6], [attachment 7], [attachment 8], [attachment 9], [attachment 10] from
			(select issues.id issue_id,
			case 
				when attachments.id is null then null 
				else CONCAT(''http://1c-tasks.rtits.ru/attachments/download/'', attachments.id,''/'', attachments.filename) 
				end attachment, 
				''attachment '' + cast(ROW_NUMBER() OVER (PARTITION BY issues.id ORDER BY issues.id) as varchar) colnames
			FROM
				issues

			LEFT JOIN attachments on container_id = issues.id and container_type = ''issue'') attachments
			PIVOT  
			(  
			Max(attachment)
			FOR colnames IN ([attachment 1], [attachment 2], [attachment 3], [attachment 4], [attachment 5], [attachment 6], [attachment 7], [attachment 8], [attachment 9], [attachment 10])  
			) AS PivotTable) attachments
			ON attachments.issue_id = issues.id 

LEFT JOIN (select issue_id, [comment 1], [comment 2], [comment 3], [comment 4], [comment 5], [comment 6], [comment 7], [comment 8], [comment 9], [comment 10] from
			(select	issues.id issue_id, 
					CONCAT(users.login,'';'',CONVERT(nvarchar(30), journals.created_on, 120),'';'',journals.notes) comment, 
					''comment '' + cast(ROW_NUMBER() OVER (PARTITION BY issues.id ORDER BY issues.id) as varchar) colnames
			FROM
				issues

			LEFT JOIN journals on journals.journalized_id = issues.id and journalized_type = ''Issue''
			LEFT JOIN users on users.id = journals.[user_id]) comments
			PIVOT  
			(  
			Max(comment)
			FOR colnames IN ([comment 1], [comment 2], [comment 3], [comment 4], [comment 5], [comment 6], [comment 7], [comment 8], [comment 9], [comment 10])  
			) AS PivotTable) comments
			ON comments.issue_id = issues.id
WHERE
issues.project_id = 7

order by [Issue Key]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment