Script should correspond to single change. Script should be part of the same release as this change. Here are the steps to write migration script:
-
Lookup current database version in
pkg/migrations/internal/seq_num.gofile -
Under
migrationsfolder create new folder with namem_{currentDBVersion}_to_m_{currentDBVersion+1}_{summary_of_migration}- Ensure that the
summary_of_migrationfollows the naming convention of previous migrations, i.e., postfix_policyif it modifies policies
- Ensure that the
-
Create at least two files:
migration.goandmigration_test.go. These files should belong to packagem{currentDBVersion}tom{currentDBVersion+1} -
To better understand how to write these two files, look at existing examples: #1 #2 #3 in
migrationsdirectory. Avoid depending on code that might change in the future as migration should produce consistent results. -
Add to
migrator/runner/all.goline_ "github.com/stackrox/rox/migrator/migrations/m_{currentDBVersion}_to_m_{currentDBVersion+1}_{summary_of_migration}"
-
Increment the currentDBVersion to currentDBVersion+1
-
Create PR with migration files to build image in CircleCI
-
Checkout before commit with migration files and
make clean image -
export STORAGE=pvc -
teardown && ./deploy/k8s/deploy-local.sh -
./scripts/k8s/local-port-forward.sh -
Create all necessary testing data via central UI and REST endpoints
-
Checkout at the same commit your PR currently pointing to
-
kubectl -n stackrox set image deploy/central central=stackrox/main:$(make tag) -
You can ensure migration script was executed by looking into Central logs. You should see next log messages:
Migrator: <timestamp> log.go:18: Info: Found DB at version <currentDBVersion>, which is less than what we expect (<currentDBVersion+1>). Running migrations... Migrator: <timestamp> log.go:18: Info: Successfully updated DB from version <currentDBVersion> to <currentDBVersion+1> -
Re-run
./scripts/k8s/local-port-forward.sh -
Verify that migration worked correctly