C
C#2mo ago
Cryy

Create data during EF6 migrations

Hey guys, in our project we use some kind of "changelog implementation" to track all changes in our data. For some reason we also need to create changelongs with default values in case we add let says new columns to DB tables and I dont know what's the best way to do it. Currently I'm playing with some kind of DbCommandInterceptor that detects DB update process (applying migrations), parse them and create records accordingly but I'm not sure if that's correct approach. One of the reason I dont like it it's because it has to parse every command to DB and calculate if it is or if it's not the migration but maybe there is smarter way to do that. Any experience with it ? Thanks
7 Replies
Omnissiah
Omnissiah2mo ago
if it's exclusively part of the migration then why not put it in the migration itself?
Cryy
Cryy2mo ago
You mean put some "seed" kode to migration file itself ? But I dont want to write these updates manually
Sossenbinder
Sossenbinder2mo ago
I'd agree that you might want to put this into a migration
Sossenbinder
Sossenbinder2mo ago
If you're looking for automation, you might be able to do something with https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/operations#using-a-migrationoperation
Custom Migrations Operations - EF Core
Managing custom and raw SQL migrations for database schema management with Entity Framework Core
Sossenbinder
Sossenbinder2mo ago
You could intercept the sql generation, still delegate the sql generation to the base class, but create your custom logic accordingly
jcotton42
jcotton422mo ago
By EF6 do you mean old EF, or Core?
Cryy
Cryy2mo ago
old EF
Want results from more Discord servers?
Add your server