Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kapouer/751502 to your computer and use it in GitHub Desktop.
Save kapouer/751502 to your computer and use it in GitHub Desktop.
create table with default charset
From bffadf6a55e99291270b7c95c4787ff19ef63348 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lal?= <kapouer@melix.org>
Date: Wed, 22 Dec 2010 14:31:03 +0100
Subject: [PATCH] mysql adapter should create table with default charset.
This fixes :
https://rails.lighthouseapp.com/projects/8994/tickets/5830-mysql-adapter-should-create-table-with-default-charset
---
.../connection_adapters/mysql2_adapter.rb | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/lib/active_record/connection_adapters/mysql2_adapter.rb b/lib/active_record/connection_adapters/mysql2_adapter.rb
index 1e004f3..0c311e5 100644
--- a/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -470,6 +470,10 @@ module ActiveRecord
end
def create_table(table_name, options = {})
+ encoding = @config[:encoding]
+ if encoding
+ options = options.reverse_merge(:options => "DEFAULT CHARSET=#{encoding}")
+ end
super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB"))
end
--
1.7.2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment