Migrations-based approach with auto-generation of migration scripts
Published 04 June 2024
This approach is for teams looking to improve developer productivity with auto-generation of migration scripts.
Onboarding tips
The tips below will focus on setting up the script auto-generation from your development database (1).
Separate instructions exist on how to set up database deployments with Flyway (3), and to maintain an object level history (2).
Flyway project setup
Ensure that a Flyway migrations project has been created with the development database, shadow database and baseline script configured.
Script auto-generation can be configured for development teams as follows:
- Migration scripts are generated in Flyway Desktop
- Migration scripts are generated as part of a pull request
- Migration scripts are generated as part of an automated pipeline
For options 2 and 3, developers need not install or interact directly with the Flyway tooling, which means this model is well suited to teams that have an existing development process:
1. Migration scripts are generated in Flyway Desktop
This is suited for developers who want full control over the script generation process.
Note: the following experience is not yet implemented in Flyway Desktop and will be coming soon.
Using Flyway Desktop
- Visit the Generate migrations page to review changes in your development database that aren't reflected in your migration scripts
- Select the specific changes to be added to a new migratino script
- Select Generate scripts to auto-generate both the new migration script as well as the corresponding undo script.
2. Migration scripts are generated as part of a pull request
It is possible to configure script generation when using an ORM and SSDT or any database development process that leverages version control.
- Create a GitHub Action "on: pull_request" that:
- Runs flyway clean migrate on the shadow database
- Compares the database with the shadow database
- Generates a migration script from the changes
- Optionally generates the undo script
- The migration script and undo can be reviewed before the pull request is merged
If an object level history is required, an optional step to generate a schema model from the shadow database can be configured.
3. Migration scripts are generated as part of an automated pipeline
This approach is required when migration script generation can't easily be run as part of a pull request, or this isn't the desired approach. This is particularly suited to teams looking to benefit from auto-generation of migration scripts without interrupting their existing development practices.
To implement, use the same approach as described above but implement as a pipeline in your CI/CD tool. This can be manually triggered or run on a schedule.