-
Notifications
You must be signed in to change notification settings - Fork 73
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
New operation: create_constraint
#411
Conversation
…eign-key-constraints
…eign-key-constraints
…eign-key-constraints
create_constraint
This seems super useful. Right now there is no other ways to add a UNIQUE constraint on a table that applies across columns right? |
Drive by comment, I didn't do a full review, but the |
@JoachimKoenigslieb You can create a unique index on a table using |
@ryanslade If you are ok with reviewing a big PR, I am happy to add it. But to ease the burden on the reviewer, it would be better to address |
Happy for it to be in another PR, just wanted to make sure you were aware of the limitation. |
Created a follow up issue to track |
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.
Left some comments.
Could this PR be split into three pieces? One each for CHECK
, UNIQUE
and FOREiGN KEY
constraints. It think that's going to make the implementation and review easier.
I've only looked at the table levelCHECK
constraints in detail so far. The implementation there adds the new constraint to the affected columns directly. In the case of single-column CHECK
constraints added via the alter_column
operation, the affected column is duplicated and backfilled and the constraint added to the new column. This gives us a 'zero downtime, multiversion' migration as the old column without the constraint is referenced by the old versioned view and the new column with the constraint is referenced from the new versioned view.
By adding the CHECK
constraint directly to the columns, we break this as now both old and new versions of the schema will be affected by the constraint.
We will need to do the same thing for these potentially multi-column CHECK
constraints as we do for the single column versions:
- on
Start
: duplicate and backfill the affected columns and apply the constraint to the new columns. - on
Complete
: validate the check constraint - on
Rollback
: remove the duplicated columns
Co-authored-by: Andrew Farries <[email protected]>
Co-authored-by: Andrew Farries <[email protected]>
Turning it into draft and opening follow-up PRs. |
…h multiple columns (#459) This PR adds a new operation named `create_constraint`. Previously, we only supported adding constraints to columns. This operation lets us define table level constraints including multiple columns. The operation supports `unique` constraints for now. In a follow-up PR I am adding `foreign_key` and `check` constraints as well. ### Unique ```json { "name": "44_add_table_unique_constraint", "operations": [ { "create_constraint": { "type": "unique", "table": "tickets", "name": "unique_zip_name", "columns": [ "sellers_name", "sellers_zip" ], "up": { "sellers_name": "sellers_name", "sellers_zip": "sellers_zip" }, "down": { "sellers_name": "sellers_name", "sellers_zip": "sellers_zip" } } } ] } ``` ### Related Created from #411 --------- Co-authored-by: Andrew Farries <[email protected]> Co-authored-by: Ryan Slade <[email protected]>
Closing as the last PR has been opened: #471 |
This PR adds a new operation named
create_constraint
. Previously, we only supported adding constraints to columns. This operation lets us define table level constraints including multiple columns.The operation supports
foreign_key
,check
andunique
constraint definition on tables.Examples
Foreign key
Check
Unique
Related
Requires #413
Requires #426
Closes #81