Comment #10 on issue 460 by
virid...@gmail.com: Allow multiple scripts per
version
https://code.google.com/p/flyway/issues/detail?id=460
The concept is simple:
* Some packages have associated database components. (We use
package-by-feature, which I warmly recommend.)
* We chose to mark all such packages by creating, in each of them, a
subclass of a custom abstract class 'Module'. This allows us to give nice
display names to the modules as well. We use a simple library to collect
all the modules from the classpath. I don't remember the name of the
library, and I'm no longer using Java, but if you can name a few simple
libraries I may be able to recognize it.
* Each module instantiates a Flyway instance bound to its package and can
be asked questions about its state: which versions are not up-to-date, etc.
* We also allow for modules to depend on other modules (by naming a list of
module names and versions). The resulting dependency graph had better be a
DAG, and we must run the updates in a topological sorting order of the
graph.
* (Nice to have) We put all the modules under a single umbrella object,
called in our case an Application, cause we don't like dangling lists. We
can then invoke a single "update" on the Application to do a topological
sort and run module updates. To support this, Modules have
an "updateToVersion" methods.
* (Nice to have) Finally, we have a UI control (we used Vaadin) that can
display the status of the modules and allows for an update to be triggered.
* We used Spring application context reloading to load only a very basic
Spring application context (we called it a bootstrap context) in memory on
startup, and this context checked if the database was up to date. If up to
date, it would load the full context, otherwise it would not load anything
and it would only render the UI control I mentioned above (to admins; yes,
it had enough in it to allow signing in) to force the user to update the
database. ( Some hints here:
http://stackoverflow.com/questions/16464420/why-spring-context-not-gracefully-closed?noredirect=1#comment25289168_16464420
)
Notes:
* You can reuse versions between modules.
* Flyway will introspect a package and all subpackages. This means that
packages with modules cannot be nested. This wasn't much of a problem for
us in practice.