views:

384

answers:

2

I've started using Mercurial for version-controlling my Drupal project source files (I'm both a VCS and Mercurial newbie). However, the database is still "version-controlled" using a directory of dated .sql.gz files.

What I want is to have a single database dump file somewhere within my repository, that would be overwritten with a current dump when the database changes, and imported into the database when I want to rollback to another version.

I did it manually, and it worked. But what I'd really like is something that does the dumping/loading automatically on each commit/update. I'd really prefer that it would hook into Mercurial than being something external like a makefile that first dumps the database and then commits, since I like working with TortoiseHg's tools, and I don't feel like having another script to run.

Now, it seems that something like an mysql .... < dumpfile.sql on an update hook would be an easy way to load the database dump after each update. But what about the automatic dumping?

There was a similar question about SVN's pre-commit hook, and the accepted answer was that it's probably a bad idea. Does it apply to Mercurial? Maybe another hook (prechangegroup?) would work?

EDIT:

I should point out that I'm using it by myself, on my local machine. It shouldn't scale beyond a single user.

A: 

Seems like this is more of an update operation. I presume you were working on the database, deliberately choose to export the sql schema, and have committed. The problem comes when someone else updates from you (or some other location) or you update from them. Mercurial has a hook for updates.

An alternative would be to create your own mercurial plugin/extension that can actually talk directory to your database (mysql) and potentially provide more useful information. This all depends on you knowing a bit of python.

basszero
I should've added that it's a simple single-developer setup. Nobody would be updating from me or vise-versa (I've added it now). Also - I would like to import dumps on updates, but also EXPORT dumps on commits, and there lies the difficulty (I think?).As for the mercurial plugin/extension - I do know some python (but not Mercurial's API). What can it give me that mysqldump/mysql can't?
Eli Krupitsky
+3  A: 

It should be fine to dump the database with a pre-commit hook. Just be careful not to use a precommit hook, since it's a different thing (runs inside the transaction).

In general, for each command (update, commit, etc.) the pre-<command> hook is run before the command is executed.

tonfa
Great! It works via hg commit just fine. But... if I use tortoisehg, I have to commit twice (once for the source files, and once more for the newly-created database dump)... Would you happen to know how to get around that?
Eli Krupitsky
Hum it means that THG restricts the files to the files it thinks were changed. I don't know THG well enough to get around that (maybe ask in THG mailing-list).
tonfa
Thanks anyway. At most, I can use the command line for commits. It's not so bad.
Eli Krupitsky