gitsqlitegithooks

Git hook for diff sqlite table


I have a Sqlite db in a Git repository. Today I wanted to do a diff of a view in two different commits. I did it this way:

$ sqlite3 -list file.sqlite "SELECT * FROM contact_list_detailed" >/tmp/newlist
$ git checkout 51c24d13c file.sqlite
$ sqlite3 -list file.sqlite "SELECT * FROM contact_list_detailed" >/tmp/oldlist
$ git checkout -- file.sqlite
$ diff /tmp/oldlist /tmp/newlist

It works and I could script it if I want. But are there any "nice" ways of doing this with hooks?


Solution

  • You would use HEAD and HEAD^ to access the previous and current revisions; see git post-commit hook - script on committed files for an example.

    Use git show to extract files to a temporary directory without overwriting the working copy.


    I wouldn't store binary files in git unless absolutely necessary. You can avoid many hassles if you create a text file of SQL commands with sqlite3 file.sqlite .dump and put that into git, having the binary database only as a generated file. (But then you have to care about regenerating the SQL file when necessary.)