Where does one put their Flyway migration files in a Vaadin 7 project created with the multi-module Maven archetype?
I will activate the migrations through the Java API in Flyway (not the command-line).
Might the solution for Vaadin work in any Java Servlet based web app project running in a web container such as Tomcat or Jetty?
Update
As of 2018-06, the Vaadin 8 archetype named
vaadin-archetype-application-multimodule
no longer provides an existing folders forWeb Pages
,META-INF
, andWEB-INF
as seen below in the Previously section. TheWEB-INF
andclasses
folders are created dynamically at build-time.Look to your
foobar-ui
module’s folder. Locate thesrc
>main
>resources
folder hierarchy. Add the nested foldersdb
&migration
following Flyway conventions.If we explode the resulting WAR file, we see that during the build process a
WEB-INF
folder was created, with a nestedclasses
folder, where we find ourdb
>migration
folder containing our first added SQL script file.Previously
Prior versions of the multi-module Maven archetype provided by Vaadin Ltd. used a different arrangement than that seen above.
Default folder nested in
WEB-INF
Flyway by default will find your .sql migration files if located in this exact folder path:
In your project, in the
-ui
module, locate theWEB-INF
folder. The Java Servlet spec defines this special folder as a place to store class files, .jar files, and other resources that should be made available to your servlets but always shield from outside, never available as a public part of the web app.That
WEB-INF
folder will containclasses
&lib
folder. You may not yet see these two folders in your IDE’s project view. These two special folders are created during the compiling and build process. The first houses individual .class files for your web app, whilelib
houses .jar files. Again, all this is defined by the Servlet spec.The Trick: Manually create the
classes
folder in your IDE if not shown. What you place inside will be automatically merged with the other content destined for theclasses
folder when created during the compiling/build process.Flyway by default looks on the classpath for a hierarchy named exactly
/db/migration/
. So create folders by these names inside thatclasses
folder you added toWEB-INF
. Now when Flyway looks on the classpath at runtime, Flyway will look in/WEB-INF/classes
and find/db/migration/
.So in your IDE:
classes
in your project’sWEB-INF
.db
.migration
.migration
folder.Run your Flyway migration. Here is example code using the H2 Database called in the
contextInitialized
method of my class implementing[ServletContextListener][3]
.Caveat
Take this Answer with a grain of salt as I am new to Flyway. But this is working for me using Flyway 4, Vaadin 7.6.4, Java 1.8 Update 77, NetBeans 8.1, Apache Tomcat 8.0.27, Mac OS X El Capitan.