Skip to content

Instantly share code, notes, and snippets.

@stilliard
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stilliard/c2cf024c9552415b1b49 to your computer and use it in GitHub Desktop.
Save stilliard/c2cf024c9552415b1b49 to your computer and use it in GitHub Desktop.
Git checkout and auto ruckusing migrations and composer composer setup!
git config alias.migrate-to '!f() { make checkout BRANCH=$1; }; f'
#
# Chekout branch in git and run migrations down and up
#
checkout:
ifeq ($(BRANCH),)
@echo "\nPlease specify branch, e.g. make checkout BRANCH=master\n"
else
$(eval old_id = $(shell git diff $(BRANCH) --name-status -- migrations | grep '^A' | head -n1 | grep -oP '(\d+)(?=_)'))
@echo "Checking for any migrations needed to be rolled back"
@if [[ "$(old_id)" != "" ]]; then \
echo "Migrating down..."; \
php vendor/bin/ruckus.php db:migrate VERSION=$$(ls migrations/default/ | grep -B 1 $(old_id) | head -n 1 | grep -oP '(\d+)(?=_)'); \
fi;
git checkout $(BRANCH)
make update --no-print-directory
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment