Skip to content

Commit 74fedee

Browse files
authored
Merge pull request rails#44480 from fatkodima/change_column_comment-auto_increment
Fix `change_column_comment` to preserve column's AUTO_INCREMENT in the MySQL adapter
2 parents 62d81af + 51852d2 commit 74fedee

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
*Nick Holden*
1111

12+
* Fix `change_column_comment` to preserve column's AUTO_INCREMENT in the MySQL adapter
13+
14+
*fatkodima*
15+
1216
* Fix quoting of `ActiveSupport::Duration` and `Rational` numbers in the MySQL adapter.
1317

1418
*Kevin McPhillips*

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@ def change_column_for_alter(table_name, column_name, type, **options)
722722
options[:comment] = column.comment
723723
end
724724

725+
options[:auto_increment] = column.auto_increment?
726+
725727
td = create_table_definition(table_name)
726728
cd = td.new_column_definition(column.name, type, **options)
727729
schema_creation.accept(ChangeColumnDefinition.new(cd, column.name))

activerecord/test/cases/comment_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ def test_change_table_comment_to_nil
178178
end
179179

180180
def test_change_column_comment
181-
@connection.change_column_comment :commenteds, :name, "Edited column comment"
182-
column = Commented.columns_hash["name"]
181+
@connection.change_column_comment :commenteds, :id, "Edited column comment"
182+
column = Commented.columns_hash["id"]
183183
assert_equal "Edited column comment", column.comment
184+
185+
if current_adapter?(:Mysql2Adapter)
186+
assert column.auto_increment?
187+
end
184188
end
185189

186190
def test_change_column_comment_to_nil

0 commit comments

Comments
 (0)