Preliminary and Post-Migration Scenarios for Flyway

I am looking for a way to execute a hook script before and after the migration. I have a bunch of views and stored procedures and would like this process to be as follows:

  • Discard all views and stored procedures.
  • Start the migration.
  • Rebuild views and stored procedures.

This ensures that any change to the schema is reflected in the associated views and stored procedures. Steps (1) and (3) will be bash scripts.

Is this possible in flight?

+6
source share
2 answers

Update 2014-04-29: Now it is possible with Flyway 3.0 by implementing the FlywayCallback interface.

Previous answer

Short answer: no, not at this moment.

Here's why: I thought about it, and also laid the original design for Flyway. The more I thought about this aspect, the more it became clear to me that these pre and post scenarios are also an integral part of migration, or at least something that migration cannot handle if it wants to be successful. Therefore, I would recommend either:

  • Combine 1, 2, and 3 in one migration
  • You have 3 separate migrations x.1 (drop views), x.2 (actual migration), x.3 (rebuild)

You might even want x.1 and x.3 to call stored procedures that do the work for you to avoid code duplication between migrations if these steps are repeated.

If Flyway takes care of making all the changes in the database structure, it all becomes simpler, avoiding the combination of different technologies.

+5
source

To expand on Axel's answer : sql script callbacks simply mean that beforeMigrate.sql (for example, this is one keyword among others) in the directory containing the migrations, and Flyway will execute beforeMigrate.sql before the other migration scripts. Even before blocking schema_version .

Other callback names (for example, afterMigrate ) are listed in the documentation for callbacks .

+3
source

Source: https://habr.com/ru/post/896067/


All Articles