updateManyXXXX not working as expected for complex type in schema
Describe the bug
Can't updateManyXXXX fields null to post types It only work with basic type
To Reproduce Steps to reproduce the behavior:
- Deploy this schema
type User {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
username: String! @unique
password: String!
}
- Create User from mutation
- Add more fields to schema
type User {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
username: String! @unique
password: String!
post: Post
}
type Post {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
content: String
}
- Now post fields in old user will be null but we want to migrate old data to have post type
mutation {
migration_01: updateManyUsers(
where: { post: null }
data: {
post: {
create: {
content: "hello world"
}
}
}
) {
count
}
}
Expected behavior Return post not null and have content = "hello world" for that user instead post will still be null and no content
Versions (please complete the following information):
- OS: Linux archlinux 4.18.5-arch1-1-ARCH
prismaCLI:prisma/1.16 node-v8.11.4- Prisma Server:
1.16
@thanatchakromsang I have same your problem. I want to know a solution for migration this case.
I don't understand the expected behaviour you're proposing, can you clarify?
@marktani I want to migrate old users which have Post as null but in reproduction step 4 It did nothing
I see! This is because nested mutations inside updateMany are currently not applied: #2010. Please follow the other issue 🙂
@marktani Thanks for the head up I got it working by migration script using typescript instead
import { Prisma } from '../generated/prisma'
const prisma = new Prisma({
endpoint: process.env.PRISMA_ENDPOINT,
secret: process.env.PRISMA_SECRET,
debug: false,
})
const main() = async () => {
const allUser = await prisma.query.users({
where: { notificationSetting: null },
})
let count = 0
const updatedUser = await Promise.all(
allUser.map(async user => {
count += 1
console.log(`update user id: ${user.id}`)
return prisma.mutation.updateUser({
where: { id: user.id },
data: {
post: {
create: {
content: "hello world",
},
},
},
})
}),
)
console.log(`===== updated ${count} users =====`)
}
main()
.then(() => {
process.exit(0)
})
.catch(e => {
console.log(e)
process.exit(1)
})