Created
September 5, 2013 09:38
-
-
Save rzymek/6448035 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package config | |
import com.googlecode.flyway.core.Flyway | |
import java.util.logging.Logger | |
import javax.annotation.PostConstruct | |
import javax.annotation.Resource | |
import javax.ejb.EJBException | |
import javax.ejb.Singleton | |
import javax.ejb.Startup | |
import javax.ejb.TransactionManagement | |
import javax.ejb.TransactionManagementType | |
import javax.sql.DataSource | |
/** | |
* http://www.hascode.com/2013/04/easy-database-migrations-using-flyway-java-ee-6-and-glassfish/#Adding_Flyway_Database_Migrations | |
*/ | |
@Singleton @Startup | |
@TransactionManagement(value=TransactionManagementType.BEAN) | |
class JeeDbMigrator { | |
static val log = Logger.getLogger(typeof(JeeDbMigrator).name) | |
@Resource(name='java:jboss/datasources/ds') | |
var DataSource dataSource | |
@PostConstruct | |
def void onStartup() { | |
if (dataSource === null) { | |
throw new EJBException('no datasource found to execute the db migrations!'); | |
} | |
val flyway = new Flyway(); | |
flyway.cleanOnValidationError = true | |
flyway.initOnMigrate =true | |
flyway.dataSource = dataSource | |
flyway.info.all.forEach[ | |
log.info('''migrate task: «it.version»: "«it.description»" («it.script»)''') | |
] | |
flyway.migrate | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment