diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-12-22 12:10:40 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-12-22 20:40:42 -0500 |
commit | a4932d6a63e9883408537145e1f81477c27df3fc (patch) | |
tree | 09dd205dd8131fb1e24fa62e0adfc7b8bfd73b9d /activerecord/lib | |
parent | f9da785d0b1b22317cfca25c15fb555e9016accb (diff) | |
download | rails-a4932d6a63e9883408537145e1f81477c27df3fc.tar.gz rails-a4932d6a63e9883408537145e1f81477c27df3fc.tar.bz2 rails-a4932d6a63e9883408537145e1f81477c27df3fc.zip |
Fixes for PR [#8267]
* Fix Migration#reversible by not using `transaction`.
* Adapt mysql adapter to updated api for remove_column
* Update test after aedcd683684d08eaf30623a4b48ce31a31426372
Diffstat (limited to 'activerecord/lib')
3 files changed, 18 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index d37e489f5c..124a2419ec 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -669,10 +669,13 @@ module ActiveRecord rename_column_sql end - def remove_column_sql(table_name, *column_names) - columns_for_remove(table_name, *column_names).map {|column_name| "DROP #{column_name}" } + def remove_column_sql(table_name, column_name, type = nil, options = {}) + "DROP #{quote_column_name(column_name)}" + end + + def remove_columns_sql(table_name, *column_names) + column_names.map {|column_name| remove_column_sql(table_name, column_name) } end - alias :remove_columns_sql :remove_column def add_index_sql(table_name, column_name, options = {}) index_name, index_type, index_columns = add_index_options(table_name, column_name, options) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 273af32237..67339c05e5 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -477,7 +477,7 @@ module ActiveRecord # end def reversible helper = ReversibleBlockHelper.new(reverting?) - transaction{ yield helper } + execute_block{ yield helper } end # Runs the given migration classes. @@ -639,6 +639,15 @@ module ActiveRecord "%.3d" % number end end + + private + def execute_block + if connection.respond_to? :execute_block + super # use normal delegation to record the block + else + yield + end + end end # MigrationProxy is used to defer loading of the actual migration classes diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index a6377185a8..79c55045ba 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, :rename_table, :add_column, :remove_column, :rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps, :change_column_default, :add_reference, :remove_reference, :transaction, - :drop_join_table, :drop_table, + :drop_join_table, :drop_table, :execute_block, :change_column, :execute, :remove_columns, # irreversible methods need to be here too ].each do |method| class_eval <<-EOV, __FILE__, __LINE__ + 1 @@ -94,6 +94,7 @@ module ActiveRecord module StraightReversions private { transaction: :transaction, + execute_block: :execute_block, create_table: :drop_table, create_join_table: :drop_join_table, add_column: :remove_column, |