Redgate Flyway

Pre and Post Deployment Scripts for State-based deployments

FLYWAY ENTERPRISE

This currently is a work in progress.  Please email us if you're interested in using Pre and Post deployment scripts in your state-based deployments.

This example shows you how to have scripts run before and/or after every state-based deployment.

Create two folders in the root of your project (at the same level as the schema-model folder) called PreScripts and PostScripts.

In the PreScripts folder, add any scripts that you want to run before a state-based deployment.  This could be a script to take a backup or maybe check permissions or insert a record to capture the deployment.  The script must start with the name "beforeMigrate."  Multiple scripts are allowed (e.g., beforeMigrate_1.sql, beforeMigrate_2.sql).  

In the PostScripts folder, add any scripts that you want to run after every deployment.  This could be to take a backup, check the number of records in a table, or do further data manipulation.  The script must start with the name "afterMigrate."  Multiple scripts are allowed (e.g., afterMigrate_1.sql, afterMigrate_2.sql).  They will be executed in alphabetical order.

Make sure your scripts are idempotent if your pipeline is setup to have them executed on every deployment.

In your pipeline, the workflow could look like:

  1. flyway prepare
    Prepare your deployment script by comparing the schema model on disk to a target database.  This gives you a chance to review the script before executing it on the target.

  2. flyway check -changes or other additional capabilities (e.g., code analysis, drift detection).

  3. Deploy your changes with pre/post scripts:
    1. flyway deploy -locations=PreScripts
    2. flyway deploy...
    3. flyway deploy -locations=PostScripts




Didn't find what you were looking for?