Commit 8dbfda4566fbf24b73f6173967fb0d0de032d296

Authored by Stephen Crosby
1 parent 9c798492
Exists in master and in 1 other branch production

get migrations running from start to finish

@@ -116,7 +116,7 @@ GEM @@ -116,7 +116,7 @@ GEM
116 errbit_lighthouse_plugin (0.1.0) 116 errbit_lighthouse_plugin (0.1.0)
117 errbit_plugin (~> 0) 117 errbit_plugin (~> 0)
118 lighthouse-api (~> 2) 118 lighthouse-api (~> 2)
119 - errbit_pivotal_plugin (0.1.0) 119 + errbit_pivotal_plugin (0.2.0)
120 errbit_plugin (~> 0.4, >= 0.4.0) 120 errbit_plugin (~> 0.4, >= 0.4.0)
121 pivotal-tracker (~> 0.5, >= 0.5.0) 121 pivotal-tracker (~> 0.5, >= 0.5.0)
122 errbit_plugin (0.4.0) 122 errbit_plugin (0.4.0)
@@ -191,7 +191,7 @@ GEM @@ -191,7 +191,7 @@ GEM
191 railties 191 railties
192 method_source (0.8.2) 192 method_source (0.8.2)
193 mime-types (1.25.1) 193 mime-types (1.25.1)
194 - mini_portile (0.6.0) 194 + mini_portile (0.6.1)
195 mongoid (3.1.5) 195 mongoid (3.1.5)
196 activemodel (~> 3.2) 196 activemodel (~> 3.2)
197 moped (~> 1.4) 197 moped (~> 1.4)
@@ -217,8 +217,8 @@ GEM @@ -217,8 +217,8 @@ GEM
217 net-ssh (2.7.0) 217 net-ssh (2.7.0)
218 net-ssh-gateway (1.2.0) 218 net-ssh-gateway (1.2.0)
219 net-ssh (>= 2.6.5) 219 net-ssh (>= 2.6.5)
220 - nokogiri (1.6.3.1)  
221 - mini_portile (= 0.6.0) 220 + nokogiri (1.6.4.1)
  221 + mini_portile (~> 0.6.0)
222 nokogiri-happymapper (0.5.9) 222 nokogiri-happymapper (0.5.9)
223 nokogiri (~> 1.5) 223 nokogiri (~> 1.5)
224 oauth (0.4.7) 224 oauth (0.4.7)
db/migrate/20110812135951_move_issue_trackers_to_sti.rb
@@ -5,21 +5,27 @@ class MoveIssueTrackersToSti < Mongoid::Migration @@ -5,21 +5,27 @@ class MoveIssueTrackersToSti < Mongoid::Migration
5 # All issue trackers now subclass the IssueTracker model, 5 # All issue trackers now subclass the IssueTracker model,
6 # and their class is stored in the '_type' field, which is 6 # and their class is stored in the '_type' field, which is
7 # also aliased to 'type'. 7 # also aliased to 'type'.
8 - if app.issue_tracker && app.issue_tracker.attributes["issue_tracker_type"]  
9 - app.issue_tracker._type = case app.issue_tracker.issue_tracker_type  
10 - when 'lighthouseapp'; "LighthouseTracker"  
11 - when 'redmine'; "RedmineTracker"  
12 - when 'pivotal'; "PivotalLabsTracker"  
13 - when 'fogbugz'; "FogbugzTracker"  
14 - when 'mingle'; "MingleTracker" 8 + tracker = app.attributes['issue_tracker']
  9 + if tracker && tracker['issue_tracker_type']
  10 + tracker['_type'] = case tracker['issue_tracker_type']
  11 + when 'lighthouseapp'; "IssueTrackers::LighthouseTracker"
  12 + when 'redmine'; "IssueTrackers::RedmineTracker"
  13 + when 'pivotal'; "IssueTrackers::PivotalLabsTracker"
  14 + when 'fogbugz'; "IssueTrackers::FogbugzTracker"
  15 + when 'mingle'; "IssueTrackers::MingleTracker"
