Redgate Flyway

Recommended practices

  1. After auto-generating a migration script, never edit it to include new schema changes.  Always make the changes to your development database first, then save to schema model, and then generate the migration script.

  2. Be careful with branching.  Best to start simple and avoid branching unless you need to/really understand what you're doing. See Switching Branching for more information.

  3. Generate migrations from the same branch to avoid conflicts.  The schema model could catch conflicts, but not necessarily and you may need to edit version numbers, which could create additional work to straighten out.

  4. The filename description defaults to your username.  It's nice to give this a clearer description to more easily understand the contents of your repo.

  5. Always protect your credentials.  You can leverage the CI/CD system to do this using variables.

  6. Rolling forward: In the event there was a bad change in a migration script that has been applied to some of the downstream environments (e.g, Pre-Prod) and you don't want it to be deployed any further, the recommended workflow is to:
    1. Apply the undo script to all the environments the script was applied.  For example, if your pipeline is Test > QA > Pre-Prod > Prod, then you would have to undo Test, QA, and Pre-Prod.  Ideally this will catch everything in the migration.  You can also use our comparison tools to check how the environments differ from Prod or an environment without this change to make sure everything is undone.)
    2. In local filesystem, delete the bad migration script.  This will cause the Shadow DB to be cleaned and rebuilt the next time you refresh the Generate Migrations tab.
    3. Commit and push this change (or use a Pull Request) to the remote repo so this bad migration script is no longer in the repository.
    4. Correct the Development DB to the desired state in the IDE of your choice (Visual Studio Code, SSMS, SQL Developer, etc.).
    5. In Flyway Desktop
      1. Save the changes made in the Development DB to the schema model.
      2. Generate a new migration script.
      3. Commit and then push this change (or use a Pull Request) to your remote repo. 
    6. This new script will now flow through the pipeline as normal.

  7. It's best to explicitly name your constraints.  You can read more about this in the Bad UNDOs section in this article.

  8. If you're using Oracle, or a database that auto-commits DDL, then it might be best to have one change per versioned migration script so that if the script fails, then you're not left in a state where some of the migration script is executed and the rest is not and you have to fix up the release.  

Didn't find what you were looking for?