How do you run a database migration safely before deploying a new version?
Short answer
Use a PreSync hook Job that runs the migration; ArgoCD waits for it to complete successfully before applying the new app version (in a later phase/wave).
Advertisement
AModel answer
Use a PreSync hook Job that runs the migration; ArgoCD waits for it to complete successfully before applying the new app version (in a later phase/wave). If the migration fails, the sync fails and the new version isn't rolled out, protecting against deploying code against an unmigrated schema.
kind: Job
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookSucceededReal-world example
The schema migration runs as a PreSync Job; only after it succeeds does the new app image get deployed.
Likely follow-ups
- What happens to the deploy if the migration fails? | Why PreSync rather than PostSync?
Related topics