.zh
PPrisma
•Created by .zh on 12/30/2024 in #help-and-questions
Executing data migration/data field seed script for a migration automatically
I did a quick search on the topic but didn't find any concrete solution I can use and it is quite the everyday case. Basically, I need to introduce a new required field in my db (postgres). The recommended solution is the expand-contract pattern where I first introduce the field as optional, then seed the data and then make it required in 2 separate migrations. For the data seeding aspect, I see a couple of options: default value in schema (which can reduce the migrations to 1), modify the migration
.sql
to seed the field or execute a script manually after the migration before proceeding. However, none of the solutions for seeding cover my case. I need to be able to execute a sequence of migrations without going 1 by 1 and manually running data migrations scripts inbetween. Basically, I want to create the field, seed the data and make it required in one migrate deploy
step. How can I achieve that? Can I somehow associate a data migration script to every migration that gets executed automatically before the next migration or something? I can't use @default()
as the data is calculated dynamically.8 replies