Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to rename Flyway repeatable migrations?

I have set up a bunch of repeatable migrations for my project to drop (and recreate) some frequently modified database views. The package structure looks something like this:

src/main/resources
  |-db
    |-R__pets_amphibians_view.sql
    |-R__pets_birds_view.sql
    |-R__pets_mammals_view.sql
    |-R__pets_reptiles_view.sql
    |-...
    |-<versioned-migrations>

Now, what I would like to do is to split the R__pets_mammals_view.sql view up into two more specific views: e.g. R__pets_mammals_dogs_view.sql and R_pets_mammals_rodents_view.sql, respectively. This would also entail renaming/deleting the original R_pets_mammals_view.sql file.

What I would like to know is whether I can do this without messing up my schema versioning (possibly killing any hosted environments in the process)? Unfortunately, I could not find an answer to this in the Flyway docs.

P.S.: I understand that it's not a good idea to rename versioned migrations once they've been deployed to anything beyond the local environment. However, since repeatable migrations can be modified at will (and since they're executed last), I'm not sure whether they actually "count" in this context.

like image 449
Priidu Neemre Avatar asked Aug 14 '17 09:08

Priidu Neemre


People also ask

What is repeatable migration in Flyway?

Repeatable migrations have a description and a checksum, but no version. Instead of being run just once, they are (re-)applied every time their checksum changes. This is very useful for managing database objects whose definition can then simply be maintained in a single file in version control.

Which is better Flyway or Liquibase?

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.

Are Flyway migrations transactional?

Flyway runs each migration in a separate transaction. In case of failure this transaction is rolled back. Unfortunately, today only DB2, PostgreSQL, Derby, EnterpriseDB and to a certain extent SQL Server support DDL statements inside a transaction.


1 Answers

From a technical point of view, you can add, remove and rename repeatable migrations as you like. Flyway will not do anything with removed repeatable migrations. These migrations will also remain in the schema_version table. So you can still track which repeatable migrations were executed on your schema even if they have been removed.

In your example, where you delete the R__pets_mammals_view.sql and add two other views, the "mammals" view will just remain on your schema and you might drop it via a versioned migration (or manually).

like image 66
Stefan Ferstl Avatar answered Oct 01 '22 03:10

Stefan Ferstl