Skip to content

Commit 9a8e4e8

Browse files
authored
Merge pull request #94 from coord-e/fix-collation-migration
Fix column collations and table default collation in a migration
2 parents 79f25d3 + 6b3d85e commit 9a8e4e8

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Support Ruby 3.0
66
- Drop support for Ruby < 3.0
77
- Drop support for MySQL 5.7
8+
- A new migration is added to fix collations properly in MySQL 8.0
89

910
## v2.8.0 (2021-12-23)
1011
### New features
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# In MySQL 8.0, the default collation for utf8mb4 is changed to utf8mb4_0900_ai_ci.
2+
# The column collations are utf8mb4_0900_ai_ci after we ran migrations prior to this
3+
# on MySQL 8.0 because we did not specify collation in create_table (thus the default is used).
4+
# This happens on testing/development but we want to keep utf8mb4_general_ci.
5+
#
6+
# Note that running this should not affect the actual schema and data
7+
# unless you've ran prior migrations on MySQL 8.0.
8+
class FixCollations < ActiveRecord::Migration[6.1]
9+
def change
10+
reversible do |direction|
11+
direction.up do
12+
# alter column collations and default collation of every tables defined to utf8mb4_general_ci
13+
execute 'ALTER TABLE barbeque_apps CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
14+
execute 'ALTER TABLE barbeque_docker_containers CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
15+
execute 'ALTER TABLE barbeque_ecs_hako_tasks CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
16+
execute 'ALTER TABLE barbeque_job_executions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
17+
execute 'ALTER TABLE barbeque_job_queues CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
18+
execute 'ALTER TABLE barbeque_job_retries CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
19+
execute 'ALTER TABLE barbeque_retry_configs CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
20+
execute 'ALTER TABLE barbeque_slack_notifications CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
21+
execute 'ALTER TABLE barbeque_sns_subscriptions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
22+
23+
# barbeque_job_definitions contains a column with explicitly specified collation
24+
execute 'ALTER TABLE barbeque_job_definitions DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'
25+
change_column :barbeque_job_definitions, :command, :string, collation: 'utf8mb4_general_ci'
26+
change_column :barbeque_job_definitions, :description, :text, collation: 'utf8mb4_general_ci'
27+
end
28+
29+
direction.down do
30+
raise ActiveRecord::IrreversibleMigration
31+
end
32+
end
33+
end
34+
end

spec/dummy/db/schema.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# of editing this file, please use the migrations feature of Active Record to
33
# incrementally modify your database, and then regenerate this schema definition.
44
#
5-
# Note that this schema.rb definition is the authoritative source for your
6-
# database schema. If you need to create the application database on another
7-
# system, you should be using db:schema:load, not running all the migrations
8-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9-
# you'll amass, the slower it'll run and the greater likelihood for issues).
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_10_29_105530) do
13+
ActiveRecord::Schema.define(version: 2024_04_15_080757) do
1414

15-
create_table "barbeque_apps", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
15+
create_table "barbeque_apps", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
1616
t.string "name", null: false
1717
t.string "docker_image", null: false
1818
t.text "description"
@@ -21,15 +21,15 @@
2121
t.index ["name"], name: "index_barbeque_apps_on_name", unique: true
2222
end
2323

24-
create_table "barbeque_docker_containers", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
24+
create_table "barbeque_docker_containers", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
2525
t.string "message_id", null: false
2626
t.string "container_id", null: false
2727
t.datetime "created_at", null: false
2828
t.datetime "updated_at", null: false
2929
t.index ["message_id"], name: "index_barbeque_docker_containers_on_message_id", unique: true
3030
end
3131

32-
create_table "barbeque_ecs_hako_tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
32+
create_table "barbeque_ecs_hako_tasks", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
3333
t.string "message_id", null: false
3434
t.string "cluster", null: false
3535
t.string "task_arn", null: false
@@ -38,7 +38,7 @@
3838
t.index ["message_id"], name: "index_barbeque_ecs_hako_tasks_on_message_id", unique: true
3939
end
4040

41-
create_table "barbeque_job_definitions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
41+
create_table "barbeque_job_definitions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
4242
t.string "job", null: false, collation: "utf8mb4_bin"
4343
t.integer "app_id", null: false
4444
t.string "command", null: false
@@ -48,7 +48,7 @@
4848
t.index ["job", "app_id"], name: "index_barbeque_job_definitions_on_job_and_app_id", unique: true
4949
end
5050

51-
create_table "barbeque_job_executions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
51+
create_table "barbeque_job_executions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
5252
t.string "message_id", null: false
5353
t.integer "status", default: 0, null: false
5454
t.datetime "created_at", null: false
@@ -62,7 +62,7 @@
6262
t.index ["status"], name: "index_barbeque_job_executions_on_status"
6363
end
6464

65-
create_table "barbeque_job_queues", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
65+
create_table "barbeque_job_queues", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
6666
t.string "name", null: false
6767
t.text "description"
6868
t.string "queue_url", null: false
@@ -71,7 +71,7 @@
7171
t.index ["name"], name: "index_barbeque_job_queues_on_name", unique: true
7272
end
7373

74-
create_table "barbeque_job_retries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
74+
create_table "barbeque_job_retries", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
7575
t.string "message_id", null: false
7676
t.integer "job_execution_id", null: false
7777
t.integer "status", default: 0, null: false
@@ -82,7 +82,7 @@
8282
t.index ["status"], name: "index_barbeque_job_retries_on_status"
8383
end
8484

85-
create_table "barbeque_retry_configs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
85+
create_table "barbeque_retry_configs", charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
8686
t.integer "job_definition_id", null: false
8787
t.integer "retry_limit", default: 3, null: false
8888
t.float "base_delay", default: 15.0, null: false
@@ -93,7 +93,7 @@
9393
t.index ["job_definition_id"], name: "index_barbeque_retry_configs_on_job_definition_id", unique: true
9494
end
9595

96-
create_table "barbeque_slack_notifications", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
96+
create_table "barbeque_slack_notifications", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
9797
t.integer "job_definition_id"
9898
t.string "channel", null: false
9999
t.boolean "notify_success", default: false, null: false
@@ -103,7 +103,7 @@
103103
t.boolean "notify_failure_only_if_retry_limit_reached", default: false, null: false
104104
end
105105

106-
create_table "barbeque_sns_subscriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
106+
create_table "barbeque_sns_subscriptions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
107107
t.string "topic_arn", null: false
108108
t.integer "job_queue_id", null: false
109109
t.integer "job_definition_id", null: false

0 commit comments

Comments
 (0)