Tutorial - Roll back a state-based deployment
Published 21 November 2025
Pre-requisites
- Created a project
- Saved a schema model
- Configured a target environment. The environment referenced in this tutorial is named production.
Steps to run
- Generate an undo script alongside a deployment script
You can generate an undo script when running the prepare command as part of a deployment
flyway prepare -source=schemaModel -target=production -types=deploy,undo -scriptFilename="D__deployment.sql" -undoFilename="DU__undo.sql"
You should get confirmation of the operation success in the output
Note that while the
preparecommand can be used for migrations-based deployments as well, generating undo scripts in this scenario is not currently supported. - (Execute the deployment script)
Run the deploy command
flyway deploy -scriptFilename="D__deployment.sql" -environment=production
You should get confirmation of the operation success in the output
- Execute the undo script
flyway deploy -scriptFilename="DU__undo.sql" -environment=production