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
i don't like combining seed data with migrations personally
i have a separate process to seed data after migrations have run
Same
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.
That's where I make the FK optional, then fill it up with defaults, then remove the
?
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.
i don't seed my data by hand
my application does
my application applies the migrations too
Okay, but this way of seeding data is not bad option or?
if you want your seeding to be coupled with your migrations it's fine
migrations also support seeding "properly" by configuring
.HasData