From 481145b89c247b8b5d0d7f79dbd0264c94c42d0d Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Fri, 14 Jun 2024 10:30:02 -0400 Subject: [PATCH] Fix nillable unique contraint check. Fixes #73 --- boltz/indexes.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/boltz/indexes.go b/boltz/indexes.go index 5250b5b..1cc95ab 100644 --- a/boltz/indexes.go +++ b/boltz/indexes.go @@ -391,7 +391,14 @@ func (index *uniqueIndex) CheckIntegrity(ctx MutateContext, fix bool, errorSink for entityCursor := index.symbol.GetStore().IterateValidIds(tx, ast.BoolNodeTrue); entityCursor.IsValid(); entityCursor.Next() { id := entityCursor.Current() - _, fieldVal := index.symbol.Eval(tx, id) + fieldType, fieldVal := index.symbol.Eval(tx, id) + if fieldType == TypeNil { + if !index.nullable { + errorSink(errors.Errorf("entity with id %s has non-nillable unique index %v.%v, but field has nil value, unable to fix", + string(id), store.GetEntityType(), index.symbol.GetName()), false) + } + continue + } idxId := index.Read(tx, fieldVal) if idxId == nil {