Skip to content

Instantly share code, notes, and snippets.

@gregawoods
Last active December 20, 2022 03:47
Show Gist options
  • Save gregawoods/b26751a623a56aa0a75d to your computer and use it in GitHub Desktop.
Save gregawoods/b26751a623a56aa0a75d to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.mysql</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/mysql/bin/mysqld_safe</string>
<string>--bind-address=127.0.0.1</string>
<string>--datadir=/usr/local/var/mysql</string>
<string>--innodb_file_format=Barracuda</string>
<string>--innodb_large_prefix=ON</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/var/mysql</string>
</dict>
</plist>
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.class_eval do
def create_table(table_name, options = {}) #:nodoc:
super(table_name, options.reverse_merge(:options => 'ROW_FORMAT=DYNAMIC ENGINE=InnoDB'))
end
end
end
@gregawoods
Copy link
Author

The goal of this hack is to work around a problem we ran into when using the utf8mb charset in mysql with Rails 4.

Using utf8mb4 allows us to store emoji characters in our text columns. This causes a new problem however that prevents us from creating indexes using the create_index migration. More details about that issue can be found here.

One workaround is to create your tables using the ROW_FORMAT=DYNAMIC option. Tables created this way will store their data off-page if the data is too large. More info about that can be found here.

You could resolve this by adding ROW_FORMAT=DYNAMIC to all of your migrations, but that is tedious. This code will override the default create_table migration and add that config to all of your tables by default.

@gregawoods
Copy link
Author

In order to use this solution your Mysql server will need to be configured with the following two options:

I credit serversforhackers.com for the info on innodb_large_prefix.

@gregawoods
Copy link
Author

Added sample launch deamon for users on OS X and using Homebrew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment