[performance] improved enum migrations #3782
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This improves our shared enum migration function to use a singular update query that handles all possible variations using a CASE statement (thank you for the suggestion @mirabilos !). I probably should have gone with this approach first but our ORM doesn't expose CASE logic so it hadn't initially jumped to mind. The ups-and-downs of ORMs, eh!
I ran this on our test suite (which isn't always the best test of migrations) with both SQLite and Postgres just fine. And I had an old backup of my own database which I was able to use to confirm in a production-like environment that this definitely works on SQLite. Obviously if anyone has an old backup of some Postgres data to test this against feel free to let us know and we can wait for a test on that!
Checklist
go fmt ./...
andgolangci-lint run
.