Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve collation when changing column in MySQL #45744

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ def build_change_column_definition(table_name, column_name, type, **options) # :
options[:comment] = column.comment
end

unless options.key?(:collation)
options[:collation] = column.collation
end

unless options.key?(:auto_increment)
options[:auto_increment] = column.auto_increment?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class Mysql2CharsetCollationTest < ActiveRecord::Mysql2TestCase
assert_equal "utf8mb4_general_ci", column.collation
end

test "change column preserves collation" do
@connection.add_column :charset_collations, :description, :string, charset: "utf8mb4", collation: "utf8mb4_unicode_ci"
@connection.change_column :charset_collations, :description, :text

column = @connection.columns(:charset_collations).find { |c| c.name == "description" }
assert_equal :text, column.type
assert_equal "utf8mb4_unicode_ci", column.collation
end

test "schema dump includes collation" do
output = dump_table_schema("charset_collations")
assert_match %r/create_table "charset_collations", id: { type: :string, collation: "utf8mb4_bin" }/, output
Expand Down