Forked from nuclearsandwich/mysqldump_pre_commit_hook.bash
Created
August 7, 2018 13:22
-
-
Save aslamdoctor/57053921ec9146e4845005a87a5b320c to your computer and use it in GitHub Desktop.
A pre-commit hook for git which dumps and adds a mysql database to the repository just before commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Pre-commit hook to make a mysql dump right before committing and add it to the commit. | |
# | |
## Change the following values to suit your local setup. | |
# The name of a database user with read access to the database. | |
DBUSER=root | |
# The password associated with the above user. Leave commented if none. | |
#DBPASS=seekrit | |
# The database associated with this repository. | |
DBNAME=dplay | |
# The path relative to the repository root in which to store the sql dump. | |
DBPATH=schema | |
[[ -d schema ]] || mkdir schema | |
if [ -t $DBPASS ]; then | |
mysqldump -u $DBUSER -p$DBPASS $DBNAME > $DBPATH/$DBNAME.sql | |
else | |
mysqldump -u $DBUSER $DBNAME > $DBPATH/$DBNAME.sql | |
fi | |
git add $DBPATH/$DBNAME.sql | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment