diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-10-09 10:28:46 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-10-09 21:32:34 +0200 |
commit | 022205be1d677d446437af0618697434472157e8 (patch) | |
tree | d310646fb489b71199f631aaae757cb983db6b5a /activerecord/lib | |
parent | 4377f8eba2dde51fe5d3bc50248c0089e24c8d24 (diff) | |
download | rails-022205be1d677d446437af0618697434472157e8.tar.gz rails-022205be1d677d446437af0618697434472157e8.tar.bz2 rails-022205be1d677d446437af0618697434472157e8.zip |
Add callback on skipped migration while copying migrations
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 3fc69d7af0..a4c09b654a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -384,23 +384,32 @@ module ActiveRecord end end - def copy(destination, sources) + def copy(destination, sources, options = {}) copied = [] + destination_migrations = ActiveRecord::Migrator.migrations(destination) + last = destination_migrations.last sources.each do |name, path| - destination_migrations = ActiveRecord::Migrator.migrations(destination) source_migrations = ActiveRecord::Migrator.migrations(path) - last = destination_migrations.last source_migrations.each do |migration| - next if destination_migrations.any? { |m| m.name == migration.name } + source = File.read(migration.filename) + source = "# This migration comes from #{name} (originally #{migration.version})\n#{source}" + + if duplicate = destination_migrations.detect { |m| m.name == migration.name } + options[:on_skip].call(name, migration) if File.read(duplicate.filename) != source && options[:on_skip] + next + end migration.version = next_migration_number(last ? last.version + 1 : 0).to_i + new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.rb") + old_path, migration.filename = migration.filename, new_path last = migration - new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.rb") - FileUtils.cp(migration.filename, new_path) - copied << new_path + FileUtils.cp(old_path, migration.filename) + copied << migration + options[:on_copy].call(name, migration, old_path) if options[:on_copy] + destination_migrations << migration end end @@ -426,6 +435,10 @@ module ActiveRecord @migration = nil end + def basename + File.basename(filename) + end + delegate :migrate, :announce, :write, :to=>:migration private |