Forked from jeremyjarrell/Prefix migrations with timestamp Ant task
Created
June 17, 2014 09:56
-
-
Save timoyuen/42bc6219f1b68832ebe3 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
<project name="migrations"> | |
<target name="prefix-new-migrations"> | |
<foreach target="rename-file" param="the-file"> | |
<path> | |
<!-- The hardcoded directory containing the migrations --> | |
<fileset dir="./src/db/migrations" casesensitive="no" includes="*.sql"> | |
<!-- Exclude any migration files which have already been prefixed --> | |
<not> | |
<filename regex="\d+__.*" casesensitive="true"/> | |
</not> | |
</fileset> | |
</path> | |
</foreach> | |
</target> | |
<target name="rename-file"> | |
<tstamp> | |
<format property="time.stamp" pattern="yyyyMMddHHmmssSSS"/> | |
</tstamp> | |
<dirname property="dir.name" file="${the-file}"/> | |
<basename property="file.name" file="${the-file}"/> | |
<!-- Renames my_migration.sql to 20130704144750766__my_migration.sql --> | |
<move file="${the-file}" tofile="${dir.name}${file.separator}${time.stamp}__${file.name}"/> | |
<!-- Sleep to prevent prefix conflicts when renaming multiple files --> | |
<sleep seconds="1"/> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment