Changing the database during a rollout.
WHAT THE PROBLEM IS
Several instances deploy gradually, so old and new code run simultaneously.
WHAT THAT REQUIRES
Schema changes compatible with both versions.
WHAT THAT MEANS PRACTICALLY
Add before removing, always.
WHAT THE SAFE SEQUENCE IS
Add the new structure Deploy code writing to both Migrate existing data in batches Deploy code reading the new Stop writing the old Remove it in a later release
WHY THAT MANY STEPS
Each is safe with the version before and after it.
WHERE TO RUN THE MIGRATION
As a separate job, before the rollout.
WHAT NOT TO DO
Run migrations from every application instance at startup.
WHY
Several instances then migrate simultaneously.
WHAT TO USE IF STARTUP MIGRATION IS UNAVOIDABLE
A lock, so only one proceeds.
WHAT AN INIT CONTAINER PROVIDES
Something running to completion before the main container starts.
WHERE THAT SUITS
Waiting for a dependency, or preparing state.
WHAT TO BE CAREFUL WITH
Long migrations blocking the rollout Migrations that cannot be reversed
WHAT TO TEST
The migration against production-sized data, timed.
WHAT TO PREPARE
A way to stop it partway.