(s *pb.SchemaUpdate)
| 378 | return false |
| 379 | } |
| 380 | func checkSchema(s *pb.SchemaUpdate) error { |
| 381 | if s == nil { |
| 382 | return errors.Errorf("Nil schema") |
| 383 | } |
| 384 | |
| 385 | if x.ParseAttr(s.Predicate) == "" { |
| 386 | return errors.Errorf("No predicate specified in schema mutation") |
| 387 | } |
| 388 | |
| 389 | if x.IsInternalPredicate(s.Predicate) { |
| 390 | return errors.Errorf("Cannot create user-defined predicate with internal name %s", |
| 391 | x.ParseAttr(s.Predicate)) |
| 392 | } |
| 393 | |
| 394 | if s.Directive == pb.SchemaUpdate_INDEX && !schema.HasTokenizerOrVectorIndexSpec(s) { |
| 395 | return errors.Errorf("Tokenizer must be specified while indexing a predicate: %+v", s) |
| 396 | } |
| 397 | |
| 398 | if schema.HasTokenizerOrVectorIndexSpec(s) && s.Directive != pb.SchemaUpdate_INDEX { |
| 399 | return errors.Errorf("Directive must be SchemaUpdate_INDEX when a tokenizer is specified") |
| 400 | } |
| 401 | |
| 402 | typ := types.TypeID(s.ValueType) |
| 403 | if typ == types.UidID && s.Directive == pb.SchemaUpdate_INDEX { |
| 404 | // index on uid type |
| 405 | return errors.Errorf("Index not allowed on predicate of type uid on predicate %s", |
| 406 | x.ParseAttr(s.Predicate)) |
| 407 | } else if typ != types.UidID && s.Directive == pb.SchemaUpdate_REVERSE { |
| 408 | // reverse on non-uid type |
| 409 | return errors.Errorf("Cannot reverse for non-uid type on predicate %s", |
| 410 | x.ParseAttr(s.Predicate)) |
| 411 | } |
| 412 | |
| 413 | // If schema update has upsert directive, it should have index directive. |
| 414 | if s.Upsert && len(s.Tokenizer) == 0 && !s.Unique { |
| 415 | return errors.Errorf("Index tokenizer is mandatory for: [%s] when specifying @upsert directive", |
| 416 | x.ParseAttr(s.Predicate)) |
| 417 | } |
| 418 | |
| 419 | if s.Unique { |
| 420 | ctx := context.WithValue(context.Background(), schema.IsWrite, false) |
| 421 | prevSchema, _ := schema.State().Get(ctx, s.Predicate) |
| 422 | if err := validateSchemaForUnique(prevSchema, s); err != nil { |
| 423 | return err |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | t, err := schema.State().TypeOf(s.Predicate) |
| 428 | if err != nil { |
| 429 | // No schema previously defined, so no need to do checks about schema conversions. |
| 430 | return nil |
| 431 | } |
| 432 | |
| 433 | // schema was defined already |
| 434 | switch { |
| 435 | case t.IsScalar() && (t.Enum() == pb.Posting_PASSWORD || s.ValueType == pb.Posting_PASSWORD): |
| 436 | // can't change password -> x, x -> password |
| 437 | if t.Enum() != s.ValueType { |
searching dependent graphs…