Using Git to Track DB Schema Changes with Git Hook
Jan 28, 2010 · 2 minute readCategory: git
This is post is now quite old and the the information it contains may be out of date or innacurate.
If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub
Go to your project folder and into the hidden .git folder, then a sub folder in there called hooks
cd .git/hooks
Create a file called pre-commit and open it in vim (or whatever text editor you like)
vim pre-commit
Add a mysql dump command to that file and save it ```
#!/bin/sh mysqldump -u DBUSER -pDBPASSWORD DATABASE –no-data=true > SQLVersionControl/vc.sql git add SQLVersionControl/vc.sql exit 0
(note this assumes you have a folder called SQLVersionControl in the root of your project. If you don't just create it.)
No without any further effort, you will update the schema file on every commit.
eg
git commit -am ‘this commit will include a mysql schema dump that has been run just before the commit - sweet :)’
```