summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDrew Blessing <drew@gitlab.com>2016-01-14 08:20:23 -0600
committerFelipe Artur <felipefac@gmail.com>2016-10-26 15:02:16 -0200
commitf4bc18d237413ac55e32ce16a23b3d2ab35a6976 (patch)
tree0b9cf78efee768bdcaa3a5175199b7475c1188b0 /db
parent2fc359a506b5997cb65b6d5f2f5c85df98fd1c69 (diff)
downloadgitlab-ce-f4bc18d237413ac55e32ce16a23b3d2ab35a6976.tar.gz
Refactor JIRA service to use gem
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20160122231710_migrate_jira_to_gem.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/db/migrate/20160122231710_migrate_jira_to_gem.rb b/db/migrate/20160122231710_migrate_jira_to_gem.rb
new file mode 100644
index 00000000000..972aea323d9
--- /dev/null
+++ b/db/migrate/20160122231710_migrate_jira_to_gem.rb
@@ -0,0 +1,52 @@
+class MigrateJiraToGem < ActiveRecord::Migration
+ def change
+ reversible do |dir|
+ select_all("SELECT id, properties FROM services WHERE services.type IN ('JiraService')").each do |service|
+ id = service['id']
+ properties = JSON.parse(service['properties'])
+ properties_was = properties.clone
+
+ dir.up do
+ # Migrate `project_url` to `project_key`
+ # Ignore if `project_url` doesn't have jql project query with project key
+ if properties['project_url'].present?
+ jql = properties['project_url'].match('project=([A-Za-z]*)')
+ properties['project_key'] = jql.captures.first if jql
+ end
+
+ # Migrate `api_url` to `url`
+ if properties['api_url'].present?
+ url = properties['api_url'].match('(.*)\/rest\/api')
+ properties['url'] = url.captures.first if url
+ end
+
+ # Delete now unnecessary properties
+ properties.delete('api_url')
+ properties.delete('project_url')
+ properties.delete('new_issue_url')
+ properties.delete('issues_url')
+ end
+
+ dir.down do
+ # Rebuild old properties based on sane defaults
+ if properties['url'].present?
+ properties['api_url'] = "#{properties['url']}/rest/api/2"
+ properties['project_url'] =
+ "#{properties['url']}/issues/?jql=project=#{properties['project_key']}"
+ properties['issues_url'] = "#{properties['url']}/browse/:id"
+ properties['new_issue_url'] = "#{properties['url']}/secure/CreateIssue.jspa"
+ end
+
+ # Delete the new properties
+ properties.delete('url')
+ properties.delete('project_key')
+ end
+
+ # Update changes properties
+ if properties != properties_was
+ execute("UPDATE services SET properties = '#{quote_string(properties.to_json)}' WHERE id = #{id}")
+ end
+ end
+ end
+ end
+end