Skip to content

Instantly share code, notes, and snippets.

@christos
Forked from kamipo/database.yml
Created June 15, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christos/f4c2b924df821b1b69715246097d46f0 to your computer and use it in GitHub Desktop.
Save christos/f4c2b924df821b1b69715246097d46f0 to your computer and use it in GitHub Desktop.
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