Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Mercurial hooks to create/load database dumps for versioning

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.

like image 282
Eli Krupitsky Avatar asked Sep 19 '09 18:09

Eli Krupitsky


2 Answers

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.

like image 182
tonfa Avatar answered Oct 23 '22 14:10

tonfa


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.

like image 43
basszero Avatar answered Oct 23 '22 15:10

basszero