diff --git a/README.md b/README.md index caa59d9..2e54169 100644 --- a/README.md +++ b/README.md @@ -93,9 +93,6 @@ Global migrations can still be created with the `--no-shards` option. * `1.5.x` targets Mongoid >= `5.0` and Rails >= `4.2` * `1.4.x` targets Mongoid >= `4.0` and Rails >= `4.2` -* `1.3.x` targets Mongoid >= `4.0` and Rails >= `4.2` -* `1.2.x` targets Mongoid >= `4.0` and Rails >= `4.2` -* `1.1.x` targets Mongoid >= `4.0` and Rails >= `4.2` * `1.0.0` targers Mongoid >= `3.0` and Rails >= `3.2` * `0.0.14` targets Mongoid >= `2.0` and Rails >= `3.0` (but < `3.2`) @@ -103,16 +100,18 @@ Global migrations can still be created with the `--no-shards` option. ## Unreleased +* Remove unnecessary purge, setup, reset, etc. rake tasks because they are already defined by Mongoid (#60) +* Minor tests improvements + ## 1.5.0 _26/03/2021_ -[Compare master with 1.4.0](https://github.com/adacosta/mongoid_rails_migrations/compare/v1.4.0...master) +[Compare master with 1.5.0](https://github.com/adacosta/mongoid_rails_migrations/compare/v1.5.0...master) * Add support of multi databases * Shards migrations can now be stored in a `shards` subfolder inside the migration folder * All Rake tasks now support a custom client with the `MONGOID_CLIENT_NAME` environment variable ## 1.4.0 _08/01/2021_ -[Compare master with 1.3.0](https://github.com/adacosta/mongoid_rails_migrations/compare/v1.3.0...master) * The hook `after_migrate` can be use when migration crash (#56) ## 1.3.0 diff --git a/lib/mongoid_rails_migrations/active_record_ext/migrations.rb b/lib/mongoid_rails_migrations/active_record_ext/migrations.rb index 89b031d..2eb4eab 100644 --- a/lib/mongoid_rails_migrations/active_record_ext/migrations.rb +++ b/lib/mongoid_rails_migrations/active_record_ext/migrations.rb @@ -103,7 +103,6 @@ def migrate(direction) # it is safe for the call to proceed. def singleton_method_added(sym) #:nodoc: return if defined?(@ignore_new_methods) && @ignore_new_methods - begin @ignore_new_methods = true @@ -154,24 +153,11 @@ def suppress_messages def connection # ActiveRecord::Base.connection if ENV['MONGOID_CLIENT_NAME'] - Migrator.with_mongoid_client(ENV['MONGOID_CLIENT_NAME']) do - Mongoid.client(Mongoid::Threaded.client_override) - end + Mongoid.client(ENV['MONGOID_CLIENT_NAME']) else Mongoid.default_client end end - - def method_missing(method, *arguments, &block) - arg_list = arguments.map(&:inspect) * ', ' - - say_with_time "#{method}(#{arg_list})" do - # unless arguments.empty? || method == :execute - # arguments[0] = Migrator.proper_table_name(arguments.first) - # end - connection.send(method, *arguments, &block) - end - end end end diff --git a/lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake b/lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake index cecf39e..ad484e0 100644 --- a/lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake +++ b/lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake @@ -1,4 +1,14 @@ namespace :db do + if Rake::Task.task_defined?("db:drop") + Rake::Task["db:drop"].clear + end + + desc 'Drops the database for the current Mongoid client' + task :drop => :environment do + # Unlike Mongoid's default, this implementation supports the MONGOID_CLIENT_NAME override + Mongoid::Migration.connection.database.drop + end + desc 'Current database version' task :version => :environment do puts Mongoid::Migrator.current_version.to_s diff --git a/test/helper.rb b/test/helper.rb index 7563493..bab23c6 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -11,7 +11,7 @@ MIGRATIONS_ROOT = 'test/migrations' Mongoid.configure.load!("#{__dir__}/mongoid.yml", 'test') -require 'models/survey_schema' +require_relative 'models/survey_schema' module TestMongoidRailsMigrations class Application < Rails::Application; end @@ -19,6 +19,9 @@ class Application < Rails::Application; end TestMongoidRailsMigrations::Application.load_tasks +# Mongo debug log +# Mongo::Logger.logger = Logger.new(STDOUT) + # Hide task output class Mongoid::Migration def self.puts _ diff --git a/test/migration_test.rb b/test/migration_test.rb index eb50b39..90512a0 100644 --- a/test/migration_test.rb +++ b/test/migration_test.rb @@ -4,11 +4,8 @@ module Mongoid class TestCase < Minitest::Test #:nodoc: def setup - Mongoid::Migration.verbose = true - Mongo::Logger.logger.level = 1 - # same as db:drop command in lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake invoke("db:drop") - Mongoid::Migrator.with_mongoid_client("shard1") do + with_env("MONGOID_CLIENT_NAME" => "shard1") do invoke("db:drop") end end diff --git a/test/tasks/task_test_base.rb b/test/tasks/task_test_base.rb index 9fa0e56..8500294 100644 --- a/test/tasks/task_test_base.rb +++ b/test/tasks/task_test_base.rb @@ -1,4 +1,4 @@ -require 'helper' +require_relative '../helper' load 'lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake' diff --git a/test/tasks/version_task_test.rb b/test/tasks/version_task_test.rb index 83114e8..5ba7f0e 100644 --- a/test/tasks/version_task_test.rb +++ b/test/tasks/version_task_test.rb @@ -20,13 +20,15 @@ def test_multidatabase_version assert_output("0\n") { invoke("db:version") } end - def test_multidatabase_version_with_target_client + def test_multidatabase_version_with_target_client_and_rollback Mongoid::Migrator.migrations_path = [MIGRATIONS_ROOT + "/multi_shards"] with_env("MONGOID_CLIENT_NAME" => "shard1") do assert_output("0\n") { invoke("db:version") } invoke("db:migrate") assert_output("20210210125532\n") { invoke("db:version") } - invoke("db:drop") + invoke("db:rollback") + assert_output("20210210124656\n") { invoke("db:version") } + invoke("db:rollback") assert_output("0\n") { invoke("db:version") } end end