State-Based Approach – Flyway CLI
Published 22 December 2025
👉 Want to skip ahead and use ready-made scripts? Clone the full repo here: Flyway Helper Files GitHub Repo.
Why choose State-Based?
State-based deployments let you define your database schema as a model and automatically generate deployment scripts to bring any target database in line with that model. This approach is:
- Recommended for new users: Quickest time-to-value (Especially when paired with our Chinook sample schema to get up and running)
- Ideal for automation: Perfect for CI/CD workflows where you want predictable, repeatable deployments.
Unlike migrations-based workflows, you don’t need to handcraft every script. Instead, Flyway compares your model to the target database and generates the necessary changes.
State-based workflows typically involve two stages:
1. Developer Workflow Simulation
Commands like diff and model simulate what developers do in Flyway Desktop:
diff: Compares two sources (e.g., Development DB vs model) and shows the differences.model: Analyse the above diff output and save changes to your Flyway Schema Model.
2. DevOps Workflow Simulation
Commands like prepare, snapshot, check, and deploy are used in CI/CD pipelines:
prepare: Generates a deployment script based on differences between model and target.snapshot: Captures the state of a database for drift detection and auditability of database state.check: Validates that the deployment script is safe and any known risk for the upcoming deploymentdeploy: Applies the generated script to the target database.
Tip - Not every customer needs both stages—if your goal is simply to deploy changes, you can start at prepare → deploy.
💡Using the Chinook Sample Database
For the fastest start, use the Chinook schema for SQL Server, PostgreSQL, Oracle, or MySQL. It’s included in our Flyway Helper Files repo.
Run the setup script for your database engine, then proceed with the steps below.
(Prefer your own schema? That works too—just adjust the connection details accordingly)
Next Steps
Below, you’ll find expandable sections for each command in the workflow.
The full repository can be found here: 👉 Flyway Helper Files GitHub Repo
Each section includes:
- Purpose – Why the command matters.
- When to use – Where it fits in the workflow.
- Helper script links – Quick access to ready-made scripts.
- How to configure – Variables explained for easy setup.
✔️ What You’ve Achieved
Congratulations! You’ve now completed the State-Based Flyway CLI workflow end-to-end:
- Captured differences between environments with Diff.
- Updated your schema model using Model.
- Generated deployment and undo scripts with Prepare.
- Created snapshots for drift detection using Snapshot.
- Validated changes and code quality with Check.
- Applied changes to your target environment using Deploy.
By following these steps, you’ve proven the workflow works and mastered the basics of Flyway CLI for state-based deployments. This foundation gives you the flexibility to integrate Flyway into almost any workflow—including CI/CD pipelines—at your own pace.
Next Steps
- Explore more learning resources:
Redgate University offers self-paced courses to deepen your knowledge. - Need tailored guidance?
Redgate Professional Services can help with advanced scenarios or bespoke implementations. - Ready for full automation?
Check out the Flyway Autopilot guides for CI/CD pipeline setups and advanced workflows.