Skip to content

Instantly share code, notes, and snippets.

@mithereal
Last active April 14, 2021 00:12

Revisions

  1. mithereal revised this gist Nov 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-precommit-hook-mysqldump
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ else
    echo "schema committed"
    fi
    else
    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME > $NEW
    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction --no-data > $NEW
    git add $NEW
    echo "schema committed"
    fi
  2. mithereal revised this gist Nov 17, 2015. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions Git-precommit-hook-mysqldump
    Original file line number Diff line number Diff line change
    @@ -11,22 +11,22 @@ OLD=$NEW.old

    DIR=$(pwd)
    cd $GITREPO

    if [ -f "$NEW" ]
    then
    mv $NEW $OLD

    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction > $NEW

    # NOTE : ignore .old
    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction --no-data > $NEW

    if cmp -s $OLD $NEW; then
    echo Same
    echo Databases are the Same
    else
    echo Differ
    echo changes detected in database schema
    git add $NEW
    git commit $NEW -m "$DBNAME DB update"
    echo "schema+data committed"

    git push # assuming you have a remote to push to
    echo "schema+data pushed"
    echo "schema committed"
    fi
    else
    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME > $NEW
    git add $NEW
    echo "schema committed"
    fi
    cd $DIR
  3. @wilcollins wilcollins revised this gist Jun 22, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Git-precommit-hook-mysqldump
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,13 @@ mv $NEW $OLD

    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction > $NEW

    # NOTE : the new schema.sql file & location need to be added to your GIT repo & ignore .old
    # NOTE : ignore .old

    if cmp -s $OLD $NEW; then
    echo Same
    else
    echo Differ
    git add $NEW
    git commit $NEW -m "$DBNAME DB update"
    echo "schema+data committed"

  4. @wilcollins wilcollins created this gist Jun 22, 2015.
    31 changes: 31 additions & 0 deletions Git-precommit-hook-mysqldump
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/bash -e
    # -e means exit if any command fails
    DBHOST=address.to.your.server
    DBUSER=username
    DBPASS=password # do this in a more secure fashion
    DBNAME=DBNAME
    GITREPO=/where/is/your/repo
    DUMP=$GITREPO/where/you/store/dumps
    NEW=$DUMP/schema.sql
    OLD=$NEW.old

    DIR=$(pwd)
    cd $GITREPO

    mv $NEW $OLD

    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME --skip-dump-date --single-transaction > $NEW

    # NOTE : the new schema.sql file & location need to be added to your GIT repo & ignore .old

    if cmp -s $OLD $NEW; then
    echo Same
    else
    echo Differ
    git commit $NEW -m "$DBNAME DB update"
    echo "schema+data committed"

    git push # assuming you have a remote to push to
    echo "schema+data pushed"
    fi
    cd $DIR