C
C#9mo ago
TJacken

Seed data from migration

Just need opinion about seeding data from migration. Lets start, I have some data on DEV env and I want to migrate data to TEST env. I can generate SQL script from data on DEV env and put generated script in new migration under Up() method. How can I handle future delete/update data generate new migration again? Should I have delete script in Down() method? Or should I manually delete data if new migration has new data.
8 Replies
Jimmacle
Jimmacle9mo ago
i don't like combining seed data with migrations personally i have a separate process to seed data after migrations have run
Angius
Angius9mo ago
Same
Yawnder
Yawnder9mo ago
The only "seeding" I'd do in a migration is something that is required. For example, if you add a new required property that's a FK on a reference table, I would add the default in there, and set the value.
Angius
Angius9mo ago
That's where I make the FK optional, then fill it up with defaults, then remove the ?
TJacken
TJackenOP9mo ago
I'm aware of my approach but I don't have much options left. TEST env is protected and I dont have permission to connevt on db and change data. Pipeline will run migration over database and pipeline has permissions to do it over all environments.
Jimmacle
Jimmacle9mo ago
i don't seed my data by hand my application does my application applies the migrations too
TJacken
TJackenOP9mo ago
Okay, but this way of seeding data is not bad option or?
Jimmacle
Jimmacle9mo ago
if you want your seeding to be coupled with your migrations it's fine migrations also support seeding "properly" by configuring .HasData
Want results from more Discord servers?
Add your server