diff options
author | Jack Danger Canty <github@jackcanty.com> | 2014-07-30 14:51:17 -0700 |
---|---|---|
committer | Jack Danger Canty <github@jackcanty.com> | 2014-07-31 10:06:04 -0700 |
commit | d66ed3b08d8035d4bcb20a26a5739415c0b92428 (patch) | |
tree | 3b228e0ddc05687cbca47fd0766680a10808698b /activerecord/lib | |
parent | 30194a5b475ea91f9709f64a08e6645cedbe4cb5 (diff) | |
download | rails-d66ed3b08d8035d4bcb20a26a5739415c0b92428.tar.gz rails-d66ed3b08d8035d4bcb20a26a5739415c0b92428.tar.bz2 rails-d66ed3b08d8035d4bcb20a26a5739415c0b92428.zip |
Add ActiveRecord::Tasks::DatabaseTasks.migrate
This extracts the logic that was embedded in a Rake task into a static
method.
Bonus: the first test for `rake db:migrate`
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index fa94df7a52..ac385817e4 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -41,10 +41,7 @@ db_namespace = namespace :db do desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)." task :migrate => [:environment, :load_config] do - ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true - ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration| - ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope) - end + ActiveRecord::Tasks::DatabaseTasks.migrate db_namespace['_dump'].invoke if ActiveRecord::Base.dump_schema_after_migration end diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index b7315ed4b3..72e0cf3723 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -127,6 +127,16 @@ module ActiveRecord } end + def migrate + verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true + version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil + scope = ENV['SCOPE'] + Migration.verbose = verbose + Migrator.migrate(Migrator.migrations_paths, version) do |migration| + scope.blank? || scope == migration.scope + end + end + def charset_current(environment = env) charset ActiveRecord::Base.configurations[environment] end |