3
votes

We are using Flyway for migration of our DB which and we literally have thousands of schemas (a.k.a Silos).

When we deploy a new build, the DB migration may take 10 minutes even if there is no migration needed for the software build.

I wonder if we could configure Flyway to do a lazy DB migration: check each the schema_version table for all the schemas, if latest DB version in the table is equal to that of the current software build, then there is no need to do anything; otherwise, if db version in software builder is newer, just do the necessary migration starting from latest version in the table.

If we can do the above, the migration time could shrink from 10 minutes to a few seconds.

Could anyone shed any light on how to do this? Thanks!

1
I don't really understand how that would be different than what FlywayDB does: it does check the current version, and only updates it if needed. - JB Nizet
@JBNizet It does that but it also a ton of other things for each of the thousand schemas even if there is no need to do any migration work. I was able to snoop the traffic between our web server and DB and saw it. I think there has to be a method to make the db migration lazy, if there is no need to migrate, then do nothing! - pktCoder

1 Answers

0
votes

As stated by JB Nizet, Flyway checks the current version, and does not perform any update unless required.

However, if your goal is getting rid of this check because it takes time, you could maybe switch to Java-based migrations instead of SQL-based ones, because unlike the latter ones, Java migrations do not have checksums, and this is were you might reduce some execution time; still has to be tested though.

This is from the official doc in this matter:

Unlike SQL migrations, Java migrations by default do not have a checksum and therefore do not participate in the change detection of Flyway’s validation. This can be remedied by implementing the MigrationChecksumProvider interface.

I do not have an idea if this will reduce execution time, but it may be worth testing at least.