Thanks for your response. Sorry it’s taken me so long to get back to you.
Migrate [uid] => uid can’t be done right. As you are migrating from a one to many to a one to one relation. The other edges will be lost anyway in that case.
True, but in my case I only have one to migrate, so that won’t be a problem. The problem is that I inadvertently defined a one-to-many relationship…
Token.person: [uid] @reverse .
…when I should have defined a one-to-one:
Token.person: uid @reverse .
I tried to fix this today by adding a new predicate that defines a single uid instead of a list…
Token.singlePerson: uid @reverse .
…then running an upsert block to copy each Token.person
into its Token.singlePerson
…
upsert {
query {
token as token(func: type(Token)) {
person as Token.person {
uid
}
uid
}
}
mutation {
set {
uid(token) <Token.singlePerson> uid(person) .
}
}
}
…but now all Token.singlePerson
edges reference the same Token.person
(instead of each referencing its own).
Here’s my data before and after:
Before:
"tokens": [
{
"Token.person": [
{
"Person.handle": "BubblyCat",
"uid": "0x102c3"
}
],
},
{
"Token.person": [
{
"Person.handle": "CuddlyBear",
"uid": "0x102c5"
}
],
},
{
"Token.person": [
{
"Person.handle": "CuddlyCat",
"uid": "0x102c7"
}
],
}
]
After:
"tokens": [
{
"Token.person": [
{
"Person.handle": "BubblyCat",
"uid": "0x102c3"
}
],
"Token.singlePerson": {
"Person.handle": "CuddlyCat",
"uid": "0x102c7"
},
},
{
"Token.person": [
{
"Person.handle": "CuddlyBear",
"uid": "0x102c5"
}
],
"Token.singlePerson": {
"Person.handle": "CuddlyCat",
"uid": "0x102c7"
},
},
{
"Token.person": [
{
"Person.handle": "CuddlyCat",
"uid": "0x102c7"
}
],
"Token.singlePerson": {
"Person.handle": "CuddlyCat",
"uid": "0x102c7"
},
}
]
You can see that the one CuddlyCat
instance was copied to all Token.singlePerson
edges.
So I have two questions:
- Is there a way to do a bulk upsert like this in a single transaction, or do I have to run a separate upsert for each token?
- If I must run an upsert for each token, can I do them all in one transaction, or do I need a separate transaction for each upsert?