Common state-based deployment scripts
Published 12 September 2025
Deployment with manual review step when the target environment is configured in toml
# Check to see if the target environment has drifted since last deployment (optional) flyway check -drift -environment=production -failOnDrift=true # Generate a deployment report, containing list of objects changes (optional) flyway check -changes -changesSource=schemaModel -environment=production # Generate a deployment script, which can be reviewed flyway prepare -source=schemaModel -target=production -scriptFilename="D__deployment.sql" # Run code analysis on deployment script (optional) flyway check -code -scope=script -scriptFilename="D__deployment.sql" -failOnError=true ### Manual review step ### # Execute deployment script and save a snapshot in the target environment, which can be used for future drift checks or rollbacks flyway deploy -scriptFilename="D__deployment.sql" -environment=production -saveSnapshot=true
This script generates a deployment report, and allows for a manual review before deployment. It uses the check drift, check changes, prepare, and deploy commands.
Deployment with manual review step when the target environment is configured inline
# Check to see if the target environment has drifted since last deployment (optional) flyway check -drift "-url=<JDBC URL>" -failOnDrift=true # Generate a deployment report, containing list of objects changes (optional) flyway check -changes -changesSource=schemaModel "-url=<JDBC URL>" # Generate a deployment script, which can be reviewed flyway prepare -source=schemaModel "-url=<JDBC URL>" -scriptFilename="D__deployment.sql" # Run code analysis on deployment script (optional) flyway check -code -scope=script -scriptFilename="D__deployment.sql" -failOnError=true ### Manual review step ### # Execute deployment script and save a snapshot in the target environment, which can be used for future drift checks or rollbacks flyway deploy -scriptFilename="D__deployment.sql" "-url=<JDBC URL>" -saveSnapshot=true
This script generates a deployment report, and allows for a manual review before deployment. It uses the check drift, check changes, prepare, and deploy commands.
Full automated deployment
# Check to see if the target environment has drifted since last deployment (optional) flyway check -drift -environment=production -failOnDrift=true # Generate a deployment report, containing list of objects changes (optional) flyway check -changes -changesSource=schemaModel -environment=production # Combined script generation and deployment, with script generated to default location flyway prepare deploy -prepare.source=schemaModel -deploy.saveSnapshot=true -environment=production
This script generates a deployment report, and skips the manual review step. It uses the check drift, check changes, prepare, and deploy commands. Note: be careful of the namespaced parameters.
Undo script generation
# Generate a deployment script and a corresponding undo script flyway prepare -source=schemaModel -target=production -types=deploy,undo -scriptFilename="D__deployment.sql" -undoFilename="DU__undo.sql"
This script generate a deployment script which can be used to rollback the deployment. It uses the prepare command.