Created
December 16, 2012 22:54
-
-
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.
This file contains 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
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