Skip to content

Instantly share code, notes, and snippets.

@wesamly
Created April 14, 2015 10:17
Show Gist options
  • Save wesamly/b5443ee183d670a6f3cd to your computer and use it in GitHub Desktop.
Save wesamly/b5443ee183d670a6f3cd to your computer and use it in GitHub Desktop.
Git mysql schema on project commits
#!/bin/sh
#path to script: /path_to_git_repo/.git/hooks/pre-commit
#DB Details
DBHOST=localhost
DBUSER=myuser
DBPASS=mypass
DBNAME=test_dbname
#Path to mysqldump
MYSQLDUMP=/Applications/MAMP/Library/bin/mysqldump
#Path to repository
GITREPO=/Applications/MAMP/htdocs/gitwithdb
cd $GITREPO
#Where to save the sql file
mkdir -p $GITREPO/sqlSchema/
$MYSQLDUMP --compact --user=$DBUSER -p$DBPASS -d $DBNAME > $GITREPO/sqlSchema/schema.sql
git add sqlSchema/schema.sql
@wesamly
Copy link
Author

wesamly commented Apr 14, 2015

Applied from this StackOverflow answer: http://stackoverflow.com/a/5518976/249645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment