Is it reliable to periodically update schema on production?

Hi folks. In my opinion it is important to clarify the following question for Dgraph’s future.

Here is the question:

Is it reliable to add, delete new predicates, new indexes and even changing types of existing predicates on a live production system?

What I want to do

I want to give my users the option to define/modify their schema per their business needs.
The idea is powerful at first glance, however it might be quite dangerous if reliability is not provided.

Can you please share your thoughts?
Thank you.

Yes, and it depends. In the dgraph, each predicate is a small part of a whole (node). If you modify a predicate, it will not affect the nodes in any way. If you modify the indexing of a predicate, a reindexing task will trigger. In general, changes to the schema do not affect the data, so it is safe to modify the Schema.

There are Type Value changes that cannot be made, in which case you would have to do an Upsert Mutation to migrate the data to another Value Edge.

It depends cuz, why you wanna change the schema all the time? this will consume resources unnecessarily. But if you wanna do it, I see no problem.

Maybe I didn’t catch what is your concern.

Is it possible to alter only a single predicate’s type with a request? Or is it possible to add new field without sending entire type information to the server?

As far as I understand, to make a single type change I have to send the entire Schema of the Type.

With every schema update, I see all indexes are being dropped and rebuilt.
I would expect single update of a field instead.

If I am not wrong, console logs tell me DGraph rebuilds entire type for a single update.

Yes, but some predicate you won’t change. Cuz some change can’t be done. e.g. scalar to uid. For example, isn’t a good thing to change int to DateTime, cuz DateTime follows the RFC3339 format. Changing to String is fine tho.

In short, you can send a single request with that single predicate change. You don’t need to send the whole schema again and again.

Are you talking about the field type (value type/predicate type) or the Schema Type?
All objects should have their own Schema type. The type definition per see. And all predicates used in that Type Definition has to exist too.

So, if you modify your Type Def, and it has a new field with no pre-existing predicate. You must add it before the Type Def modification/creation.

Nope. Every single part of the schema can be changed separately.

That’s odd. I have created a long time ago a ticket to stop any unnecessary indexing modification if you send the whole schema twice. That’s strange cuz it has more than 2 years. I gonna take a look at it.

No, go with me. You don’t need to send the entire schema every new change you need to do.

Rate UI is misleading developer in that regard. The schema alteration on the official UI is as a whole.

Suggestions:

  1. Add a note to Ratel UI to teach developer not to send entire schema. (or add UI option for individual changes)
  2. Improve Dgraph’s capabilities to take care of non-changed schema update requests.

Scenario:
I have a schema Type:
Animal { Name, Kind, Age}
Now I want to add Color predicate.
Shall I send entire Type information or only Color predicate?

Per my understanding, here, it requires entire Type predicates as a whole in the request.
If this is the only choice, Dgraph should take care of non-changed predicates and not rebuild entire indexes on Schema Type.

I might be wrong in the previous comment. Because in my dev environment,
I am always sending predicate index types along with Type information.
So, perhaps you are right. Sending types does not trigger index rebuilding alone.
However if I send exact same index along with Type it triggers index rebuilders.
This was annoying for me until figure this out.
Now I have to change my code and also willing to Dgraph handle this :slight_smile:
Thank you for pointers.

Do you mean the bulk edit? yeah, it pull and shows up the entire schema. You can simply select all and delete. And start from scratch.

I see.

It has, just needs to check why isn’t working.

In the case of the Type definition, I have re-checked. You have to send the entire Type Definition with the new predicate references. Only by adding predicates, you can send a single-line request. But you don’t need to send the entire Schema. Just the entire Type definition.

Instead of using Bulk Edit, just use the Type session of Ratel. It will handle the types for you.

In that case, we don’t call it “Type predicates”. It is a Type Definition. As this is the Type of an entity. Inside of it, there is only a “mention/references” of predicates. They aren’t predicates. The predicates are treated outside the Type Definitions.

If you change the Type Definition, it will not change the indexation of your predicates.

Hey koculu, Can you share type definition update attr API reference .

Thanks.

Hey @Rishan ,
I think there is no such reference yet. I am using Ratel UI to get the relevant endpoints and post content structure.
Beside, this might help: https://dgraph.io/docs/get-started/

Thank you for reply @koculu. But my scenario is different
For ex : i have type User and initially i added name, age and later if i want to add email attr to that type User how i can add ? Should i update whole type or what ?

I am using npm dgraph js.

Sample Code :
let schema = type User { name age } name: string @index(term) . age: int .
const op = new dgraph.Operation();
op.setSchema(schema);
await config.dgraphDb.alter(op);

After this i want to add email attr to that type User.

@Rishan
I am not pro with DGraph.
Per my understanding, you have to send entire Type information in single request.
If you omit some predicates or edges in the Type definition those types are being deleted.

On the other hand, deleting a Type fully is not implemented yet. You can delete all predicates and edges of a Type by sending an empty Type body but you cannot delete the Type entirely as of today.

Another hint:
It is better to send predicate and edge definitions in a separated query.
Because they are separated internally.
You can delete some predicate from a Type but predicate survives.
Deleting a predicate/edge and deleting a Type are 2 separate things.