-
-
Save anish137i/695ea891ce213e7feded9e25c6f51c60 to your computer and use it in GitHub Desktop.
Git pre commit hook to export database
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 | |
DBUSER="root" | |
DBPASS="" | |
DB="test" | |
SCHEMAPATH="__sql" | |
if [ ! -d "$SCHEMAPATH" ]; then | |
mkdir $SCHEMAPATH | |
if [ "$(uname)" == "Darwin" ]; then | |
/Application/XAMPP/xamppfiles/bin/mysqldump -u $DBUSER --password=$DBPASS $DB > $SCHEMAPATH/$DB.sql | |
git add $SCHEMAPATH/$DB.sql | |
echo 'Exported From MAC OS and added Database to commit' | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
# SQL Dump under GNU/Linux platform | |
mysqldump -u $DBUSER --password=$DBPASS $DB > $SCHEMAPATH/$DB.sql | |
git add $SCHEMAPATH/$DB.sql | |
echo 'Exported From Linux and added Database to commit' | |
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then | |
# SQL Dump under Windows NT platform | |
C:/xampp/mysql/bin/mysqldump -u $DBUSER --password=$DBPASS $DB > $SCHEMAPATH/$DB.sql | |
git add $SCHEMAPATH/$DB.sql | |
echo 'Exported From Windows and added Database to commit' | |
fi | |
exit | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated Git Hook for OS Base execution to work with multiple OS environment.