Redgate Flyway

Switching between branches

If you are working on a new feature and wish to isolate your changes from the default or main branch, you can start working on a new branch.

Handling the development database when switching branches

Branches have the benefit of providing you with isolated development areas. But when you switch branch the schema changes you are tracking have changed on disk, but your development database is still the same as it was when on your previous branch.

Either you have to update your development database to match the project state on the branch, or you need to point to a different development database per branch.

The most flexible solution is to use a different database per branch, as it minimizes the overhead of switching back and forth between branches, To avoid having to repeatedly reconfigure your development database connection all the time, Flyway provides a Git resolver that can be used to generate a database name based upon a branch name. See this tutorial for how to implement this.

The neatest solution is to combine this approach with use of Redgate Clone to automatically swap out your development database on branch switch. See this tutorial for the steps needed.

The other approach is to use a single database and manually update it ti match the new project state whenever you switch branch. Updating the development database is simpler if using a schema model. If you are taking this approach and using migrations, it is best to drop and recreate the database.

Redgate Clone - SQL Server, Oracle, PostgreSQL, and MySQL

Redgate Clone can be used to create database instances with full copies of your database for each piece of work during development, and switch between them automatically when you change branches in Git. This allows you to make changes to your database on one branch, and store those changes when you need to work on another branch. When you return to the original branch all your database changes including data will be preserved. Learn more about Redgate Clone.

See this tutorial for getting this configured.

SQL Clone - SQL Server (new users should use Redgate Clone), 

This gives you the same capabilities as Redgate Clone but for SQL Server only. See the SQL Clone documentation for creating a git post-checkout hook to do this automatically. 

Relevant tutorials



Didn't find what you were looking for?