Skip to content

Instantly share code, notes, and snippets.

  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A Groovy task that prefixes new SQL migration files with a timestamp precise to milliseconds. The following usage will add a prefix to any SQL file in a hardcoded directory that does not begin with an number and double leading underscore: $ gradle prefixNewMigrations
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 $ to ${timestamp}__$"
// Sleep for a moment to avoid prefix conflicts when renaming multiple files
def isFilePrefixed(file) {
return ( ==~ '^\\d+__.*\\.sql\$')
Copy link

Thanks for sharing this!
I had to do something similar, but I had to plug it into a maven build, so I could only use pure Groovy. You can find this Gist here:

Copy link

Thanks for sharing!
Here is a version for SBT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment