-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add PK constraint on bigserial ID columns on postgres adapter #10455
Add PK constraint on bigserial ID columns on postgres adapter #10455
Conversation
In rails#10410 it was noted that you can no longer create PK's with the type of bigserial in PostgreSQL in 4.0.0.rc1. This is mostly because the newer adapter is checking for column type with the id column instead of just letting it pass through like it did before. Side effects: You may just create a PK column of a type that you really don't want to be your PK. As far as I can tell this was allowed in 3.2.X and perhaps an exception should be raised if you try and do something extremely dumb.
@tenderlove this might be ready for your review now. |
…ntifying_pk Add PK constraint on bigserial ID columns on postgres adapter
…ntifying_pk Add PK constraint on bigserial ID columns on postgres adapter
@@ -359,8 +359,12 @@ class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition | |||
# a record (as primary keys cannot be +nil+). This might be done via the | |||
# +SecureRandom.uuid+ method and a +before_save+ callback, for instance. | |||
def primary_key(name, type = :primary_key, options = {}) | |||
return super unless type == :uuid | |||
options[:default] = options.fetch(:default, 'uuid_generate_v4()') | |||
return super unless type = :primary_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems wrong. Can you run the pg tests and resend a pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That line is indeed very wrong. Will correct it in a sec.
Sorry, I should have reviewed more closely, but this PR seems wrong. I'm reverting the merge commit. Can you check the pg tests and resubmit? Specifically we're getting a failure on: |
In #10410 it was noted that you can no longer create PK's with the
type of bigserial in PostgreSQL in 4.0.0.rc1. This is mostly
because the newer adapter is checking for column type with the
id column instead of just letting it pass through like it did
before.
Side effects:
You may just create a PK column of a type that you really don't
want to be your PK. As far as I can tell this was allowed in 3.2.X
and perhaps an exception should be raised if you try and do
something extremely dumb.