Integrating Flyway into an existing database with Jenkins

Viewed 121

We haven't used Flyway from the beginning of our project. We are at an advanced state of development. And let's start using Flyway in our project with Jenkins.

From the documentation, what I understood is:

Take a backup of the development schema (both DDL and DML) as SQL script files, give a file name like V1_0_1__initial.sql.

Clean the development database using "flyway clean".

Baseline the Development database "flyway baseline -baselineversion=1.0.0"

Now, execute "flyway migrate" which will apply the SQL script file V1_0_1__initial.sql.

Any new scripts should be written with higher version numbers (like V2_0_1__account_table.sql)

Is this the correct way or is there any better way to do this?

1 Answers

No, this is not quite right. Cleaning and then executing your DDL/DML again could be a useful test that you've got it right, but if you clean the database there is no need to baseline any more.

The correct sequence for baselining is:

  • Take a backup of the development schema (both DDL and DML) as SQL script files, with a file name like V1_0_0_initial.sql.

  • In development, run flyway baseline -baselineversion=1.0.0 - this tells Flyway that the database is already in the state represented by the V1.0.0 script and it should not be run again.

  • In other environments, run flyway migrate - so that Flyway runs the V1.0.0 script. Your various environments should now be in the same state

Any new scripts should be written with higher version numbers, and applied in every environment with flyway migrate

Related