migration: Add stitch utilities
Created by: efritz
This PR adds utilities to combine the migration graphs over several releases of Sourcegraph so that we can perform upgrades over multiple versions where a migration file squash has occurred. Fixes #38045 (closed).
The new main method StitchDefinitions
calculates a stitched migration graph for tests but is not yet utilized. Future PRs will bundle these results into artifacts that can be used to upgrade on-prem.
How to review - by file, in order:
-
stitch_test.go
: Start with the test case to see the current coverage.There's currently only basic validation (is the graph valid), but we should also add testing to ensure the migration graph can run correctly against a live database in a subsequent PR.We validate the graph and the result of an upgrade from 3.29 -> 3.42. -
git.go
: Read these leaf functions that interact with the enclosing git clone to prep for the next two files. -
reader.go
: Read this file which reads "raw migrations" from the enclosing git clone. -
rewriter.go
: This is a wrapper around reading raw migrations (above) that does some specific rewrites to handle changes to migration definitions over time. Pay attention to details within this file, but forget them once moving on in the review. This file is how we support migrations defined back to 3.29.0 for all three schemas. -
stitch.go
: Read top-to-bottom with code flow to finish off how migrations are merged together.
Test plan
New unit tests introduced in this PR.