github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/schemautil/schemautil.go (about)

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