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.
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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With