How Can We Use Flyway with Gitlab CI/CD Pipeline

Hasan Kadir Demircan
3 min readNov 18, 2022

As you know, for database version control, we use some tools such as Liquibase and Flyway.
Today, we will look at how we can use flyway with GitLab ci/cd pipeline.

First of all,
I created a PostgreSQL database on AWS to test flyway actions on my database.

Now let’s go forward with creating gitlab-ci.yml

gitlab-ci.yml

I defined flyway.sh file. When I start the pipeline, the code will run flyway.sh file.

  • Sh file processes the following steps in order
  • Created flyway URI.
  • Download flyway dependency
  • Flyway info (only snaps the status of table before migrating process)
  • Flyway migrate (migration)
  • If you use MySQL, Redshift, or another database, you should change flyway URI and don’t forget to add the SQL connector jar into the repository like postgresql-42.5.0.jar

These POSTGRES_ADDRESS, POSTGRESS_PORT etc.. are defined on GitLab CI/CD variables like below.

  • You can define these variables for each environment such as dev, qa, and prod.

here are my values on GitLab ci/cd variables section

SQL File:

NOTE: Don’t forget to start the file name with V1__ , V2__ etc..
Let’s run the pipeline

  • Flyway-info runs and shows the version, description, type, and state pieces of information.
  • flyway-migrate runs and creates the accounts table.

When I check the table on a database client app, I see my account table :)

  • Flyway also creates a table to calculate checksum and control the versions of tables

If I run the pipeline again;
I will see that state = Success

If you have any questions, please don’t hesitate to contact me.

Here are the all flyway commands, you can use which are required for your project

Gitlab Link: Here

--

--