Tutorial - Resolve drift by incorporating it (state-based deployments)
Published 05 January 2026
Pre-requisites
- Ensure that your current working directory is set correctly. The working directory can be specified explicitly on every flyway command and will otherwise be the command-line current working directory. All commands in this tutorial assume that the command-line current working directory will be correct.
- Check for drift - if drift is detected, scripts to help with drift resolution will be generated in the
drift-resolutionfolder under your working directory.
Commands to run
- Ensure that your development environment is in sync with your schema model. You can verify this by running the diff command (as we are checking for equality it doesn't matter which is the source and which is the target).
flyway diff -source=development -target=schemaModel
If the environment is in sync with the schema model, no differences will be detected. - Execute the incorporate script against your development database
flyway deploy -scriptFilename="drift-resolution/incorporateDrift.sql" -environment=development
- Update your schema model (see this tutorial for more information on this step)
flyway diff -source=development -target=schemaModel flyway model
- Commit and push to version control
- (Optional) Update snapshot in target environment - if you don't do this, the drift check will continue to fail (see this tutorial for more information on embedded snapshots, and this tutorial for snapshots on the filesystem)
flyway snapshot -source=production -filename="snapshotHistory:drift_correction"
- Rerun your commands for validating your deployment and generating your deployment script (see common state based deployment scripts)
flyway check -drift -environment=production -failOnDrift=true flyway check -changes -changesSource=schemaModel -environment=production flyway prepare -source=schemaModel -target=production
If you have done the previous step, the drift check should now pass. Your previous deployment script would have reverted the drift and the deployment report would have captured this. Your new script should now leave the drift alone and it should not show up as a difference in the report. - You can now deploy safely
flyway deploy -environment=production -saveSnapshot=true
Note that steps 5 and 6 may be part of an automated pipeline, and do not need to be run manually.
Related command reference
Pre-requisites
- Check for drift - if drift is detected, scripts to help with drift resolution will be generated in the
drift-resolutionfolder under your project directory.
Run command
- Ensure that your development environment is in sync with your schema model, by navigating to the schema model page and ensuring there are no differences.
- Execute the incorporate script against your development database
It isn't currently possible to run the deploy command with custom arguments from Flyway Desktop. Navigate to the command line, and follow the instructions for the command-line.flyway deploy -scriptFilename="drift-resolution/incorporateDrift.sql" -environment=development
- Navigate to the schema model page, refresh the left hand pane, and click Save, to update the schema model.
- Commit and push to version control
- If using automated deployments, see the command-line tutorial steps.
If using manual deployment, navigate to the deployment page. Previously the drift would have shown up as differences on this page, and now it should not. Click Deploy... to generate the deployment script and proceed with the deployment.