Commit 4b00b5760908151b139c078a9c502662eacdd5c4

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

fix mongoid migrations

Gemfile
... ... @@ -3,9 +3,8 @@ source 'http://rubygems.org'
3 3 gem 'rails', '3.2.13'
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 8 gem 'haml'
10 9 gem 'htmlentities'
11 10 gem 'rack-ssl', :require => 'rack/ssl' # force SSL
... ...
Gemfile.lock
... ... @@ -185,11 +185,11 @@ GEM
185 185 moped (~> 1.4)
186 186 origin (~> 1.0)
187 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 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 193 moped (1.5.1)
194 194 multi_json (1.7.9)
195 195 multi_xml (0.5.5)
... ... @@ -392,7 +392,7 @@ DEPENDENCIES
392 392 database_cleaner (~> 0.9.0)
393 393 debugger
394 394 decent_exposure
395   - devise (~> 2.2.6)
  395 + devise
396 396 email_spec
397 397 execjs
398 398 fabrication (~> 1.3.0)
... ... @@ -412,7 +412,7 @@ DEPENDENCIES
412 412 lighthouse-api
413 413 meta_request
414 414 mongoid (~> 3.1.4)
415   - mongoid_rails_migrations (~> 0.0.14)
  415 + mongoid_rails_migrations (~> 1.0.1)
416 416 octokit
417 417 omniauth-github
418 418 oruen_redmine_client
... ...
db/migrate/20110422152027_move_notices_to_separate_collection.rb
1 1 class MoveNoticesToSeparateCollection < Mongoid::Migration
2 2 def self.up
  3 + errs_coll = connection["errs"]
  4 +
3 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 7 errs.each do |err|
7 8 next unless err['notices']
8 9  
... ... @@ -18,7 +19,7 @@ class MoveNoticesToSeparateCollection &lt; Mongoid::Migration
18 19 e.notices.create!(notice)
19 20 end
20 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 23 end
23 24 Rake::Task["errbit:db:update_notices_count"].invoke
24 25 Rake::Task["errbit:db:update_problem_attrs"].invoke
... ...
db/migrate/20120530005915_rename_klass_to_error_class.rb
1 1 class RenameKlassToErrorClass < Mongoid::Migration
2 2 def self.up
3 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 5 end
6 6 end
7 7  
8 8 def self.down
9 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 11 end
12 12 end
13 13 end
... ...
db/migrate/20120603112130_change_github_url_to_github_repo.rb
1 1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration
2 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 4 App.all.each do |app|
5 5 app.send :normalize_github_repo
6 6 app.save
... ... @@ -8,7 +8,7 @@ class ChangeGithubUrlToGithubRepo &lt; Mongoid::Migration
8 8 end
9 9  
10 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 12 App.all.each do |app|
13 13 unless app.github_repo.include?("github.com")
14 14 app.update_attribute :github_url, "https://github.com/" << app.github_url
... ...