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

Fix change_column_comment to preserve column's AUTO_INCREMENT in the MySQL adapter #44480

Merged
merged 1 commit into from
Feb 18, 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
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

*Nick Holden*

* Fix `change_column_comment` to preserve column's AUTO_INCREMENT in the MySQL adapter

*fatkodima*

* Fix quoting of `ActiveSupport::Duration` and `Rational` numbers in the MySQL adapter.

*Kevin McPhillips*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ def change_column_for_alter(table_name, column_name, type, **options)
options[:comment] = column.comment
end

options[:auto_increment] = column.auto_increment?

td = create_table_definition(table_name)
cd = td.new_column_definition(column.name, type, **options)
schema_creation.accept(ChangeColumnDefinition.new(cd, column.name))
Expand Down
8 changes: 6 additions & 2 deletions activerecord/test/cases/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,13 @@ def test_change_table_comment_to_nil
end

def test_change_column_comment
@connection.change_column_comment :commenteds, :name, "Edited column comment"
column = Commented.columns_hash["name"]
@connection.change_column_comment :commenteds, :id, "Edited column comment"
column = Commented.columns_hash["id"]
assert_equal "Edited column comment", column.comment

if current_adapter?(:Mysql2Adapter)
assert column.auto_increment?
end
end

def test_change_column_comment_to_nil
Expand Down