Skip to content

Instantly share code, notes, and snippets.

@kamipo kamipo/database.yml
Last active Jan 21, 2018

Embed
What would you like to do?
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
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
You can’t perform that action at this time.