EF Core generates and stores a full snapshot of the database for every migration. For a large data model, like we have at Vesta (come join us!), every migration adds ~15k LOC. Over time, we end up with more migration than application code—in 10 months, we generated over 2 million(!) lines of migration code.
All these snapshots significantly impact compile time, and without configuration, makes interacting with the codebase more tedious and slower. These snapshots also aren’t useful—after enough time has passed, it becomes prohibitively difficult to actually revert N migrations back.
Ideally, we’d be able to “squash” old migrations into one, removing the old snapshots and migration logic while preserving the ability to spin up a fresh database. In the following, I’ll describe how we achieved this at Vesta.
Track has been the most constant part of my life these past few years—through job changes, moves, and a global pandemic, I’ve hit the track and competed. This year, my preseason started all the way back in September of last year, and I didn’t run my last race until the last day of July.
And I had a great season! I shaved two tenths off my wind-legal 100m (10.92->10.71) and more than a half second off my 200 (22.10->21.55)—these results, especially the 200, are well beyond my expectations for the year. I also managed to stay healthy during the competitive season (with one minor hamstring injury in October) for the first time in about a decade.
At Vesta, we have a multi-tenant application where tenant data is logically separated in our Postgres instance by a tenant_id column on entity tables. As we’ve grown, we’ve had to delete some tenant data. Although I’ve done it manually a few times in psql, manually deleting rows is dangerous, so I decided to write a script to delete tenants for us.
We use EF Core for all of our database interactions at Vesta, so our entire database schema is represented in our DbContext. Because DbContexts contain entity metadata, I wrote the script against that data.
After the Summer Sunset Classic, I wasn’t sure if I’d compete again this season. But I felt like I’d ended on a down note, especially from skipping the 200 in that meet. So I kept training, and I flew down to Lexington this past week to compete in the 100 and 200 at the USATF Masters National Championships.
I concluded my track season at the Sunset Summer Classic in Marietta this past weekend. Although I intended to race both the 100 and 200, the meet was gargantuan and extremely late: I didn’t run the 100 until 8:45 PM (I’m usually in bed before 8:30)! Since the 200 wasn’t likely to go off before 11 PM or so, I skipped it.