Monsieur Wholesome
Proper usage of EF Core in teams?
The re-doing of the migration with rebasing ain't that bad tbh, unless you have a really really big database project.
Because Remove-Migration & Add-Migration will force rebuild the project before doing the Migration generation magic. Of course, you can force it to not rebuild via a --no-rebuild flag or something, but the default is to let it build the latest version of your code
We have a pretty sizable database project, and when compiling only the Database with no migrations, it takes around 16 seconds
One pain point however of managing EFC Migrations:
Each migration creates and keeps a
.Designer.cs
which is a snapshot of the entire database, and each migration adds onto the last Snapshot, so it gets bigger and bigger. So after like 30 Migrations it causes our Database project file to bloat up to 1:30 Minutes in compile time. Which is pretty annoying. Not just that, but it hogs up huge amounts of RAM during compilation just because it needs to compile essentially the same huge file again and again.
There is currently no solution to that, and it's only a problem if you've got a huuge database project.
The only workaround is to squash the Migrations. basically eliminating the option to rollback to previous migrations and merging all 30+ Migrations into 1 initial.cs migration.
It's a process that we are planning on implementing regularly at some point, and as far as I have heard, other companies do that too8 replies
Proper usage of EF Core in teams?
One thing however is
You can leave out applying migrations, as long as the migrations were added in incremental order
-
20241201_AddTableX.cs
-- Added 01st December
- 20241202_CriticalChangeY.cs
-- Added 02nd December
- 20241203_UpdateColumnZ.cs
-- Added 03rd December
All of these were Add-Migration'ed one after the other, nicely, but you still need CriticalChangeY
for testing, and you cannot afford it to go live on the prod update tomorrow
Then you can simply leave out the commit which added that Migration, via a hotfix / release branch with cherry picking, so that its "Up()" method can never run.
And yes, if you later on add CriticalChangeY
back onto your deployed branch, it will work with no problems
We do that sometimes 😉8 replies
Proper usage of EF Core in teams?
EFC Migrations are always supposed to be added in incremental order
Never never never let two migrations be made and merged in parallel. They need to be added one after the other
If two people work on the DB within two PRs, then the PR who is getting merged second has to bite the bullet, and needs to
- Rollback the Migration from their local db (Update-Database to previous migration)
- Undo the Migration (Revert
XContextModelSnapshot.cs
, Delete 20241204.....MigrationName.cs
& 20241204.....MigrationName.Design.cs
)
- Rebase PR branch to the develop / main branch with the other migration
- Add-Migration now that we have the other migration
- Push / Update PR8 replies
Improving performance / caching
Of course, you can scatter information about the existence of a file around the table, but it can and will in the long run hurt integrity
Things will get lost, files will be deleted, and various tables need to be updated extensively
61 replies
Improving performance / caching
https://www.microsoft.com/en-us/research/publication/to-blob-or-not-to-blob-large-object-storage-in-a-database-or-a-filesystem/?from=https://research.microsoft.com/apps/pubs/default.aspx?id=64525&type=exact
Is a good research paper talking about disk (blob storage being just one way of saving a file on a disk) vs database storage of files
61 replies