-
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
adding a null constraint is unsafe #28
Conversation
Hey @abcm1989, thanks for the PR 👍 Can you explain more about what happened and why this should fix it? |
e20ff52
to
ebdbd00
Compare
@ankane Ah, I got my logic flipped in the code, which I've fixed. Adding the constraint should be unsafe, rather than removing it. We had a migration that added a null constraint using change_column_null that wouldn't run in some environments because there were rows with null values. I had it raising the error only if no default value is passed based on this from the docs
|
Hey @abcm1989, I don't think adding a default value to replace |
ba07c2a
to
b4bfa89
Compare
@ankane alrighty, updated so that adding a null constraint always is unsafe |
Hey @abcm1989, I'm not sure it's unsafe if all values are filled in. |
@ankane sorry can you rephrase, I'm not sure what you mean |
@abcm1989 Your initial report is about an error if you try to add a not null constraint and have rows with null values. If you don't have rows with null values, I believe this operation is safe. |
@ankane that's right, do you think it should not raise a warning at all then? |
Yeah, that's my current thinking. |
@ankane okay...just to make sure I understand, your position is that because the migration is safe sometimes, we shouldn't wrap it in a safety assured block? It's a bit inconsistent that change_column_null would not require a safety assured block LMK your thoughts |
Hey @abcm1989, all |
@ankane okay, I see your point. I'll update this so it's only dangerous when setting a default value. It likely makes sense to catch change_column_default migrations too in that case |
@abcm1989 I haven't run into this, so would need a proof of concept. Also, changing the default by itself should be fine. |
gotcha, okay, well thanks for reviewing |
Fix for #29 https://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column_null