documentation/Reference/Commands/Check/Check Drift.md
{% include enterprise.html %}
The check -drift command checks a target environment for drift, in order to ensure that it is still in the expected
state for running deployments.
Deployment can be aborted if drift is detected, and a report will be generated.
The report is generated using snapshots .
See Drift analysis for more information.
flyway check -drift -environment="Production"
The comparison which underlies the report is generated from the specified snapshot and a target database. Note that if you configure your pipeline to check for drift ahead of doing a deployment, the very first time you do a deployment, there won't be a snapshot in the database to use for the drift check. In this scenario, Flyway will succeed but log a warning, so that the first deployment doesn't have to be treated as a special case.
flyway check -drift -deployedSnapshot="C:\snapshot1.json" -environment="Production"
The comparison which underlies the report is generated from the specified snapshot and a target database.
flyway check -drift -buildEnvironment="build" -environment="production"
This approach captures a snapshot of the updated build database, and uses this as the basis for the comparison against the target database which underlies the report. This approach will detect all drift from what is in the migrations, regardless of whether it has occurred since the last deployment or was pre-existing.
flyway info -infoOfState="success,out_of_order" -migrationIds > appliedMigrations.txt
flyway check -drift -buildEnvironment="build" -appliedMigrations="$(cat appliedMigrations.txt) -environment="production"
This approach captures a snapshot of the updated build database, and uses this as the basis for the comparison against the target database which underlies the report. This assumes that the migrations deployed to the target environment represent the full state of that database at the point of last deployment.
| Parameter | Namespace | Description |
|---|---|---|
deployedSnapshot | check | A snapshot matching the last known state of the target database. |
buildEnvironment | check | Build environment id, when using a build environment instead of a snapshot. |
buildUrl | check | URL for the build database, when using a build environment instead of a snapshot and defining the environment inline. |
failOnDrift | check | Return an error if drift is detected. |
appliedMigrations | check | Migration ids (migration versions or repeatable descriptions) to apply to create snapshots. |
buildUser | check | Username for the build database. |
buildPassword | check | Password for the build database. |
filterFile | check | The path to a filter file, containing custom filtering rules for excluding objects from the comparisons. |
generateDriftResolutionScripts | check | Generates scripts for reverting, incorporating, or filtering the drift, if drift is detected. |
environment | (root) | The target environment id. |
reportFilename | (root) | The output path of the generated report. |
workingDirectory | (root) | The directory to consider the current working directory. All relative paths will be considered relative to this. |
| {environment parameters} | (root) | Environment configuration for the source and/or target environments. |
Universal commandline parameters are listed here.
Settings from the following sections of the Flyway namespace can be specified in relation to database connections:
When a build environment is used, settings from the following sections of the Flyway namespace can also be set:
Note:
failOnDrift error occurs, Flyway will continue processing the remaining verb operations.
For this reason, it is recommended to run subsequent Flyway verbs separately.{
"htmlReport": "report.html",
"jsonReport": "report.json",
"individualResults": [
{
message: null,
stackTrace: null,
onlyInSource: [],
onlyInTarget: [],
differences: [
{
name: "Table_1",
schema: "dbo",
objectType: "Table",
definitionBefore: "CREATE TABLE Table_1 (id text)",
definitionAfter: "CREATE TABLE Table_1 (different_id text)",
},
],
timestamp: "2022-07-22T08-08-33Z",
database: "testdb",
operation: "drift",
flywayVersion: undefined,
warnings: undefined,
}
]
}
This command can produce the following error codes: