Categories
General

Using Flyway to Manage Database Changes

Flyway is an open source project that let’s you manage your database changes. In simple terms, it helps us migrate database changes from one environment to another environment. Currently our team is working on a new project that it’s using Postgresql, ASP.NET MVC, and WebApi. When we started the project, we did not have an easy way to manage database changes. At the beginning, we decided to create sql files to manage database changes. We were able to capture the database changes but it was difficult to migrate changes. After some time researching database tools, we decided to use Flyway.

In this post, I want to share how simple is to setup Flyway in a windows environment.

1. Install Flywaydb command line tool
Go to flywaydb.org and download the command line tool. When you are done installing the cli, go ahead and add it to your path. I highly recommend it so you can run flyway from any directory.

2. Setup folder structure
We have 3 environments that we need to deploy to: development, test, and production. To make our lives easier, we create a conf folder and inside that folder we create dev, test, and prod folder. Each environment folder will have the configuration file to connect to the specific database.

For dev, we created a post-build step that will run the migrations automatically. For test and production, we will run them manually. We do this because we need to be more careful about those environments.

3. Run migrations
When you are ready to apply the database changes, you can open up a new console window and type “flyway migrate” and press enter. This command will run all pending changes to the specific database. The nice thing about Flyway is that it keeps track of all the versions or migrations thru the schema_version table.

In the next post, I will share a sample project that demonstrate how to use Flyway to manage Postgresql changes in a windows environment.

Leave a Reply

Your email address will not be published. Required fields are marked *