From b0ef4509a685870617233198a096fc0e335179d3 Mon Sep 17 00:00:00 2001 From: Dumitru Ursu Date: Mon, 19 Jan 2015 02:09:39 +0200 Subject: [PATCH] Change the adapter encoding to utf8mb4 --- config/database.yml.example | 4 +- ...20150106050733_set_mysql_to_unicode_mb4.rb | 38 +++++++++++++++++++ db/schema.rb | 7 ++-- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb diff --git a/config/database.yml.example b/config/database.yml.example index baec2fbbf..38f15f3c8 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -5,7 +5,7 @@ mysql: &mysql username: "root" password: "" # socket: /tmp/mysql.sock - charset: utf8 + charset: utf8mb4 collation: utf8_bin postgres: &postgres @@ -25,7 +25,7 @@ common: &common # Should match environment.sidekiq.concurrency #pool: 25 - + ################################################## #### CONFIGURE ABOVE ############################# ################################################## diff --git a/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb b/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb new file mode 100644 index 000000000..a4abd5b36 --- /dev/null +++ b/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb @@ -0,0 +1,38 @@ +class SetMysqlToUnicodeMb4 < ActiveRecord::Migration + + UTF8_PAIRS = { + 'comments': 'text', + 'messages': 'text', + 'poll_answers': 'answer', + 'polls': 'question', + 'posts': 'text', + } + + def self.up + if ENV['DB'] == 'mysql' + execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET utf8mb4;" + + ActiveRecord::Base.connection.tables.each do |table| + execute "ALTER TABLE `#{table}` CHARACTER SET = utf8mb4;" + end + + UTF8_PAIRS.each do |table, col| + execute "ALTER TABLE `#{table}` CHANGE `#{col}` `#{col}` TEXT CHARACTER SET utf8mb4 NULL;" + end + end + end + + def self.down + if ENV['DB'] == 'mysql' + execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET utf8;" + + ActiveRecord::Base.connection.tables.each do |table| + execute "ALTER TABLE `#{table}` CHARACTER SET = utf8;" + end + + UTF8_PAIRS.each do |table, col| + execute "ALTER TABLE `#{table}` CHANGE `#{col}` `#{col}` TEXT CHARACTER SET utf8 NULL;" + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e2251207a..0521d0fa3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141230214830) do +ActiveRecord::Schema.define(version: 20150106050733) do create_table "account_deletions", force: true do |t| t.string "diaspora_handle" @@ -66,6 +66,7 @@ ActiveRecord::Schema.define(version: 20141230214830) do t.string "name" t.string "ask", limit: 128 t.string "subscription", limit: 128, null: false + t.text "groups" end add_index "chat_contacts", ["user_id", "jid"], name: "index_chat_contacts_on_user_id_and_jid", unique: true, using: :btree @@ -241,7 +242,7 @@ ActiveRecord::Schema.define(version: 20141230214830) do t.text "data", null: false end - add_index "o_embed_caches", ["url"], name: "index_o_embed_caches_on_url", length: {"url"=>255}, using: :btree + add_index "o_embed_caches", ["url"], name: "index_o_embed_caches_on_url", using: :btree create_table "open_graph_caches", force: true do |t| t.string "title" @@ -429,11 +430,11 @@ ActiveRecord::Schema.define(version: 20141230214830) do create_table "reports", force: true do |t| t.integer "item_id", null: false - t.string "item_type", null: false t.boolean "reviewed", default: false t.text "text" t.datetime "created_at" t.datetime "updated_at" + t.string "item_type", null: false t.integer "user_id", null: false end