Created
June 2, 2017 15:54
-
-
Save screamingjungle/8db2cd330b06b8d4a44234105f52acf1 to your computer and use it in GitHub Desktop.
GIT MySQL DB Schema Pre-Commit-Hook
This file contains 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 -e | |
# -e means exit if any command fails | |
DBHOST="localhost" | |
DBUSER="root" | |
DBPASS="passwd" | |
DBNAME="test" | |
SCHEMAPATH="__sql" | |
MYSQLBINPATH="" | |
# leave blank if it is in PATH. | |
#MYSQLBINPATH="/Application/XAMPP/xamppfiles/bin" ## MACOS | |
#MYSQLBINPATH="C:/xampp/mysql/bin" ## WINDOWS | |
if [ ! -d "$SCHEMAPATH" ]; then | |
mkdir $SCHEMAPATH | |
fi | |
$MYSQLBINPATH/mysqldump -h $DBHOST -u $DBUSER --password=$DBPASS $DBNAME --no-data=true > $SCHEMAPATH/$DBNAME_schema.sql | |
git add $SCHEMAPATH/$DBNAME_schema.sql | |
## uncomment this to use as a commit script | |
# git commit -m "$DBNAME schema version $(`date`)" | |
# git push # assuming you have a remote to push to | |
echo 'Exported and added Database to commit' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment