drewrockshard
drewrockshard

Reputation: 2071

Git: Export MySQL database on commit?

Is there a way I can utilize git to export/download my MySQL development database that is utilized in my code on a commit or some other way through git so that whenever I clone my project, I always have a current copy of the database?

If not, I can always export the database, and add it to the source, I was just wondering if git had the capability of doing this almost like a hook.

Upvotes: 11

Views: 5764

Answers (1)

drewrockshard
drewrockshard

Reputation: 2071

I ended up using the git hooks as I anticipated. I created the pre-commit hook and added the following to it:

#!/bin/bash
DBUSER="sysbackup"
DBPASS="password"
DB="database-name"
SCHEMAPATH="DBSchema"

mysqldump -u $DBUSER -p$DBPASS $DB > $SCHEMAPATH/$DB.sql
git add $SCHEMAPATH/$DB.sql
exit 0

Upvotes: 18

Related Questions