Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
18 changes: 8 additions & 10 deletions ar_innodb_row_format.rb
Original file line number Diff line number Diff line change
@@ -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