-
Notifications
You must be signed in to change notification settings - Fork 67
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
Implement the drop_constraint
operation
#103
Conversation
Add examples of dropping `CHECK` and `FOREIGN KEY` constraints.
if o.Up == "" { | ||
return FieldRequiredError{Name: "up"} | ||
} | ||
|
||
if o.Down == "" { | ||
return FieldRequiredError{Name: "down"} | ||
} |
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.
dropping a constraint is in many cases an easy operation, you land on a less restrictive schema but the old one keeps working. I wonder if these should be optional?
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.
In the case of removing a constraint the down
SQL is the important one as that's the one that goes from a less restrictive schema to a more restrictive one. In the absence of data quarantine, it's necessary to ensure that values inserted into the new schema can successfully be written to the old one.
Theup
sql could probably be made optional as it's almost always going to be a straight copy of the value from the more restrictive schema to the less restrictive one.
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.
PR here to make the up
SQL optional: #106
I believe we will need this anyway, for instance to validate that the migration makes sense (the constraint exists?). Also, if you think about exposing postgres schema to Xata users, probably our internal representation is a great candidate for this. |
Agreed, it would be useful for migration validation if nothing else.
You mean as an alternative to giving access to system catalogs? |
I've created #105 for adding constraints to the internal schema representation. |
No, I was thinking about exposing some form of processed schema in our API, for some clients to consume, let's discuss this at some point |
In response to this comment #103 (comment). Theup sql is made optional as it's almost always going to be a straight copy of the value from the more restrictive schema to the less restrictive one.
Implement the
drop_constraint
operation for dropping constraints defined on single columns.An example of the operation looks like:
for dropping a
CHECK
constraint. And like this for dropping aFOREIGN KEY
constraint:The operation works very similarly to the inverse operation of adding
CHECK
andFOREIGN KEY
constraints to a single column.Start
:up
anddown
SQL. Thedown
SQL needs to ensure that rows inserted into the new view that don't meet the constraint are converted into rows that do meet the constraint.Complete
Rollback
Improvements
drop_constraint
operation requires that the column on which the constraint is defined is named in the migrationjson
file. Ifpg-roll
's internal schema representation knew about the constraints defined on a table it would be possible to delete constraints by constraint name only; the schema representation would know on which column the constraint was defined.pg-roll
currently only allows for creatingCHECK
andFOREIGN KEY
constraints on single columns; this limitation also applies to thedrop_constraint
operation.