Last active
June 16, 2022 05:20
-
-
Save cm-igarashi-ryosuke/9b10e9759a2cc1a1b95cdd82d5f4edb0 to your computer and use it in GitHub Desktop.
db:migrateをロールバックしながらブランチを切り替えるスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
RAILS_COMMAND="docker compose exec -T backend rails" | |
branch_name=$1 | |
if [ -z "$branch_name" ]; then | |
echo "Please specify branch name." | |
exit 0; | |
fi | |
if [ -z "`git branch --list $branch_name`" ]; then | |
echo "Branch does not exist" | |
exit 0; | |
fi | |
echo "*** Running: db:migrate:down" | |
versions=`git diff develop --name-status | grep -E "A\\tbackend/db/migrate" | sed -e "s/^.*\([0-9]\{14\}\).*$/\1/" | sort -r` | |
for version in ${versions[@]} | |
do | |
eval $RAILS_COMMAND db:migrate:down VERSION=$version | |
done | |
git checkout backend/db/schema.rb | |
echo "*** Switching from current branch to: $branch_name" | |
git checkout $branch_name | |
echo "*** Running: db:migrate" | |
eval $RAILS_COMMAND db:migrate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こちらのPythonのスクリプトをbashで書き直したものです。