Skip to content

Instantly share code, notes, and snippets.

@dtanner
Created December 16, 2012 22:54
Show Gist options
  • Save dtanner/4313893 to your computer and use it in GitHub Desktop.
Save dtanner/4313893 to your computer and use it in GitHub Desktop.
Example of a grails project using mybatis migrations in the Bootstrap.groovy, automatically nuking and paving the test databases.
def init = { servletContext ->
if (["test", "ci", "functional"].contains(Environment.current.name)) {
// bring some environments down to bare database. 20120609160926 is the base migration script's ID
// limitation: if we add development to this list and run the app in IDEA, it orphans the java processes
executeCommand ("${getMigrationCommand()} --env=${Environment.current.name} version 20120609160926", new File("./db"))
executeCommand ("${getMigrationCommand()} --env=${Environment.current.name} up", new File("./db"))
}
// other init operations...
}
String getMigrationCommand() {
return System.properties['os.name'].toLowerCase().contains('windows') ? "bin/migrate.cmd" : "bin/migrate"
}
void executeCommand(String command, File workingDirectory) {
println "Executing ${command}"
def sout = new StringBuffer()
def serr = new StringBuffer()
def proc = command.execute(null, workingDirectory)
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(10000)
if (sout)
println "sout: ${sout}"
if (serr)
println "serr: ${serr}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment