Skip to content

Instantly share code, notes, and snippets.

@anish137i
Forked from glauckner/GIT DB Export Hook
Last active December 11, 2022 11:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anish137i/695ea891ce213e7feded9e25c6f51c60 to your computer and use it in GitHub Desktop.
Save anish137i/695ea891ce213e7feded9e25c6f51c60 to your computer and use it in GitHub Desktop.
Git pre commit hook to export database
#!/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
@anish137i
Copy link
Author

Updated Git Hook for OS Base execution to work with multiple OS environment.

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