ArgoCD › Sync Waves & Hooks
How do you run a database migration safely before deploying a new version?
IntermediateAnswer
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.