Problem
To get around the imperative migration issue as stated here https://github.com/prisma/migrate/issues/492
I need to run a database migration, then migrate the data, then proceed with another database migration.
If I test this locally there's no way for me to perform this operation in production as migrate up runs all migrations and I can't do the data migration in between.
For example, if I add a non-nullable Author relation to a Post, I need to
- Create a nullable migration
model Post {
id String @default(cuid()) @id
author Author? @relation(fields: [authorId], references: [id])
authorId String?
}
- Set up the default data
const posts = await prisma.posts.findMany()
for (const post of posts) {
await prisma.task.update({
where: { id: post.id },
data: {
author: getDefaultAuthor(),
},
});
- Then migrate the field to be nullable.
model Post {
id String @default(cuid()) @id
author Author @relation(fields: [authorId], references: [id])
authorId String
}
If I perform the 3 steps above locally, then wish to do the same in production, it is not possible as migrate up will execute both steps 1 & 3, and I can't execute step 2 in between.
Suggested solutions
For my needs, the solution here would be great https://github.com/prisma/migrate/issues/492
However, if it's quicker to implement a way to migrate or down a specific number of steps or to a specific version. It is possible to work around the current implementation, and I'm sure it would be useful in other circumstances as well.
Migrate up / down 2 steps
prisma migrate up -steps 2
prisma migrate down -steps 2
Or migrate all migration between the current completed migration and the specified id / timestamp
prisma migrate up -id 20200701123310
prisma migrate down -id 20200701123310
Problem
To get around the imperative migration issue as stated here https://github.com/prisma/migrate/issues/492
I need to run a database migration, then migrate the data, then proceed with another database migration.
If I test this
locallythere's no way for me to perform this operation inproductionasmigrate upruns all migrations and I can't do the data migration in between.For example, if I add a non-nullable
Authorrelation to aPost, I need toIf I perform the 3 steps above locally, then wish to do the same in production, it is not possible as
migrate upwill execute both steps 1 & 3, and I can't execute step 2 in between.Suggested solutions
For my needs, the solution here would be great https://github.com/prisma/migrate/issues/492
However, if it's quicker to implement a way to migrate or down a specific number of steps or to a specific version. It is possible to work around the current implementation, and I'm sure it would be useful in other circumstances as well.
Migrate up / down 2 steps
Or migrate all migration between the current completed migration and the specified id / timestamp