Skip to content

Commit

Permalink
Merge pull request #72 from openziti/add-fx-index-cascade-del
Browse files Browse the repository at this point in the history
Add AddFkIndexCascadeDelete. Fixes #71
  • Loading branch information
plorenz authored Jun 10, 2024
2 parents 4249f3e + ef5807b commit 0c06cd3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions boltz/indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ func (indexer *Indexer) AddFkIndex(symbol EntitySymbol, fkSymbol EntitySetSymbol
indexer.addFkIndex(symbol, fkSymbol, false)
}

func (indexer *Indexer) AddFkIndexCascadeDelete(symbol EntitySymbol, fkSymbol EntitySetSymbol) {
index := &fkIndex{
symbol: symbol,
nullable: false,
fkSymbol: fkSymbol,
}

indexer.AddConstraint(index)
fkStore := fkSymbol.GetStore()
if baseStore, ok := fkStore.(Constrained); ok {
baseStore.AddConstraint(&fkDeleteCascadeConstraint{
symbol: symbol,
cascadeType: CascadeDelete,
})
} else {
panic(errors.Errorf("linked store %v is not constrained, can't enforce validity of constraint on delete",
fkSymbol.GetStore().GetEntityType()))
}
}

func (indexer *Indexer) AddNullableFkIndex(symbol EntitySymbol, fkSymbol EntitySetSymbol) {
indexer.addFkIndex(symbol, fkSymbol, true)
}
Expand Down

0 comments on commit 0c06cd3

Please sign in to comment.