Skip to content

Instantly share code, notes, and snippets.

@xxswingxx
Last active February 26, 2016 14:56
Show Gist options
  • Save xxswingxx/534839a9a21497bca3d4 to your computer and use it in GitHub Desktop.
Save xxswingxx/534839a9a21497bca3d4 to your computer and use it in GitHub Desktop.
Reset database after doing a checkout
#! /bin/sh
# Reset the database only if the previous branch and the current one have different schemas
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
if git diff `git rev-parse --abbrev-ref HEAD` @{-1} | grep "ActiveRecord::Schema.define(version: "; then
rake db:reset
else
echo "Skipping db reset: schema changes not found"
fi
@xxswingxx
Copy link
Author

This git hook allows to automatically reload the schema if the previous branch and the current one have different schema.rb files

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