Fix autoincrement on primary key

MySQL adapters take an auto_increment option but when using a primary
key type that option is silently ignored and doesn't change behavior.
This fixes the issue by only applying `options[:auto_increment] = true`
if it wasn't set to false already.

I didn't make changes to the other adapters because they don't accept
`auto_increment` as an option. If we want this for postgres we'll need
to implement the option first.
This commit is contained in:
eileencodes 2023-03-30 15:53:26 -04:00
parent 15369fd912
commit 01c4605800
No known key found for this signature in database
GPG Key ID: BA5C575120BBE8DF
2 changed files with 12 additions and 1 deletions

@ -94,7 +94,10 @@ def aliased_types(name, fallback)
end
def integer_like_primary_key_type(type, options)
options[:auto_increment] = true
unless options[:auto_increment] == false
options[:auto_increment] = true
end
type
end
end

@ -31,4 +31,12 @@ def test_auto_increment_with_composite_primary_key
output = dump_table_schema("auto_increments")
assert_match(/t\.integer\s+"id",\s+null: false,\s+auto_increment: true$/, output)
end
def test_auto_increment_false_with_custom_primary_key
@connection.create_table :auto_increments, id: false, force: :cascade do |t|
t.primary_key :id, auto_increment: false
end
assert_not_predicate @connection.columns(:auto_increments).first, :auto_increment?
end
end