Posts Tagged ‘ant’
* A Poor Man’s Migration
Posted on November 28th, 2008 by Dave Johnson. Filed under programming.
Working on a project with multiple people, multiple databases and many tests for each of those people and databases makes managing schemas a pretty big nightmare as many of you can probably atest to even more than I. If you are all working on a single rails app rails migrations make things much better but even then there are still cases that make it painful like when schema changes break all your tests. Since half of the application that I am currently working on is not even a rails app it means that we need some other way of managing that other database schema. To make things worse our test cases are rather specific and it may end up that a lof the tests have very different test data sets so using one set of rails fixtures also doesn’t cut it.
I looked around a bit for other migration tools and did find Migrate4j which looked OK but the idea of learning another abstraction ontop of SQL did not really sit well with me. I like writing migrations in SQL since you know exactly what you are getting and there are no problems with things like setting a field as MEDIUMTEXT type that doesn’t exist in your abstraction language.
Anyhow, I cobbled something together in the form of an ANT script in a few hours that resembles a generic migration system that will take a SQL file containing your migration (add_column_to_table.up.sql and corresponding down file) and then apply it to schema SQL file as well as data SQL files that are used for any tests.
<target name="db.dump.schema">
<exec executable="cmd" os="Windows XP,Windows Vista>
<arg value="/c" />
<arg value="mysqldump -u ${db.user} --password="${db.password}"
--databases ${db.name} --add-drop-database -R --no-data
--skip-set-charset --default-character-set=utf8 > ${sql.name}" />
</exec>
</target>
Recent Posts
- BlackBerry JavaScript Oddities
- JavaScript Event Merging
- Smart Grid Utilities
- PhoneGap Desktop
- Crockford Facts
Archives
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- January 2010
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
