Skip to content

Commit f078a91

Browse files
authored
Add support for NOT VALID in constraint writer (#649)
This PR adds support for creating not validated constraints in `ALTER TABLE` statements. I am adding unit tests in a follow-up PR, when `ConstraintSQLWriter` is moved into a separate file. Either way, it is not used anywhere yet to avoid conflicts with other FK related changes in future PRs. Extracted from #628
1 parent 9ebb691 commit f078a91

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/migrations/op_create_table.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ type ConstraintSQLWriter struct {
336336
Columns []string
337337
InitiallyDeferred bool
338338
Deferrable bool
339+
SkipValidation bool
339340

340341
// unique, exclude, primary key constraints support the following options
341342
IncludeColumns []string
@@ -367,6 +368,7 @@ func (w *ConstraintSQLWriter) WriteCheck(check string, noInherit bool) string {
367368
if noInherit {
368369
constraint += " NO INHERIT"
369370
}
371+
constraint += w.addNotValid()
370372
return constraint
371373
}
372374

@@ -406,6 +408,7 @@ func (w *ConstraintSQLWriter) WriteForeignKey(referencedTable string, referenced
406408
onUpdateAction,
407409
)
408410
constraint += w.addDeferrable()
411+
constraint += w.addNotValid()
409412
return constraint
410413
}
411414

@@ -454,3 +457,10 @@ func (w *ConstraintSQLWriter) addDeferrable() string {
454457
}
455458
return deferrable
456459
}
460+
461+
func (w *ConstraintSQLWriter) addNotValid() string {
462+
if w.SkipValidation {
463+
return " NOT VALID"
464+
}
465+
return ""
466+
}

0 commit comments

Comments
 (0)