15 else; nil 16 else; nil
16 end 17 end
17 - if app.issue_tracker.issue_tracker_type == "none"  
18 - app.issue_tracker = nil 18 +
  19 + if tracker['issue_tracker_type'] == "none"
  20 + App.collection.where({ _id: app.id }).update({
  21 + "$unset" => { :issue_tracker => 1 }
  22 + })
19 else 23 else
20 - app.issue_tracker.issue_tracker_type = nil 24 + tracker.delete('issue_tracker_type')
  25 + App.collection.where({ _id: app.id }).update({
  26 + "$set" => { :issue_tracker => tracker }
  27 + })
21 end 28 end
22 - app.save  
23 end 29 end
24 end 30 end
25 end 31 end
db/migrate/20120603112130_change_github_url_to_github_repo.rb
1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration 1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration
  2 + def self.normalize_github_repo(repo)
  3 + return if repo.blank?
  4 + github_host = URI.parse(Errbit::Config.github_url).host
  5 + github_host = Regexp.escape(github_host)
  6 + repo.strip!
  7 + repo.sub!(/(git@|https?:\/\/)#{github_host}(\/|:)/, '')
  8 + repo.sub!(/\.git$/, '')
  9 + repo
  10 + end
  11 +
2 def self.up 12 def self.up
3 App.collection.find.update({'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true) 13 App.collection.find.update({'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true)
4 App.all.each do |app| 14 App.all.each do |app|
5 - app.send :normalize_github_repo  
6 - app.save 15 + normalized_repo = self.normalize_github_repo(app.attributes['github_repo'])
  16 + App.collection.where({ _id: app.id }).update({
  17 + "$set" => { :github_repo => normalized_repo }
  18 + })
7 end 19 end
8 end 20 end
9 21
db/migrate/20131011155638_extract_issue_tracker.rb
1 class ExtractIssueTracker < Mongoid::Migration 1 class ExtractIssueTracker < Mongoid::Migration
2 2
  3 + TRACKER_MAPPING = {
  4 + 'ErrbitTracPlugin::IssueTracker' => 'trac',
  5 + 'IssueTrackers::BitbucketIssuesTracker' => 'bitbucket',
  6 + 'IssueTrackers::FogbugzTracker' => 'fogbugz',
  7 + 'IssueTrackers::GithubIssuesTracker' => 'github',
  8 + 'IssueTrackers::GitlabTracker' => 'gitlab',
  9 + 'IssueTrackers::JiraTracker' => 'jira',
  10 + 'IssueTrackers::LighthouseTracker' => 'lighthouse',
  11 + 'IssueTrackers::PivotalLabsTracker' => 'pivotal',
  12 + 'IssueTrackers::RedmineTracker' => 'redmine',
  13 + 'IssueTrackers::UnfuddleTracker' => 'unfuddle'
  14 + }
  15 +
3 def self.up 16 def self.up
4 - App.collection.find.each do |app|  
5 - if app['issue_tracker'] && !app['issue_tracker'].empty?  
6 - it = app['issue_tracker']  
7 - it['type_tracker'] = app['issue_tracker']['_type']  
8 - it['options'] = app['issue_tracker'].dup  
9 - it.delete('_type')  
10 - App.collection.find(  
11 - :_id => app['_id']  
12 - ).update(app) 17 + App.all.each do |app|
  18 + require 'pry'
  19 + binding.pry
  20 + next unless app.attributes['issue_tracker'].present?
  21 + next unless app.attributes['issue_tracker']['_type'].present?
  22 +
  23 + options = app['issue_tracker'].dup
  24 + options.delete('_type')
  25 + options.delete('_id')
  26 +
  27 + _type = app.attributes['issue_tracker']['_type']
  28 + updated_at = options.delete('updated_at')
  29 + created_at = options.delete('created_at')
  30 +
  31 + if TRACKER_MAPPING.include?(_type)
  32 + tracker = {
  33 + 'type_tracker' => TRACKER_MAPPING[_type],
  34 + 'options' => options,
  35 + 'updated_at' => updated_at,
  36 + 'created_at' => created_at
  37 + }
  38 +
  39 + App.collection.where({ _id: app.id }).update({
  40 + "$set" => { :issue_tracker => tracker }
  41 + })
13 end 42 end
14 end 43 end
15 end 44 end