Skip to content

Instantly share code, notes, and snippets.

@hank-cp
Created June 27, 2019 02:44
Show Gist options
  • Save hank-cp/9c3eaa669554e64ef8731c708b2657de to your computer and use it in GitHub Desktop.
Save hank-cp/9c3eaa669554e64ef8731c708b2657de to your computer and use it in GitHub Desktop.
Gradle script snippet for flyway to load config from Spring Boot
def getAppProperties() {
// from yaml
return new org.yaml.snakeyaml.Yaml().load(
file("${project.buildDir}/resources/main/application.yml").newDataInputStream())
// from properties
// Properties appProp = new Properties()
// appProp.load(file("$buildDir/resources/main/application.properties").newDataInputStream())
// return appProp;
}
task("doMigration") {
dependsOn processResources
doFirst {
def appProp = getAppProperties()
def dbUrl = appProp.spring.datasource.url
println ">>>>>>>>>>> doing db_migration on $dbUrl"
flyway {
url = dbUrl
user = appProp.spring.datasource.username
password = appProp.spring.datasource.password
driver = appProp.spring.datasource["driver-class-name"]
schemas = ["pf4j"]
baselineOnMigrate = true
table = "_db_migration"
locations = ["filesystem:$buildDir/resources/main/db_migration"]
}
}
finalizedBy flywayMigrate, flywayInfo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment