From: =?utf-8?q?J=C3=A9r=C3=A9my_Lal?= <kapouer@melix.org>
Date: Sat, 19 Sep 2015 17:42:05 -0300
Subject: Force table encoding in mysql

mysql default encoding is not UTF8, but forcing table encoding is
possible. dbconfig-common does not provide appropriate configuration
variable, so here the mysql adapter is modified to respect encoding set
in database.yml Forwarded: not-needed
---
 config/initializers/10-patches.rb | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb
index ef8b930..9a2ae43 100644
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -1,4 +1,19 @@
 require 'active_record'
+require 'active_record/connection_adapters/abstract_mysql_adapter'
+
+module ActiveRecord
+  module ConnectionAdapters
+    class MysqlAdapter < AbstractMysqlAdapter
+      def create_table(table_name, options = {}) #:nodoc:
+        encoding = @config[:encoding]
+        if encoding
+          options = options.reverse_merge(:options => "DEFAULT CHARSET=#{encoding}")
+        end
+        super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB"))
+      end
+    end
+  end
+end
 
 module ActiveRecord
   class Base
