Commit 4b00b5760908151b139c078a9c502662eacdd5c4

Authored by Arthur Neves
1 parent f021f134
Exists in master and in 1 other branch production

fix mongoid migrations

@@ -3,9 +3,8 @@ source 'http://rubygems.org' @@ -3,9 +3,8 @@ source 'http://rubygems.org'
3 gem 'rails', '3.2.13' 3 gem 'rails', '3.2.13'
4 gem 'mongoid', '~> 3.1.4' 4 gem 'mongoid', '~> 3.1.4'
5 5
6 -# Mongoid rails migration > 0.0.14 is not compatible to Mongoid 2.x  
7 -gem 'mongoid_rails_migrations', '~> 0.0.14'  
8 -gem 'devise', '~> 2.2.6' # Last version supporting ruby 1.8.7 6 +gem 'mongoid_rails_migrations', '~> 1.0.1'
  7 +gem 'devise'
9 gem 'haml' 8 gem 'haml'
10 gem 'htmlentities' 9 gem 'htmlentities'
11 gem 'rack-ssl', :require => 'rack/ssl' # force SSL 10 gem 'rack-ssl', :require => 'rack/ssl' # force SSL
@@ -185,11 +185,11 @@ GEM @@ -185,11 +185,11 @@ GEM
185 moped (~> 1.4) 185 moped (~> 1.4)
186 origin (~> 1.0) 186 origin (~> 1.0)
187 tzinfo (~> 0.3.22) 187 tzinfo (~> 0.3.22)
188 - mongoid_rails_migrations (0.0.14)  
189 - activesupport (>= 3.0.0) 188 + mongoid_rails_migrations (1.0.1)
  189 + activesupport (>= 3.2.0)
190 bundler (>= 1.0.0) 190 bundler (>= 1.0.0)
191 - rails (>= 3.0.0)  
192 - railties (>= 3.0.0) 191 + rails (>= 3.2.0)
  192 + railties (>= 3.2.0)
193 moped (1.5.1) 193 moped (1.5.1)
194 multi_json (1.7.9) 194 multi_json (1.7.9)
195 multi_xml (0.5.5) 195 multi_xml (0.5.5)
@@ -392,7 +392,7 @@ DEPENDENCIES @@ -392,7 +392,7 @@ DEPENDENCIES
392 database_cleaner (~> 0.9.0) 392 database_cleaner (~> 0.9.0)
393 debugger 393 debugger
394 decent_exposure 394 decent_exposure
395 - devise (~> 2.2.6) 395 + devise
396 email_spec 396 email_spec
397 execjs 397 execjs
398 fabrication (~> 1.3.0) 398 fabrication (~> 1.3.0)
@@ -412,7 +412,7 @@ DEPENDENCIES @@ -412,7 +412,7 @@ DEPENDENCIES
412 lighthouse-api 412 lighthouse-api
413 meta_request 413 meta_request
414 mongoid (~> 3.1.4) 414 mongoid (~> 3.1.4)
415 - mongoid_rails_migrations (~> 0.0.14) 415 + mongoid_rails_migrations (~> 1.0.1)
416 octokit 416 octokit
417 omniauth-github 417 omniauth-github
418 oruen_redmine_client 418 oruen_redmine_client
db/migrate/20110422152027_move_notices_to_separate_collection.rb
1 class MoveNoticesToSeparateCollection < Mongoid::Migration 1 class MoveNoticesToSeparateCollection < Mongoid::Migration
2 def self.up 2 def self.up
  3 + errs_coll = connection["errs"]
  4 +
3 # copy embedded Notices into a separate collection 5 # copy embedded Notices into a separate collection
4 - mongo_db = Err.db  
5 - errs = mongo_db.collection("errs").find({ }, :fields => ["notices"]) 6 + errs = errs_coll.find.select(notices: 1)
6 errs.each do |err| 7 errs.each do |err|
7 next unless err['notices'] 8 next unless err['notices']
8 9
@@ -18,7 +19,7 @@ class MoveNoticesToSeparateCollection &lt; Mongoid::Migration @@ -18,7 +19,7 @@ class MoveNoticesToSeparateCollection &lt; Mongoid::Migration
18 e.notices.create!(notice) 19 e.notices.create!(notice)
19 end 20 end
20 e.app.update_attribute(:notify_on_errs, old_notify) 21 e.app.update_attribute(:notify_on_errs, old_notify)
21 - mongo_db.collection("errs").update({ "_id" => err['_id']}, { "$unset" => { "notices" => 1}}) 22 + errs_coll.find({ "_id" => err['_id']}).update({ "$unset" => { "notices" => 1}})
22 end 23 end
23 Rake::Task["errbit:db:update_notices_count"].invoke 24 Rake::Task["errbit:db:update_notices_count"].invoke
24 Rake::Task["errbit:db:update_problem_attrs"].invoke 25 Rake::Task["errbit:db:update_problem_attrs"].invoke
db/migrate/20120530005915_rename_klass_to_error_class.rb
1 class RenameKlassToErrorClass < Mongoid::Migration 1 class RenameKlassToErrorClass < Mongoid::Migration
2 def self.up 2 def self.up
3 [Problem, Err, Notice].each do |model| 3 [Problem, Err, Notice].each do |model|
4 - model.collection.update({}, {'$rename' => {'klass' => 'error_class'}}, :multi => true, :safe => true) 4 + model.collection.find.update({'$rename' => {'klass' => 'error_class'}}, :multi => true, :safe => true)
5 end 5 end
6 end 6 end
7 7
8 def self.down 8 def self.down
9 [Problem, Err, Notice].each do |model| 9 [Problem, Err, Notice].each do |model|
10 - model.collection.update({}, {'$rename' => {'error_class' => 'klass'}}, :multi => true, :safe => true) 10 + model.collection.find.update({'$rename' => {'error_class' => 'klass'}}, :multi => true, :safe => true)
11 end 11 end
12 end 12 end
13 end 13 end
db/migrate/20120603112130_change_github_url_to_github_repo.rb
1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration 1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration
2 def self.up 2 def self.up
3 - App.collection.update({}, {'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true) 3 + App.collection.find.update({'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true)
4 App.all.each do |app| 4 App.all.each do |app|
5 app.send :normalize_github_repo 5 app.send :normalize_github_repo
6 app.save 6 app.save
@@ -8,7 +8,7 @@ class ChangeGithubUrlToGithubRepo &lt; Mongoid::Migration @@ -8,7 +8,7 @@ class ChangeGithubUrlToGithubRepo &lt; Mongoid::Migration
8 end 8 end
9 9
10 def self.down 10 def self.down
11 - App.collection.update({}, {'$rename' => {'github_repo' => 'github_url'}}, :multi => true, :safe => true) 11 + App.collection.find.update({'$rename' => {'github_repo' => 'github_url'}}, :multi => true, :safe => true)
12 App.all.each do |app| 12 App.all.each do |app|
13 unless app.github_repo.include?("github.com") 13 unless app.github_repo.include?("github.com")
14 app.update_attribute :github_url, "https://github.com/" << app.github_url 14 app.update_attribute :github_url, "https://github.com/" << app.github_url