Tracking SQL changes with SVN Post Commit Hook
One of the more annoying features of doing web development is tracking changes made to the database alongside revisions to the code that runs the site. I’ve been getting into subversion post-commit hooks lately, and my currently solution to this problem is to create a hook which dumps the database structure and commits it to a git repository, with a comment which can be used to link that database structure to the revision in subversion it corresponds to. You can then use git to generate patch files that are easy to follow for making updates to database structure.
my post commit hook looks like this
#!/bin/sh
mysqldump --defaults-extra-file=/home/deepwinter/svn/newframework/hooks/db.cnf -d -h dev2.madeofpeople.org -u madeofpeople11 newframework > /home/deepwinter/sites_sql/newframework/dump.sql
cd /home/deepwinter/sites_sql/newframework/
MESSAGE="SQL committed for build revision $2 in $1"
git commit -a -m"$MESSAGE"
post-commit itself, the file called by subversion looks like this:
#!/bin/sh
REPOS="$1"
REV="$2"
/home/deepwinter/svn/newframework/hooks/sqldump.sh "$REPOS" "$REV"
A good further development of this will be a way for patches to generate database structure update code automatically off a patch.
Tags: svn git hooks sql