(prevSchema pb.SchemaUpdate, currentSchema *pb.SchemaUpdate)
| 458 | } |
| 459 | |
| 460 | func validateSchemaForUnique(prevSchema pb.SchemaUpdate, currentSchema *pb.SchemaUpdate) error { |
| 461 | validTokenizer := func(tokenizers []string) bool { |
| 462 | for _, value := range tokenizers { |
| 463 | if value == "hash" || value == "exact" || value == "int" { |
| 464 | return true |
| 465 | } |
| 466 | } |
| 467 | return false |
| 468 | } |
| 469 | if prevSchema.Predicate != "" { |
| 470 | if prevSchema.Upsert && !currentSchema.Upsert { |
| 471 | return errors.Errorf("could not drop @upsert from [%v] predicate when @unique directive specified", |
| 472 | x.ParseAttr(currentSchema.Predicate)) |
| 473 | } |
| 474 | |
| 475 | if prevSchema.Unique && !validTokenizer(currentSchema.Tokenizer) { |
| 476 | return errors.Errorf("could not drop index %v from [%v] predicate when @unique directive specified", |
| 477 | prevSchema.Tokenizer, x.ParseAttr(currentSchema.Predicate)) |
| 478 | } |
| 479 | } |
| 480 | if !currentSchema.Upsert { |
| 481 | currentSchema.Upsert = true |
| 482 | } |
| 483 | switch currentSchema.ValueType { |
| 484 | case pb.Posting_STRING: |
| 485 | if len(currentSchema.Tokenizer) == 0 || |
| 486 | (len(currentSchema.Tokenizer) > 0 && !validTokenizer(currentSchema.Tokenizer)) { |
| 487 | |
| 488 | return errors.Errorf("index for predicate [%v] is missing, add either hash or exact index with @unique", |
| 489 | x.ParseAttr(currentSchema.Predicate)) |
| 490 | } else { |
| 491 | return nil |
| 492 | } |
| 493 | |
| 494 | case pb.Posting_INT: |
| 495 | if len(currentSchema.Tokenizer) == 0 { |
| 496 | return errors.Errorf("index for predicate [%v] is missing, add int index with @unique", |
| 497 | x.ParseAttr(currentSchema.Predicate)) |
| 498 | } else { |
| 499 | return nil |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | return errors.Errorf("@unique directive not supported on [%v] type predicate", currentSchema.ValueType.String()) |
| 504 | } |
| 505 | |
| 506 | // ValidateAndConvert checks compatibility or converts to the schema type if the storage type is |
| 507 | // specified. If no storage type is specified then it converts to the schema type. |
no test coverage detected
searching dependent graphs…