Of databases and repositories

Posted by on October 6, 2008

One thing that most programmers will cringe at, is the thought of placing a database into a version control repository such as subversion or mercurial. Now I know that many of have done this for various reasons (I know I am guilty of it myself).

The point of this post is to show how this can be made a little nicer under mercurial using encode/decode filters. With a carefully constructed set of filters, you are able to actually perform text diffs and make sane merges between repositories. All you have to do is drop the following into your hgrc file (either the one in your project or ~/.hgrc):

[encode]
data.db = tempfile: sqlite3 INFILE .dump > OUTFILE

[decode]
data.db = tempfile: sqlite3 OUTFILE '.read INFILE'

This requires that you have the sqlite3 binary installed, otherwise you will end up with a data.db file containing the raw sql used to generate the database.

Comments

Respond | Trackback

  1. Interesting post! I can see a number of uses for this.

    All to often programmers don’t use source control.
    When they do, if they are working on a project which has a strong dependency on a database schema they often leave that out of source control leaving you with a hell of a time figuring out your schema if you want to go back in time and play with some older revisions.

Comments

Comments: