-
Notifications
You must be signed in to change notification settings - Fork 245
/
schemautil.go
34 lines (29 loc) · 1.3 KB
/
schemautil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package schemautil
import (
"context"
"github.com/authzed/spicedb/pkg/datastore"
"github.com/authzed/spicedb/internal/services/shared"
core "github.com/authzed/spicedb/pkg/proto/core/v1"
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
)
// ValidateSchemaChanges validates the schema found in the compiled schema and returns a
// ValidatedSchemaChanges, if fully validated.
func ValidateSchemaChanges(ctx context.Context, compiled *compiler.CompiledSchema, isAdditiveOnly bool) (*shared.ValidatedSchemaChanges, error) {
return shared.ValidateSchemaChanges(ctx, compiled, isAdditiveOnly)
}
// ApplySchemaChanges applies schema changes found in the validated changes struct, via the specified
// ReadWriteTransaction. Returns the applied changes, the validation error (if any),
// and the error itself (if any).
func ApplySchemaChanges(
ctx context.Context,
rwt datastore.ReadWriteTransaction,
validated *shared.ValidatedSchemaChanges,
existingCaveats []*core.CaveatDefinition,
existingObjectDefs []*core.NamespaceDefinition,
) (*shared.AppliedSchemaChanges, *shared.ErrSchemaWriteDataValidation, error) {
result, err := shared.ApplySchemaChangesOverExisting(ctx, rwt, validated, existingCaveats, existingObjectDefs)
if err != nil {
return result, shared.AsValidationError(err), err
}
return result, nil, nil
}