Created
October 30, 2013 14:48
-
-
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.
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
<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> |
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
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