Skip to content

Commit

Permalink
Fix: respect the mysql auto_increment setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rnkaufman committed Feb 23, 2022
1 parent 497ab71 commit 4f2b86e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -722,7 +722,9 @@ def change_column_for_alter(table_name, column_name, type, **options)
options[:comment] = column.comment
end

options[:auto_increment] = column.auto_increment?
unless options.key?(:auto_increment)
options[:auto_increment] = column.auto_increment?
end

td = create_table_definition(table_name)
cd = td.new_column_definition(column.name, type, **options)
Expand Down
15 changes: 15 additions & 0 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -1347,6 +1347,21 @@ def test_changing_columns
assert_equal "This is a comment", column(:birthdate).comment
end

if current_adapter?(:Mysql2Adapter)
def test_updating_auto_increment
with_bulk_change_table do |t|
t.change :id, :bigint, auto_increment: true
end

assert column(:id).auto_increment?

with_bulk_change_table do |t|
t.change :id, :bigint, auto_increment: false
end
assert_not column(:id).auto_increment?
end
end

def test_changing_index
with_bulk_change_table do |t|
t.string :username
Expand Down

0 comments on commit 4f2b86e

Please sign in to comment.