diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-11-19 01:12:36 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-12-21 13:54:52 -0500 |
commit | af871a0623740f53a4dca5858b78efb35f0e32e0 (patch) | |
tree | e8a1f4983b6654a792bdcd93348ee2d3df84d850 /activerecord/lib/active_record/migration | |
parent | bd155d2ae31a1e4c19274cfef6049d66136fd0cd (diff) | |
download | rails-af871a0623740f53a4dca5858b78efb35f0e32e0.tar.gz rails-af871a0623740f53a4dca5858b78efb35f0e32e0.tar.bz2 rails-af871a0623740f53a4dca5858b78efb35f0e32e0.zip |
Make drop_table reversible [#8267]
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r-- | activerecord/lib/active_record/migration/command_recorder.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index 8dad1b123f..f37ec1feaa 100644 --- a/activerecord/lib/active_record/migration/command_recorder.rb +++ b/activerecord/lib/active_record/migration/command_recorder.rb @@ -73,7 +73,7 @@ module ActiveRecord [:create_table, :create_join_table, :change_table, :rename_table, :add_column, :remove_column, :rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps, :change_column, :change_column_default, :add_reference, :remove_reference, :transaction, - :drop_join_table, + :drop_join_table, :drop_table ].each do |method| class_eval <<-EOV, __FILE__, __LINE__ + 1 def #{method}(*args, &block) # def create_table(*args, &block) @@ -90,8 +90,15 @@ module ActiveRecord [:transaction, args, block] end - def invert_create_table(args) - [:drop_table, [args.first]] + def invert_create_table(args, &block) + [:drop_table, args, block] + end + + def invert_drop_table(args, &block) + if args.size == 1 && block == nil + raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)." + end + [:create_table, args, block] end def invert_create_join_table(args, &block) |