CheckAndModifyPreDefPredicate returns true if the initial update for the pre-defined predicate is different from the passed update. It may also modify certain predicates under specific conditions. If the passed update is not a pre-defined predicate, it returns false.
(update *pb.SchemaUpdate)
| 873 | // under specific conditions. |
| 874 | // If the passed update is not a pre-defined predicate, it returns false. |
| 875 | func CheckAndModifyPreDefPredicate(update *pb.SchemaUpdate) bool { |
| 876 | // Return false for non-pre-defined predicates. |
| 877 | if !x.IsPreDefinedPredicate(update.Predicate) { |
| 878 | return false |
| 879 | } |
| 880 | ns := x.ParseNamespace(update.Predicate) |
| 881 | initialSchema := CompleteInitialSchema(ns) |
| 882 | for _, original := range initialSchema { |
| 883 | if original.Predicate != update.Predicate { |
| 884 | continue |
| 885 | } |
| 886 | |
| 887 | // For the dgraph.xid predicate, only the Unique field is allowed to be changed. |
| 888 | // Previously, the Unique attribute was not applied to the dgraph.xid predicate. |
| 889 | // For users upgrading from a lower version, we will set Unique to true. |
| 890 | if update.Predicate == x.NamespaceAttr(ns, "dgraph.xid") && !update.Unique { |
| 891 | if isDgraphXidChangeValid(original, update) { |
| 892 | update.Unique = true |
| 893 | return false |
| 894 | } |
| 895 | } |
| 896 | return !proto.Equal(original, update) |
| 897 | } |
| 898 | return true |
| 899 | } |
| 900 | |
| 901 | // isDgraphXidChangeValid returns true if the change in the dgraph.xid predicate is valid. |
| 902 | func isDgraphXidChangeValid(original, update *pb.SchemaUpdate) bool { |
no test coverage detected