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

In older migrations, allow column collation to be explicitly specified #48084

Merged
merged 1 commit into from
Apr 27, 2023
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
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/migration/compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def rename_table(table_name, new_name, **options)
def change_column(table_name, column_name, type, **options)
options[:_skip_validate_options] = true
if connection.adapter_name == "Mysql2" || connection.adapter_name == "Trilogy"
options[:collation] = :no_collation
options[:collation] ||= :no_collation
end
super
end
Expand Down
15 changes: 15 additions & 0 deletions activerecord/test/cases/migration/compatibility_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,21 @@ def migrate(x)
connection.drop_table :more_testings rescue nil
end

if current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
def test_change_table_collation_not_unset_7_0
migration = Class.new(ActiveRecord::Migration[7.0]) {
def migrate(x)
add_column :testings, :txt_collated, :string, charset: "utf8mb4", collation: "utf8mb4_general_ci"
change_column :testings, :txt_collated, :string, default: "hi", collation: "utf8mb4_esperanto_ci"
end
}.new
ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate
column = @connection.columns(:testings).find { |c| c.name == "txt_collated" }
assert_equal "hi", column.default
assert_equal "utf8mb4_esperanto_ci", column.collation
end
end

def test_add_reference_on_6_0
create_migration = Class.new(ActiveRecord::Migration[6.0]) {
def version; 100 end
Expand Down