-
Notifications
You must be signed in to change notification settings - Fork 26
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
Online check constraint addition #76
Online check constraint addition #76
Conversation
@@ -1461,20 +1476,20 @@ func (csg *checkConstraintSQLGenerator) Add(con schema.CheckConstraint) ([]State | |||
|
|||
if !con.IsValid { | |||
sb.WriteString(" NOT VALID") | |||
} else if !csg.isNewTable { |
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.
We strip the migration hazards for new tables within the TableSQLGenerator, so we don't actually need this conditional
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.
Looks great! Really cool improvement -- two thoughts
README.md
Outdated
@@ -43,10 +43,13 @@ $ pg-schema-diff plan --dsn "postgres://postgres:postgres@localhost:5432/postgre | |||
* The use of postgres native operations for zero-downtime migrations wherever possible: | |||
* Concurrent index builds | |||
* Online index replacement: If some index is changed, the new version will be built before the old version is dropped, preventing a window where no index is backing queries | |||
* Online check constraint addition: Check constraints are added as `INVALID` before being validated, eliminating the need |
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.
Maybe use builds here? Addition is a bit of an awkward term in my head
* Online check constraint addition: Check constraints are added as `INVALID` before being validated, eliminating the need | |
* Online check constraint builds: Check constraints are added as `INVALID` before being validated, eliminating the need |
@@ -838,6 +838,48 @@ var ( | |||
expectedStatements: nil, | |||
expectedDiffErrIs: errDuplicateIdentifier, | |||
}, | |||
{ | |||
name: "Online check constraint addition", |
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.
thought: Do we already have a case for the validation of a previously invalid 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.
This is a different test case:
- one is testing altering a check constraint from invalid to valid
- one is testing that add a constraint is online
// UDF's in check constraints are a bad idea. Check constraints are not re-validated | ||
// if the UDF changes, so it's not really a safe practice. We won't support it for now | ||
if len(con.DependsOnFunctions) > 0 { | ||
return nil, fmt.Errorf("check constraints that depend on UDFs: %w", ErrNotImplemented) | ||
} | ||
|
||
var stmts []Statement | ||
if !con.IsValid || csg.isNewTable { |
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.
If !con.IsValid
shouldn't we have a validateConstraintStatement?
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.
Nope! Because the user is adding an invalid constraint! (They want it to be invalid)
r? |
Description
This was a pretty low-hanging fruit. We now add all check constraints as invalid and then validate them. This allows us to build check constraints "online".
Motivation
Closes #66
Testing
Tested with unit tests