-
Notifications
You must be signed in to change notification settings - Fork 170
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
[Idea] Warn on the addition of a validated foreign key #59
Comments
Hey @iamvery, thanks for the suggestion. I think this is best as a custom check. I imagine most of the time foreign keys need to be valid. |
Thanks for the response @ankane! I'm a little indifferent on this, but I understand your point. I'm indifferent, because I feel like if the purpose of this library is to protect users from themselves it might go so far to recommend against typical cases like this in the name of safety.
Either way, the custom checks are a great feature that we can take advantage of. Thank you! |
Reading about the issue more, agree that it'd be good for the gem to handle it, so happy to accept a PR. Since the References: |
Thanks for the follow up here! It's going to be a few days before I can dig in, but this sounds great 👍 |
Going to close this out, but feel free to create a PR |
I recently ran into a problem adding a new foreign key constraint at scale. It seems that by default, when adding a foreign key, the entire table is validated for the new constraint which performs some table locking.
From the PostgreSQL docs
In my particular case, I was adding the foreign key to a new column which would be NULL for all existing records anyway thus not needing the validation at all. Here's the full example that caused me problems:
And here is the preferred way:
Note:
validate: false
which results inNOT VALID
option being added to the producedALTER TABLE
statement.What do you think?
The text was updated successfully, but these errors were encountered: