1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rename rake railties:copy_migrations to rake railties:install:migrations and fix it to work with new copying strategy

This commit is contained in:
Piotr Sarnacki 2010-10-09 12:15:36 +02:00
parent 022205be1d
commit 8636f64def
2 changed files with 42 additions and 33 deletions

View file

@ -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'

View file

@ -21,6 +21,11 @@ module RailtiesTest
end
RUBY
@plugin.write "db/migrate/3_create_sessions.rb", <<-RUBY
class CreateSessions < ActiveRecord::Migration
end
RUBY
app_file "db/migrate/1_create_sessions.rb", <<-RUBY
class CreateSessions < ActiveRecord::Migration
end
@ -38,24 +43,26 @@ module RailtiesTest
add_to_config "ActiveRecord::Base.timestamped_migrations = false"
Dir.chdir(app_path) do
output = `rake railties:copy_migrations FROM=bukkits`
output = `rake railties:install:migrations FROM=bukkits 2>&1`
assert File.exists?("#{app_path}/db/migrate/2_create_users.bukkits.rb")
assert File.exists?("#{app_path}/db/migrate/3_add_last_name_to_users.bukkits.rb")
assert_match /2_create_users/, output
assert_match /3_add_last_name_to_users/, output
assert File.exists?("#{app_path}/db/migrate/2_create_users.rb")
assert File.exists?("#{app_path}/db/migrate/3_add_last_name_to_users.rb")
assert_match /Copied migration 2_create_users.rb from bukkits/, output
assert_match /Copied migration 3_add_last_name_to_users.rb from bukkits/, output
assert_match /WARNING: Migration 3_create_sessions.rb from bukkits has been skipped/, output
assert_equal 3, Dir["#{app_path}/db/migrate/*.rb"].length
output = `rake railties:copy_migrations`
output = `rake railties:install:migrations 2>&1`
assert File.exists?("#{app_path}/db/migrate/4_create_yaffles.acts_as_yaffle.rb")
assert_match /4_create_yaffles/, output
assert File.exists?("#{app_path}/db/migrate/4_create_yaffles.rb")
assert_match /WARNING: Migration 3_create_sessions.rb from bukkits has been skipped/, output
assert_match /Copied migration 4_create_yaffles.rb from acts_as_yaffle/, output
assert_no_match /2_create_users/, output
migrations_count = Dir["#{app_path}/db/migrate/*.rb"].length
output = `rake railties:copy_migrations`
output = `rake railties:install:migrations 2>&1`
assert_equal migrations_count, Dir["#{app_path}/db/migrate/*.rb"].length
assert_match /No migrations were copied/, output
end
end