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 a provisioner to automatically swap out your development database on branch switch.

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.

Relevant tutorials



Didn't find what you were looking for?