This document describes all the things that you need to take care while doing a schema update or migration.
@id to an existing fieldAppUser
would be more sensible than the name User because User seems a bit generic
to you. Then you are in a situation where you need migration.
This can be handled in a couple of ways:
User to use the new name AppUser. OR,@dgraph(type: ...) directive to
maintain backward compatibility with the existing data.User type till now,
then you might want to go with option #1. But, if you have an active app with a
very large dataset then updating the node of each user may not be a thing you
might want to commit to, as that can require some maintenance downtime. So,
option #2 could be a better choice in such conditions.
Option #2 makes your new schema compatible with your existing data. Here’s an
example:
getUser would now be renamed to
getAppUser. So, your downstream clients need to update that bit in the code.
phone as tel. You need
migration.
You have the same two choices as before:
phone to use the new name tel. OR,@dgraph(pred: ...) directive to
maintain backward compatibility with the existing data.String -> Int@id to an existing fieldusername must be unique for every user. So, you change
the schema to this:
Alice. If that was true, then
the queries would break in such cases. Like, if you run this query after the
schema change:
TestDataMigration with someOtherInfo value.
Then you update the Schema and remove the field.
TestDataMigration object using its id, the
GraphQL API delete operation is successful.
If you followed the GraphQL - DQL Schema mapping, you
understand that Dgraph has used the list the known list of predicates (id,
someInfo) and removed them. In fact, Dgraph also removed the
dgraph.typepredicate and so thisTestDataMigration node isn’t visible anymore
to the GraphQL API.
The point is that a node with this uid exists and has a predicate
someOtherInfo. This is because this data has been created initially and
nothing in the process of deploying a new version and then using a delete
operation by ID instructed Dgraph to delete this predicate.
You end up with a node without type (i.e without a dgraph.type predicate) and
with an old predicate value which is ‘invisible’ to your GraphQL API!
When doing a GraphQL schema deployment, you must take care of the data cleaning
and data migration. The good news is that DQL offers you the tools to identify
(search) potential issues and to correct the data (mutations).
In the previous case, you can alter the database and completely delete the
predicate or you can write an ‘upsert’ DQL query that searches the nodes of
interest and delete the unused predicate for those nodes.