Owen Ou
Owen Ou

Reputation: 31

Running DB migration for a Java app

What's the recommended way to run DB migration for a Java app on Heroku? Any best practices? Like tool etc.

Upvotes: 2

Views: 566

Answers (1)

bimsapi
bimsapi

Reputation: 5065

A late answer, but if you are not using Play! (which has a built-in solution called "Evolutions"), I suggest looking at liquibase (http://www.liquibase.org/). Conceptually it works like Play! evolutions or Rails migrations - modularized DDL/DML steps that are executed in order and tracked over time, so that an active history of the db is maintained. The schema definitions are defined via a pretty straightforward XML format, with the ability to define SQL statements, rollback steps, etc.

It can be wired into the Spring application context to execute on server start, as well, which makes it a perfect fit for Heroku. For example, the snippet in context.xml will trigger database upgrade analysis when Spring starts:

<bean class="liquibase.integration.spring.SpringLiquibase" id="liquibase" lazy-init="false">
  <property name="dataSource" ref="dataSource"/>
  <property name="changeLog" value="classpath:META-INF/schema/db-changelog-master.xml"/>
</bean>

Upvotes: 3

Related Questions