From 4b00b5760908151b139c078a9c502662eacdd5c4 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Tue, 20 Aug 2013 10:06:55 -0400 Subject: [PATCH] fix mongoid migrations --- Gemfile | 5 ++--- Gemfile.lock | 12 ++++++------ db/migrate/20110422152027_move_notices_to_separate_collection.rb | 7 ++++--- db/migrate/20120530005915_rename_klass_to_error_class.rb | 4 ++-- db/migrate/20120603112130_change_github_url_to_github_repo.rb | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index d0df896..4796c2d 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,8 @@ source 'http://rubygems.org' gem 'rails', '3.2.13' gem 'mongoid', '~> 3.1.4' -# Mongoid rails migration > 0.0.14 is not compatible to Mongoid 2.x -gem 'mongoid_rails_migrations', '~> 0.0.14' -gem 'devise', '~> 2.2.6' # Last version supporting ruby 1.8.7 +gem 'mongoid_rails_migrations', '~> 1.0.1' +gem 'devise' gem 'haml' gem 'htmlentities' gem 'rack-ssl', :require => 'rack/ssl' # force SSL diff --git a/Gemfile.lock b/Gemfile.lock index bebfe4c..1da086f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -185,11 +185,11 @@ GEM moped (~> 1.4) origin (~> 1.0) tzinfo (~> 0.3.22) - mongoid_rails_migrations (0.0.14) - activesupport (>= 3.0.0) + mongoid_rails_migrations (1.0.1) + activesupport (>= 3.2.0) bundler (>= 1.0.0) - rails (>= 3.0.0) - railties (>= 3.0.0) + rails (>= 3.2.0) + railties (>= 3.2.0) moped (1.5.1) multi_json (1.7.9) multi_xml (0.5.5) @@ -392,7 +392,7 @@ DEPENDENCIES database_cleaner (~> 0.9.0) debugger decent_exposure - devise (~> 2.2.6) + devise email_spec execjs fabrication (~> 1.3.0) @@ -412,7 +412,7 @@ DEPENDENCIES lighthouse-api meta_request mongoid (~> 3.1.4) - mongoid_rails_migrations (~> 0.0.14) + mongoid_rails_migrations (~> 1.0.1) octokit omniauth-github oruen_redmine_client diff --git a/db/migrate/20110422152027_move_notices_to_separate_collection.rb b/db/migrate/20110422152027_move_notices_to_separate_collection.rb index 4e76918..268022a 100644 --- a/db/migrate/20110422152027_move_notices_to_separate_collection.rb +++ b/db/migrate/20110422152027_move_notices_to_separate_collection.rb @@ -1,8 +1,9 @@ class MoveNoticesToSeparateCollection < Mongoid::Migration def self.up + errs_coll = connection["errs"] + # copy embedded Notices into a separate collection - mongo_db = Err.db - errs = mongo_db.collection("errs").find({ }, :fields => ["notices"]) + errs = errs_coll.find.select(notices: 1) errs.each do |err| next unless err['notices'] @@ -18,7 +19,7 @@ class MoveNoticesToSeparateCollection < Mongoid::Migration e.notices.create!(notice) end e.app.update_attribute(:notify_on_errs, old_notify) - mongo_db.collection("errs").update({ "_id" => err['_id']}, { "$unset" => { "notices" => 1}}) + errs_coll.find({ "_id" => err['_id']}).update({ "$unset" => { "notices" => 1}}) end Rake::Task["errbit:db:update_notices_count"].invoke Rake::Task["errbit:db:update_problem_attrs"].invoke diff --git a/db/migrate/20120530005915_rename_klass_to_error_class.rb b/db/migrate/20120530005915_rename_klass_to_error_class.rb index ceab8a1..e752b35 100644 --- a/db/migrate/20120530005915_rename_klass_to_error_class.rb +++ b/db/migrate/20120530005915_rename_klass_to_error_class.rb @@ -1,13 +1,13 @@ class RenameKlassToErrorClass < Mongoid::Migration def self.up [Problem, Err, Notice].each do |model| - model.collection.update({}, {'$rename' => {'klass' => 'error_class'}}, :multi => true, :safe => true) + model.collection.find.update({'$rename' => {'klass' => 'error_class'}}, :multi => true, :safe => true) end end def self.down [Problem, Err, Notice].each do |model| - model.collection.update({}, {'$rename' => {'error_class' => 'klass'}}, :multi => true, :safe => true) + model.collection.find.update({'$rename' => {'error_class' => 'klass'}}, :multi => true, :safe => true) end end end diff --git a/db/migrate/20120603112130_change_github_url_to_github_repo.rb b/db/migrate/20120603112130_change_github_url_to_github_repo.rb index 76b6d87..1b28226 100644 --- a/db/migrate/20120603112130_change_github_url_to_github_repo.rb +++ b/db/migrate/20120603112130_change_github_url_to_github_repo.rb @@ -1,6 +1,6 @@ class ChangeGithubUrlToGithubRepo < Mongoid::Migration def self.up - App.collection.update({}, {'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true) + App.collection.find.update({'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true) App.all.each do |app| app.send :normalize_github_repo app.save @@ -8,7 +8,7 @@ class ChangeGithubUrlToGithubRepo < Mongoid::Migration end def self.down - App.collection.update({}, {'$rename' => {'github_repo' => 'github_url'}}, :multi => true, :safe => true) + App.collection.find.update({'$rename' => {'github_repo' => 'github_url'}}, :multi => true, :safe => true) App.all.each do |app| unless app.github_repo.include?("github.com") app.update_attribute :github_url, "https://github.com/" << app.github_url -- libgit2 0.21.2