File: force-table-encoding-in-mysql.patch

package info (click to toggle)
redmine 6.0.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,100 kB
  • sloc: ruby: 116,319; javascript: 12,885; sh: 460; perl: 303; python: 166; makefile: 30
file content (38 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
Author: Jérémy Lal <kapouer@melix.org>
Forwarded: not-needed
Last-Update: 2025-02-04

--- 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
   # Undefines private Kernel#open method to allow using `open` scopes in models.
   # See Defect #11545 (http://www.redmine.org/issues/11545) for details.
@@ -10,6 +12,18 @@ module ActiveRecord
   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