ArgoCD › Sync Waves & Hooks

How do you run a database migration safely before deploying a new version?

Intermediate

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: HookSucceeded
Real-world example The schema migration runs as a PreSync Job; only after it succeeds does the new app image get deployed.

Common follow-ups: What happens to the deploy if the migration fails? | Why PreSync rather than PostSync?