Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to "compress" Flyway migrations?

Tags:

flyway

We are using Flyway to migrate the database schema and we already have more than 100 migration scripts.

Once we "squashed" multiple migrations into a single first-version migration, this is ok during development, as we drop and recreate the schema. But in production this wouldn't work, as Flyway won't be able to validate the migrations.

I couldn't find any documentation or best practice of what to do in this case. The problem is that the file quantity increases constantly, I don't want to see thousands of migration files everytime, essentially if production is already in the latest version. I mean, the migration scripts that have a version number that is lower than the version in production are irrelevant to us, it would be awesome if we could squash those files into a single migration.

We are using MySQL.

How should we handle this?

like image 846
Thiago Negri Avatar asked Nov 03 '15 21:11

Thiago Negri


People also ask

Is Liquibase better than Flyway?

While both tools are based on Martin Fowler's Evolutionary Database, there are many differences in what these tools offer. Here's where Liquibase and Flyway differ. The bottom line is that Liquibase is more powerful and flexible — covering more database change and deployment use cases than Flyway.

What is Flyway Outoforder?

Description. Allows migrations to be run “out of order”. If you already have versions 1.0 and 3.0 applied, and now a version 2.0 is found, it will be applied too instead of being ignored.

Where are Flyway migrations stored?

Flyway automatically discovers migrations on the filesystem and on the Java classpath.

Are Flyway migrations transactional?

Flyway and Transactions. With Flyway, if you make a mistake and an error is triggered, then the migration rolls back. Migrations are applied within a transaction whenever possible, and Flyway rolls back the migration if it receives an error message on its connection.


1 Answers

Isn't that what re-baselining would do?

I'm still new to flyway, but this is how I think it would work. Please test the following first before taking my word for it.

Delete the schema_version table. Delete your migration scripts.

Run flyway baseline (this recreates the schema_version table and adds a baseline record as version 1)

Now you're good to go. Bear in mind that you will not be able to 'migrate' to any prior version as you've removed all of your migration scripts, but this might not be a problem for you.

Step by step solution:

  1. drop table schema_version;
  2. Export database structure as a script via MySQL Workbench, for example. Name this script V1__Baseline.sql
  3. Delete all migration scripts and add V1__Baseline.sql to your scripts folder, so it is the only script available for Flyway
  4. Run Flyway's "baseline" command
  5. Done
like image 85
David Atkinson Avatar answered Oct 11 '22 12:10

David Atkinson