diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-09-30 00:11:32 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-10-26 20:02:16 +0300 |
commit | c2d6822e942f86422348fe4ebea7142822e5882c (patch) | |
tree | 0891efe343661528c89c995eda73c2750f1eca05 /db | |
parent | f4bc18d237413ac55e32ce16a23b3d2ab35a6976 (diff) |
Finish updates to use JIRA gem
Code improvements, bug fixes, finish documentation and specs
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20160122231710_migrate_jira_to_gem.rb | 52 | ||||
-rw-r--r-- | db/migrate/20161011222551_remove_inactive_jira_service_properties.rb | 10 | ||||
-rw-r--r-- | db/migrate/20161025231710_migrate_jira_to_gem.rb | 73 | ||||
-rw-r--r-- | db/schema.rb | 2 |
4 files changed, 84 insertions, 53 deletions
diff --git a/db/migrate/20160122231710_migrate_jira_to_gem.rb b/db/migrate/20160122231710_migrate_jira_to_gem.rb deleted file mode 100644 index 972aea323d9..00000000000 --- a/db/migrate/20160122231710_migrate_jira_to_gem.rb +++ /dev/null @@ -1,52 +0,0 @@ -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 diff --git a/db/migrate/20161011222551_remove_inactive_jira_service_properties.rb b/db/migrate/20161011222551_remove_inactive_jira_service_properties.rb new file mode 100644 index 00000000000..319d86ac159 --- /dev/null +++ b/db/migrate/20161011222551_remove_inactive_jira_service_properties.rb @@ -0,0 +1,10 @@ +class RemoveInactiveJiraServiceProperties < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = true + DOWNTIME_REASON = "Removes all inactive jira_service properties" + + def up + execute("UPDATE services SET properties = '{}' WHERE services.type = 'JiraService' and services.active = false") + end +end diff --git a/db/migrate/20161025231710_migrate_jira_to_gem.rb b/db/migrate/20161025231710_migrate_jira_to_gem.rb new file mode 100644 index 00000000000..870b00411d2 --- /dev/null +++ b/db/migrate/20161025231710_migrate_jira_to_gem.rb @@ -0,0 +1,73 @@ +class MigrateJiraToGem < ActiveRecord::Migration + DOWNTIME = true + + DOWNTIME_REASON = <<-HEREDOC + Refactor all Jira services properties(serialized field) to use new jira-ruby gem. + There were properties on old Jira service that are not needed anymore after the + service refactoring: api_url, project_url, new_issue_url, issues_url. + We extract the new necessary some properties from old keys and delete them: + taking project_key from project_url and url from api_url + HEREDOC + + def up + active_services_query = "SELECT id, properties FROM services WHERE services.type IN ('JiraService') AND services.active = true" + + select_all(active_services_query).each do |service| + id = service['id'] + properties = JSON.parse(service['properties']) + properties_was = properties.clone + + # 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') + + # Update changes properties + if properties != properties_was + execute("UPDATE services SET properties = '#{quote_string(properties.to_json)}' WHERE id = #{id}") + end + end + end + + def down + active_services_query = "SELECT id, properties FROM services WHERE services.type IN ('JiraService') AND services.active = true" + + select_all(active_services_query).each do |service| + id = service['id'] + properties = JSON.parse(service['properties']) + properties_was = properties.clone + + # 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') + + # Update changes properties + if properties != properties_was + execute("UPDATE services SET properties = '#{quote_string(properties.to_json)}' WHERE id = #{id}") + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 02282b0f666..5bbfba0d7dd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161024042317) do +ActiveRecord::Schema.define(version: 20161025231710) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |