diff --git a/scripts/deploy/scripts/run_migrations.sh b/scripts/deploy/scripts/run_migrations.sh index f9a28ae0..94abb56d 100755 --- a/scripts/deploy/scripts/run_migrations.sh +++ b/scripts/deploy/scripts/run_migrations.sh @@ -15,17 +15,19 @@ if [[ "$TARGET" == "prod" ]]; then COMPOSE_FILE="docker-compose.prod.yml" ENV_FILE="--env-file .env.prod" WORK_DIR="cmc-sales-prod" + GO_SERVICE="cmc-prod-go" else COMPOSE_FILE="docker-compose.stg.yml" ENV_FILE="" WORK_DIR="cmc-sales-staging" + GO_SERVICE="cmc-stg-go" fi echo "Running goose migrations for $TARGET environment..." SERVER="cmc" ssh $SERVER \ - "COMPOSE_FILE='$COMPOSE_FILE' ENV_FILE='$ENV_FILE' WORK_DIR='$WORK_DIR' bash -s" << 'ENDSSH' + "COMPOSE_FILE='$COMPOSE_FILE' ENV_FILE='$ENV_FILE' WORK_DIR='$WORK_DIR' GO_SERVICE='$GO_SERVICE' bash -s" << 'ENDSSH' set -e cd /home/cmc/$WORK_DIR echo "Running migrations in $WORK_DIR..." @@ -33,7 +35,7 @@ ssh $SERVER \ # Wait for Go service to be ready echo "Waiting for Go service to be ready..." for i in {1..30}; do - if docker compose $ENV_FILE -f "$COMPOSE_FILE" exec -T go test -f /app/go.mod 2>/dev/null; then + if docker compose $ENV_FILE -f "$COMPOSE_FILE" exec -T "$GO_SERVICE" test -f /app/go.mod 2>/dev/null; then echo "Go service is ready." break fi @@ -44,7 +46,7 @@ ssh $SERVER \ sleep 2 done - docker compose $ENV_FILE -f "$COMPOSE_FILE" exec -T go sh -c "cd /app && make migrate" + docker compose $ENV_FILE -f "$COMPOSE_FILE" exec -T "$GO_SERVICE" sh -c "cd /app && make migrate" echo "Migrations completed successfully." ENDSSH