From 8aeb1b4d813dfc326dbcd820469d0d89854f2171 Mon Sep 17 00:00:00 2001 From: joshweir <joshua.weir@gmail.com> Date: Tue, 26 Sep 2017 19:36:08 +1000 Subject: [PATCH] fix #1 --- README.markdown | 26 +++++++++++++------------- ar_innodb_row_format.rb | 18 ++++++++---------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/README.markdown b/README.markdown index d6f8a21..eb85e8c 100644 --- a/README.markdown +++ b/README.markdown @@ -172,20 +172,20 @@ After following the steps above your database will be converted to utf8mb4, and Create an initializer named `config/initializers/ar_innodb_row_format.rb` and paste the following code: - ActiveSupport.on_load :active_record do - module ActiveRecord::ConnectionAdapters - class AbstractMysqlAdapter - def create_table_with_innodb_row_format(table_name, options = {}) - table_options = options.reverse_merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC') - - create_table_without_innodb_row_format(table_name, table_options) do |td| - yield td if block_given? - end - end - alias_method_chain :create_table, :innodb_row_format - end - end +```ruby +ActiveSupport.on_load :active_record do + module AbstractMysqlAdapterWithInnodbRowFormatDynamic + def create_table(table_name, options = {}) + super(table_name, + options.reverse_merge( + :options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')) end + end + + ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter + .send(:prepend, AbstractMysqlAdapterWithInnodbRowFormatDynamic) +end +``` In newer versions of Rails or MySQL this monkey patch may not be necessary. diff --git a/ar_innodb_row_format.rb b/ar_innodb_row_format.rb index cbda8c4..8d630fa 100644 --- a/ar_innodb_row_format.rb +++ b/ar_innodb_row_format.rb @@ -1,14 +1,12 @@ ActiveSupport.on_load :active_record do - module ActiveRecord::ConnectionAdapters - class AbstractMysqlAdapter - def create_table_with_innodb_row_format(table_name, options = {}) - table_options = options.reverse_merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC') - - create_table_without_innodb_row_format(table_name, table_options) do |td| - yield td if block_given? - end - end - alias_method_chain :create_table, :innodb_row_format + module AbstractMysqlAdapterWithInnodbRowFormatDynamic + def create_table(table_name, options = {}) + super(table_name, + options.reverse_merge( + :options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')) end end + + ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter + .send(:prepend, AbstractMysqlAdapterWithInnodbRowFormatDynamic) end