From 0292f515e10fb167b2b2ba8ab671e58879428924 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Tue, 10 Jan 2017 20:11:15 +0100 Subject: [PATCH] Fix the migration to utf8mb4 --- db/migrate/20161104094116_move_to_utf8mb4.rb | 51 ++++++++++++++------ db/schema.rb | 32 ++++++------ 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/db/migrate/20161104094116_move_to_utf8mb4.rb b/db/migrate/20161104094116_move_to_utf8mb4.rb index 260bbb7b1..f0cbb9280 100644 --- a/db/migrate/20161104094116_move_to_utf8mb4.rb +++ b/db/migrate/20161104094116_move_to_utf8mb4.rb @@ -33,48 +33,67 @@ def up execute "ALTER DATABASE #{db_name} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;" execute "ALTER TABLE friendly_id_slugs DROP KEY index_friendly_id_slugs_on_slug_and_sluggable_type;" - + execute "ALTER TABLE friendly_id_slugs DROP KEY index_slugs_on_name_and_sluggable_type_and_scope_and_sequence;" execute "ALTER TABLE nodes DROP KEY index_nodes_on_content_id_and_content_type;" execute "ALTER TABLE nodes DROP KEY index_nodes_on_content_type_and_public_and_interest;" - execute "ALTER TABLE pages DROP KEY index_pages_on_slug;" + execute "ALTER TABLE accounts DROP KEY index_accounts_on_email;" + execute "ALTER TABLE accounts DROP KEY index_accounts_on_confirmation_token;" + execute "ALTER TABLE accounts DROP KEY index_accounts_on_reset_password_token;" + execute "ALTER TABLE tags DROP KEY index_tags_on_name;" + + execute "ALTER TABLE friendly_id_slugs MODIFY COLUMN slug VARCHAR(190);" + execute "ALTER TABLE pages MODIFY COLUMN slug VARCHAR(128);" + execute "ALTER TABLE accounts MODIFY COLUMN email VARCHAR(128) NOT NULL;" + execute "ALTER TABLE accounts MODIFY COLUMN confirmation_token VARCHAR(64);" + execute "ALTER TABLE accounts MODIFY COLUMN reset_password_token VARCHAR(64);" + execute "ALTER TABLE nodes MODIFY COLUMN content_type VARCHAR(40);" TABLES.each do |tbl| execute "ALTER TABLE #{tbl} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" end - execute "ALTER TABLE friendly_id_slugs ADD UNIQUE KEY `index_friendly_id_slugs_on_slug_and_sluggable_type` (`slug`(190),`sluggable_type`) USING BTREE;" - - execute "ALTER TABLE nodes ADD UNIQUE KEY `index_nodes_on_content_id_and_content_type` (`content_id`,`content_type`(190)) USING BTREE;" - execute "ALTER TABLE nodes ADD KEY `index_nodes_on_content_type_and_public_and_interest` (`content_type`(190),`public`,`interest`) USING BTREE;" - - execute "ALTER TABLE pages ADD KEY `index_pages_on_slug` (`slug`(190)) USING BTREE;" + execute "ALTER TABLE friendly_id_slugs ADD UNIQUE KEY `index_friendly_id_slugs_on_slug_and_sluggable_type` (`slug`,`sluggable_type`) USING BTREE;" + execute "ALTER TABLE nodes ADD UNIQUE KEY `index_nodes_on_content_id_and_content_type` (`content_id`,`content_type`) USING BTREE;" + execute "ALTER TABLE nodes ADD KEY `index_nodes_on_content_type_and_public_and_interest` (`content_type`,`public`,`interest`) USING BTREE;" + execute "ALTER TABLE pages ADD KEY `index_pages_on_slug` (`slug`) USING BTREE;" + execute "ALTER TABLE accounts ADD UNIQUE KEY `index_accounts_on_email` (`email`) USING BTREE;" + execute "ALTER TABLE accounts ADD UNIQUE KEY `index_accounts_on_confirmation_token` (`confirmation_token`) USING BTREE;" + execute "ALTER TABLE accounts ADD UNIQUE KEY `index_accounts_on_reset_password_token` (`reset_password_token`) USING BTREE;" + execute "ALTER TABLE tags ADD UNIQUE KEY `index_tags_on_name` (`name`) USING BTREE;" end def down execute "ALTER DATABASE #{db_name} CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;" execute "ALTER TABLE friendly_id_slugs DROP KEY index_friendly_id_slugs_on_slug_and_sluggable_type;" - execute "ALTER TABLE nodes DROP KEY index_nodes_on_content_id_and_content_type;" execute "ALTER TABLE nodes DROP KEY index_nodes_on_content_type_and_public_and_interest;" - - execute "ALTER TABLE oauth_applications DROP KEY index_oauth_applications_on_owner_id_and_owner_type;" - execute "ALTER TABLE pages DROP KEY index_pages_on_slug;" + execute "ALTER TABLE accounts DROP KEY index_accounts_on_email;" + execute "ALTER TABLE accounts DROP KEY index_accounts_on_confirmation_token;" + execute "ALTER TABLE accounts DROP KEY index_accounts_on_reset_password_token;" + execute "ALTER TABLE tags DROP KEY index_tags_on_name;" TABLES.each do |tbl| execute "ALTER TABLE #{tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;" end - execute "ALTER TABLE friendly_id_slugs ADD UNIQUE KEY `index_friendly_id_slugs_on_slug_and_sluggable_type` (`slug`,`sluggable_type`) USING BTREE;" + execute "ALTER TABLE friendly_id_slugs MODIFY COLUMN slug VARCHAR(255);" + execute "ALTER TABLE pages MODIFY COLUMN slug VARCHAR(255);" + execute "ALTER TABLE accounts MODIFY COLUMN email VARCHAR(255);" + execute "ALTER TABLE accounts MODIFY COLUMN confirmation_token VARCHAR(255);" + execute "ALTER TABLE accounts MODIFY COLUMN reset_password_token VARCHAR(255);" + execute "ALTER TABLE nodes MODIFY COLUMN content_type VARCHAR(255);" + execute "ALTER TABLE friendly_id_slugs ADD UNIQUE KEY `index_friendly_id_slugs_on_slug_and_sluggable_type` (`slug`,`sluggable_type`) USING BTREE;" execute "ALTER TABLE nodes ADD UNIQUE KEY `index_nodes_on_content_id_and_content_type` (`content_id`,`content_type`) USING BTREE;" execute "ALTER TABLE nodes ADD KEY `index_nodes_on_content_type_and_public_and_interest` (`content_type`,`public`,`interest`) USING BTREE;" - - execute "ALTER TABLE oauth_applications ADD KEY `index_oauth_applications_on_owner_id_and_owner_type` (`owner_id`,`owner_type`) USING BTREE;" - execute "ALTER TABLE pages ADD KEY `index_pages_on_slug` (`slug`) USING BTREE;" + execute "ALTER TABLE accounts ADD UNIQUE KEY `index_accounts_on_email` (`email`) USING BTREE;" + execute "ALTER TABLE accounts ADD UNIQUE KEY `index_accounts_on_confirmation_token` (`confirmation_token`) USING BTREE;" + execute "ALTER TABLE accounts ADD UNIQUE KEY `index_accounts_on_reset_password_token` (`reset_password_token`) USING BTREE;" + execute "ALTER TABLE tags ADD UNIQUE KEY `index_tags_on_name` (`name`) USING BTREE;" end def db_name diff --git a/db/schema.rb b/db/schema.rb index 619566915..ede79839c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -20,12 +20,12 @@ t.integer "karma", limit: 4, default: 20, null: false t.integer "nb_votes", limit: 4, default: 0, null: false t.string "stylesheet", limit: 255 - t.string "email", limit: 255, default: "", null: false + t.string "email", limit: 128, null: false t.string "encrypted_password", limit: 128, default: "", null: false - t.string "confirmation_token", limit: 255 + t.string "confirmation_token", limit: 64 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "reset_password_token", limit: 255 + t.string "reset_password_token", limit: 64 t.datetime "remember_created_at" t.integer "sign_in_count", limit: 4, default: 0 t.datetime "current_sign_in_at" @@ -80,7 +80,7 @@ t.boolean "answered_to_self", default: false, null: false t.string "materialized_path", limit: 1022 t.text "body", limit: 4294967295 - t.text "wiki_body", limit: 16777215 + t.text "wiki_body", limit: 4294967295 t.datetime "created_at" t.datetime "updated_at" end @@ -126,13 +126,13 @@ add_index "friend_sites", ["position"], name: "index_friend_sites_on_position", using: :btree create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", limit: 255 + t.string "slug", limit: 190 t.integer "sluggable_id", limit: 4 t.string "sluggable_type", limit: 40 t.datetime "created_at" end - add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", length: {"slug"=>190, "sluggable_type"=>nil}, using: :btree + add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", using: :btree add_index "friendly_id_slugs", ["sluggable_id"], name: "index_slugs_on_sluggable_id", using: :btree add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree @@ -192,20 +192,20 @@ create_table "nodes", force: :cascade do |t| t.integer "content_id", limit: 4 - t.string "content_type", limit: 255 + t.string "content_type", limit: 40 t.integer "user_id", limit: 4 - t.boolean "public", default: true, null: false - t.boolean "cc_licensed", default: true, null: false - t.integer "score", limit: 4, default: 0, null: false - t.integer "interest", limit: 4, default: 0, null: false - t.integer "comments_count", limit: 4, default: 0, null: false + t.boolean "public", default: true, null: false + t.boolean "cc_licensed", default: true, null: false + t.integer "score", limit: 4, default: 0, null: false + t.integer "interest", limit: 4, default: 0, null: false + t.integer "comments_count", limit: 4, default: 0, null: false t.datetime "last_commented_at" t.datetime "created_at" t.datetime "updated_at" end - add_index "nodes", ["content_id", "content_type"], name: "index_nodes_on_content_id_and_content_type", unique: true, length: {"content_id"=>nil, "content_type"=>190}, using: :btree - add_index "nodes", ["content_type", "public", "interest"], name: "index_nodes_on_content_type_and_public_and_interest", length: {"content_type"=>190, "public"=>nil, "interest"=>nil}, using: :btree + add_index "nodes", ["content_id", "content_type"], name: "index_nodes_on_content_id_and_content_type", unique: true, using: :btree + add_index "nodes", ["content_type", "public", "interest"], name: "index_nodes_on_content_type_and_public_and_interest", using: :btree add_index "nodes", ["public", "created_at"], name: "index_nodes_on_public_and_created_at", using: :btree add_index "nodes", ["public", "interest"], name: "index_nodes_on_public_and_interest", using: :btree add_index "nodes", ["public", "last_commented_at"], name: "index_nodes_on_public_and_last_commented_at", using: :btree @@ -256,14 +256,14 @@ add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree create_table "pages", force: :cascade do |t| - t.string "slug", limit: 255 + t.string "slug", limit: 128 t.string "title", limit: 255 t.text "body", limit: 4294967295 t.datetime "created_at" t.datetime "updated_at" end - add_index "pages", ["slug"], name: "index_pages_on_slug", length: {"slug"=>190}, using: :btree + add_index "pages", ["slug"], name: "index_pages_on_slug", using: :btree create_table "paragraphs", force: :cascade do |t| t.integer "news_id", limit: 4, null: false