Liquibase has a servlet option to initialize the database. http://liquibase.org/manual/servlet_listener
Is there an example of this for Flyway? Or, better yet a working servlet?
Liquibase has a servlet option to initialize the database. http://liquibase.org/manual/servlet_listener
Is there an example of this for Flyway? Or, better yet a working servlet?
What you really want, is to run flyway.migrate()
on startup. This can be accomplished through a variety of ways, Servlet Listeners being one of them.
There is no servlet listener included out of the box, but it's trivial to roll your own.
It should look something like this:
@WebListener
public class FlywayListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
Flyway flyway = new Flyway();
flyway.setDataSource(...);
flyway.migrate();
}
public void contextDestroyed(ServletContextEvent sce) {
}
}
A class implementing the ServletContextListener
interface is called before the first servlet (or filter) invocation and after the last. The @WebListener
annotation is one way to inform your Servlet container of your intended listener. For more info, see this Oracle Tutorial and search Stack Overflow.