MCPcopy
hub / github.com/dgraph-io/dgraph / createSchema

Function createSchema

worker/mutation.go:301–329  ·  view source on GitHub ↗
(attr string, typ types.TypeID, hint pb.Metadata_HintType, ts uint64)

Source from the content-addressed store, hash-verified

299}
300
301func createSchema(attr string, typ types.TypeID, hint pb.Metadata_HintType, ts uint64) error {
302 ctx := schema.GetWriteContext(context.Background())
303
304 // Don't overwrite schema blindly, acl's might have been set even though
305 // type is not present
306 s, ok := schema.State().Get(ctx, attr)
307 if ok {
308 s.ValueType = typ.Enum()
309 } else {
310 s = pb.SchemaUpdate{ValueType: typ.Enum(), Predicate: attr}
311 // For type UidID, set List to true. This is done because previously
312 // all predicates of type UidID were implicitly considered lists.
313 if typ == types.UidID {
314 s.List = true
315 }
316
317 switch hint {
318 case pb.Metadata_SINGLE:
319 s.List = false
320 case pb.Metadata_LIST:
321 s.List = true
322 default:
323 }
324 }
325 if err := checkSchema(&s); err != nil {
326 return err
327 }
328 return updateSchema(&s, ts)
329}
330
331func runTypeMutation(ctx context.Context, update *pb.TypeUpdate, ts uint64) error {
332 current := proto.Clone(update).(*pb.TypeUpdate)

Callers 1

applyMutationsMethod · 0.85

Calls 6

GetWriteContextFunction · 0.92
StateFunction · 0.92
checkSchemaFunction · 0.70
updateSchemaFunction · 0.70
GetMethod · 0.65
EnumMethod · 0.45

Tested by

no test coverage detected