Forked from jeremyjarrell/Prefix migrations with timestamp Groovy task
Last active
August 29, 2015 14:22
-
-
Save mcai4gl2/35e8a2ff3d7f2faaa50b 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
task prefixNewMigrations { | |
fileTree(dir: 'dev/src/db/listhub').exclude({ isFilePrefixed(it.file) }).each { file -> | |
doLast { | |
def timestamp = new Date().format('yyyyMMddHHmmssSSS', TimeZone.getTimeZone('GMT')) | |
println "Renaming $file.name to ${timestamp}__$file.name" | |
file.renameTo("$file.parentFile.absolutePath$file.separator${timestamp}__$file.name") | |
// Sleep for a moment to avoid prefix conflicts when renaming multiple files | |
sleep(1*1000) | |
} | |
} | |
} | |
def isFilePrefixed(file) { | |
return (file.name ==~ '^\\d+__.*\\.sql\$') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment