Create edges upon custom id

Hi,

I wanted to know if it is possible to create edges on self-generated ids instead of the UIDs created by the DB. It is important to me because sometimes I want to replace a node with a newer node have that node all the connections that the one which was replaced had. If I will rely on the uids that dgraph creates I will have two different ids and I will need to update every single connection manually.
If I can create a connection upon a self-generated id I will be able to give both nodes the same id

Thanks,
Spinelsun

This depends on your business logic. I think an Upsert Block is your friend there.

Nope upsert won’t work in my use case.
I don’t update an existing node I delete it and insert a complete new node instead of it and new sub-nodes under it.
and I need to connect these sub-nodes to nodes that were connected to their equivalent nodes in the node that was replaced.

A real life example: I have a branch (like in git) that has many versions. from each version of this branch other branches can be checked out (like checkout from a specific commit in git).
when pushing the local branch I don’t want to update it in the DB I want to replace the currently stored branch with the one that was pushed from the local repository.
Since I totally replace the node I need to recreate connections to the new node

I would like to be able to connect nodes upon a field that I manage and not the db like the uid.
is it possible?

Another possible solution is that dgraph will store a map of all of the references for a specific uid and when a node is replaced by another node all nodes that refer to it will be updated automatically.

Yeah, it is possible. Make a “clone”. But a bit complex. Share an example(in DQL) that I fix it for you.

Too much complex to be implemented in the DB itself.

I currently do it in python since it is a multistep operation that involves several mutations and queries:

  1. build the new branch rdf
  2. query for all of the connection of each version - all branches that were checked out from it.
    then I create the mup between a version number and its edges
  3. run 2 mutations in one transaction - one that inserts the new branch and another that removes the edge of the old branch from the repository
  4. request the new uids of the new versions that were created
  5. recreate the connection by uid predicate uid triples
  6. update all the nodes
  7. delete recursively the old branch

In each step, there is a lot of python code.
It will be impossible for me to create it only with dql.
we might think in the future about how to design our data model so we won’t need to replace nodes that are referred by other nodes and subnodes.
Till then if you have an idea for another algorithm that might work I would be thankful for your help