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.go
file -
Under
migrations
folder create new folder with namem_{currentDBVersion}_to_m_{currentDBVersion+1}_{summary_of_migration}
- Ensure that the
summary_of_migration
follows the naming convention of previous migrations, i.e., postfix_policy
if it modifies policies
- Ensure that the
-
Create at least two files:
migration.go
andmigration_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
migrations
directory. Avoid depending on code that might change in the future as migration should produce consistent results. -
Add to
migrator/runner/all.go
line_ "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