Date: Sat, 19 Sep 2015 17:42:05 -0300
Last-Update: 2022-03-29
Forwarded: not-needed
Author: Jérémy Lal <kapouer@melix.org>
Description: 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
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -1,5 +1,7 @@
 # frozen_string_literal: true
 
+require 'active_record/connection_adapters/abstract_mysql_adapter'
+
 module ActiveRecord
   class Base
     # Translate attribute names for validation errors display
@@ -26,6 +28,18 @@
     end
   end
   class Relation ; undef open ; end
+
+  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 ActionView
