-
Notifications
You must be signed in to change notification settings - Fork 24
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 safe_make_column_not_nullable #114
base: master
Are you sure you want to change the base?
Add safe_make_column_not_nullable #114
Conversation
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.
I'm wondering if we want to also (whether it's in this PR or not) add a method that converts a validated check constraint to a regular NOT NULL
constraint (the benefit basically being that it would assert that the constraint exists and is already validated).
quoted_table_name = connection.quote_table_name(table) | ||
quoted_column_name = connection.quote_column_name(column) | ||
|
||
tmp_constraint_name = :tmp_not_null_constraint |
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.
Are constraint names global? If so, do we want to add a random tag on the end of this?
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.
Yeah, I think constraint names need to be unique within a schema. Because this method is doing multiple things non-transactionally, there is a possibility we could error out before the constraint is removed. So a) I agree with @jcoleman that we should add some random characters to this string and b) we should document that this might leave behind a constraint on failure, similar to creating a partitioned index.
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.
The documentation says that constraints are only unique per-table:
I don't have a strong opinion on the naming of the constraint or if it should still have randomness regardless
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.
I think adding a random tag would make re-running a failed migration here safer, albeit at the cost of you not discovering what's been left behind by the previous run.
I think I'd probably say this: let's add a tag using a the first N chars of a sha of the column name (so it's stable), and at the beginning of the method raise a specific error if that constraint already exists.
Co-authored-by: James Coleman <[email protected]>
Co-authored-by: James Coleman <[email protected]>
@alexspeller Apologies, for some reason I'm not getting notifications on this repo anymore; I'll take a look at this again. |
@alexspeller I think @rkrage are going to add wrapping this PR up to our internal development list, and after we wrap it up, we'll merge. |
Addresses #106
I also added some quoting for some related methods where it seemed to be missing