Skip to content

Commit ac63587

Browse files
committed
In older migrations, allow column collation to be explicitly specified
1 parent 5940955 commit ac63587

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

activerecord/lib/active_record/migration/compatibility.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def rename_table(table_name, new_name, **options)
122122
def change_column(table_name, column_name, type, **options)
123123
options[:_skip_validate_options] = true
124124
if connection.adapter_name == "Mysql2" || connection.adapter_name == "Trilogy"
125-
options[:collation] = :no_collation
125+
options[:collation] ||= :no_collation
126126
end
127127
super
128128
end

activerecord/test/cases/migration/compatibility_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,21 @@ def migrate(x)
606606
connection.drop_table :more_testings rescue nil
607607
end
608608

609+
if current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
610+
def test_change_table_collation_not_unset_7_0
611+
migration = Class.new(ActiveRecord::Migration[7.0]) {
612+
def migrate(x)
613+
add_column :testings, :txt_collated, :string, charset: "utf8mb4", collation: "utf8mb4_general_ci"
614+
change_column :testings, :txt_collated, :string, default: "hi", collation: "utf8mb4_esperanto_ci"
615+
end
616+
}.new
617+
ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate
618+
column = @connection.columns(:testings).find { |c| c.name == "txt_collated" }
619+
assert_equal "hi", column.default
620+
assert_equal "utf8mb4_esperanto_ci", column.collation
621+
end
622+
end
623+
609624
def test_add_reference_on_6_0
610625
create_migration = Class.new(ActiveRecord::Migration[6.0]) {
611626
def version; 100 end

0 commit comments

Comments
 (0)