Last active
January 21, 2018 12:40
-
-
Save kamipo/e319648b2c4752890af5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: &default | |
adapter: mysql2 | |
encoding: utf8mb4 | |
username: root | |
password: | |
host: localhost | |
variables: | |
sql_mode: TRADITIONAL,NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY | |
development: | |
<<: *default | |
database: myna_development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveSupport.on_load(:active_record) do | |
require 'active_record/connection_adapters/mysql2_adapter' | |
module ActiveRecord | |
module ConnectionAdapters | |
module MysqlMigrationExt | |
def create_table(table_name, options = {}) | |
if %w(development test).include?(Rails.env) | |
innodb_variables = [] | |
unless show_variable('innodb_file_per_table') == 1 | |
innodb_variables << 'innodb_file_per_table = 1' | |
end | |
unless show_variable('innodb_file_format') == 'Barracuda' | |
innodb_variables << 'innodb_file_format = Barracuda' | |
end | |
unless show_variable('innodb_large_prefix') == 1 | |
innodb_variables << 'innodb_large_prefix = 1' | |
end | |
unless innodb_variables.empty? | |
innodb_variables << 'innodb_strict_mode = 1' | |
execute("SET GLOBAL #{innodb_variables.join(',')}".tap { |sql| puts "NOTICE: #{sql}" }) | |
required_innodb_file_format_barracuda_message | |
end | |
end | |
super(table_name, options.reverse_merge(options: "ROW_FORMAT=DYNAMIC")) | |
end | |
def required_innodb_file_format_barracuda_message | |
puts "This application required MySQL 5.6 and innodb_file_format = Barracuda." | |
puts "Please add the following setting in your my.cnf." | |
puts "" | |
puts "```my.cnf" | |
puts "[mysqld]" | |
puts "innodb_strict_mode = 1" | |
puts "innodb_file_format = Barracuda" | |
puts "innodb_large_prefix = 1" | |
puts "innodb_file_per_table = 1" | |
puts "```" | |
puts "" | |
end | |
end | |
class Mysql2Adapter | |
include MysqlMigrationExt | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment