Skip to content

Instantly share code, notes, and snippets.

@SlevinBE
Created October 30, 2013 14:48
Show Gist options
  • Save SlevinBE/7233913 to your computer and use it in GitHub Desktop.
Save SlevinBE/7233913 to your computer and use it in GitHub Desktop.
Based on Jeremy's Gradle task (see https://gist.github.com/jeremyjarrell/6083207), but in pure Groovy. Can be integrated into a Maven build.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${pom.basedir}/prefixNewMigrations.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
import static groovy.io.FileType.*
def incrementalScriptsDir = new File("src/main/dbscripts");
/**
* Traverses all files in the incremental directory, excluding the ones which already
* start with a number followed by an underscore.
* Each of these files will be renamed by prefixing them with a timestamp.
*/
incrementalScriptsDir.traverse(type: FILES, excludeNameFilter: ~/.+\d+_.*/) { file ->
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(1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment