Created
January 18, 2024 08:21
-
-
Save plfort/2c218281f6426f58aa11e24a57271385 to your computer and use it in GitHub Desktop.
Symfony/Doctrine - Switch git branch while taking account of Doctrine migrations
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 -eu | |
export XDEBUG_MODE=off | |
NEW_BRANCH=$1 | |
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
MIGRATIONS_DIR=migrations | |
MIGRATIONS_NAMESPACE=DoctrineMigrations\ | |
echo "Switching to $1" | |
LAST_COMMON_MIGRATION_FILE=`comm -12 <(git ls-tree -r --name-only $CURRENT_BRANCH $MIGRATIONS_DIR|sort) <(git ls-tree -r --name-only $NEW_BRANCH $MIGRATIONS_DIR|sort) |tail -1` | |
TARGET_MIGRATION_VERSION=$MIGRATIONS_NAMESPACE\\`echo $LAST_COMMON_MIGRATION_FILE|sed "s/$MIGRATIONS_DIR\/\(.*\)\.php/\1/"` | |
echo "Last common migration file between current branch ($CURRENT_BRANCH) and target branch ($NEW_BRANCH) is " | |
echo $LAST_COMMON_MIGRATION_FILE | |
#Rollback to the last migration file common to both branches | |
php bin/console d:m:m $TARGET_MIGRATION_VERSION -n | |
php bin/console d:m:m $TARGET_MIGRATION_VERSION --env=test -n | |
git switch $NEW_BRANCH | |
#Sync js deps | |
npm install | |
#Sync php deps, cache & clear | |
composer install | |
#Run new branch migrations | |
php bin/console d:m:m -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: