Skip to content

Instantly share code, notes, and snippets.

@manniru
Forked from anish137i/GIT DB Export Hook
Created December 11, 2022 11:58
Show Gist options
  • Select an option

  • Save manniru/25a44a113cc50735e2362608ae9c943d to your computer and use it in GitHub Desktop.

Select an option

Save manniru/25a44a113cc50735e2362608ae9c943d 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment