Skip to content

Commit

Permalink
Merge pull request #44480 from fatkodima/change_column_comment-auto_i…
Browse files Browse the repository at this point in the history
…ncrement

Fix `change_column_comment` to preserve column's AUTO_INCREMENT in the MySQL adapter
  • Loading branch information
byroot committed Feb 18, 2022
2 parents 62d81af + 51852d2 commit 74fedee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit 74fedee

Please sign in to comment.