diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-10-09 12:15:36 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-10-09 21:32:34 +0200 |
commit | 8636f64defb4b6fd9f00c70ffc9dc7ffc017fe58 (patch) | |
tree | 441b260c5bb00e623ff2c5d22b9716c84090a711 /activerecord/lib/active_record/railties | |
parent | 022205be1d677d446437af0618697434472157e8 (diff) | |
download | rails-8636f64defb4b6fd9f00c70ffc9dc7ffc017fe58.tar.gz rails-8636f64defb4b6fd9f00c70ffc9dc7ffc017fe58.tar.bz2 rails-8636f64defb4b6fd9f00c70ffc9dc7ffc017fe58.zip |
Rename rake railties:copy_migrations to rake railties:install:migrations and fix it to work with new copying strategy
Diffstat (limited to 'activerecord/lib/active_record/railties')
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 4ef6c6f751..778bce697e 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -5,27 +5,6 @@ namespace :db do ActiveRecord::Migrator.migrations_path = Rails.application.paths["db/migrate"].first end - task :copy_migrations => :load_config do - to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map {|n| n.strip } - railties = {} - Rails.application.railties.all do |railtie| - next unless to_load == :all || to_load.include?(railtie.railtie_name) - - if railtie.respond_to?(:paths) && (path = railtie.paths["db/migrate"].first) - railties[railtie.railtie_name] = path - end - end - - copied = ActiveRecord::Migration.copy(ActiveRecord::Migrator.migrations_path, railties) - - if copied.blank? - puts "No migrations were copied, project is up to date." - else - puts "The following migrations were copied:" - puts copied.map{ |path| File.basename(path) }.join("\n") - end - end - namespace :create do # desc 'Create all the local databases defined in config/database.yml' task :all => :load_config do @@ -501,8 +480,31 @@ namespace :db do end namespace :railties do - desc "Copies missing migrations from Railties (e.g. plugins, engines). You can specify Railties to use with FROM=railtie1,railtie2" - task :copy_migrations => 'db:copy_migrations' + namespace :install do + desc "Copies missing migrations from Railties (e.g. plugins, engines). You can specify Railties to use with FROM=railtie1,railtie2" + task :migrations => :"db:load_config" do + to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map {|n| n.strip } + railties = {} + Rails.application.railties.all do |railtie| + next unless to_load == :all || to_load.include?(railtie.railtie_name) + + if railtie.respond_to?(:paths) && (path = railtie.paths["db/migrate"].first) + railties[railtie.railtie_name] = path + end + end + + on_skip = Proc.new do |name, migration| + $stderr.puts "WARNING: Migration #{migration.basename} from #{name} has been skipped. Migration with the same name already exists." + end + + on_copy = Proc.new do |name, migration, old_path| + puts "Copied migration #{migration.basename} from #{name}" + end + + ActiveRecord::Migration.copy( ActiveRecord::Migrator.migrations_path, railties, + :on_skip => on_skip, :on_copy => on_copy) + end + end end task 'test:prepare' => 'db:test:prepare' |