diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-02 08:29:00 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-05 17:31:04 +0900 |
commit | 214dc7d82d8a87914d5d426b7e8460300000acc2 (patch) | |
tree | 4c9f975a30db11387185b7ace244fb5930f2a419 /activerecord | |
parent | bd2542b74fe528d95f51d8f3668b0f7d6d8af974 (diff) | |
download | rails-214dc7d82d8a87914d5d426b7e8460300000acc2.tar.gz rails-214dc7d82d8a87914d5d426b7e8460300000acc2.tar.bz2 rails-214dc7d82d8a87914d5d426b7e8460300000acc2.zip |
Extract repeatedly appeared prepending compatible table definition
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index 502cef2e20..2b247f7a7a 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -52,11 +52,8 @@ module ActiveRecord end if block_given? - super(table_name, options) do |t| - class << t - prepend TableDefinition - end - yield t + super do |t| + yield compatible_table_definition(t) end else super @@ -65,11 +62,8 @@ module ActiveRecord def change_table(table_name, options = {}) if block_given? - super(table_name, options) do |t| - class << t - prepend TableDefinition - end - yield t + super do |t| + yield compatible_table_definition(t) end else super @@ -80,11 +74,8 @@ module ActiveRecord column_options.reverse_merge!(type: :integer) if block_given? - super(table_1, table_2, column_options: column_options, **options) do |t| - class << t - prepend TableDefinition - end - yield t + super do |t| + yield compatible_table_definition(t) end else super @@ -103,6 +94,14 @@ module ActiveRecord super(table_name, ref_name, type: :integer, **options) end alias :add_belongs_to :add_reference + + private + def compatible_table_definition(t) + class << t + prepend TableDefinition + end + t + end end class V4_2 < V5_0 @@ -121,11 +120,8 @@ module ActiveRecord def create_table(table_name, options = {}) if block_given? - super(table_name, options) do |t| - class << t - prepend TableDefinition - end - yield t + super do |t| + yield compatible_table_definition(t) end else super @@ -134,11 +130,8 @@ module ActiveRecord def change_table(table_name, options = {}) if block_given? - super(table_name, options) do |t| - class << t - prepend TableDefinition - end - yield t + super do |t| + yield compatible_table_definition(t) end else super @@ -174,6 +167,12 @@ module ActiveRecord end private + def compatible_table_definition(t) + class << t + prepend TableDefinition + end + t + end def index_name_for_remove(table_name, options = {}) index_name = index_name(table_name, options) |