Skip to content

feat: Add migration workflow #14

feat: Add migration workflow

feat: Add migration workflow #14

Workflow file for this run

name: Dev Database Migrations
on:
push:
branches:
- dev
jobs:
migrate-dev:
name: Migrate Dev Database
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: pdo, mysql
- name: Install Composer dependencies
run: composer install --no-interaction --no-dev --prefer-dist
- name: Copy .env.example to .env
run: cp .env.example .env
- name: Set up environment variables for dev
run: |
echo "DB_CONNECTION=mysql" >> .env
echo "DB_HOST=localhsot" >> .env # Use service name
echo "DB_PORT=3306" >> .env
echo "DB_DATABASE=laravel_gh_ost" >> .env
echo "DB_USERNAME=root" >> .env
echo "DB_PASSWORD=" >> .env
- name: Install gh-ost
run: |
wget https://github.com/github/gh-ost/releases/download/v1.1.7/gh-ost-binary-linux-amd64-20241219160321.tar.gz -O gh-ost
chmod +x gh-ost
sudo mv gh-ost /usr/local/bin/
- name: Check for gh-ost migrations and run
id: check-gh-ost
run: |
HAS_GHOST=false
for file in $(find database/migrations -name "*.php"); do
if grep -q "gh-ost:" "$file"; then
HAS_GHOST=true
echo "::set-output name=has_ghost::true"
GHOST_COMMAND=$(grep "gh-ost:" "$file" | cut -d':' -f2 | xargs)
echo "Running gh-ost command: $GHOST_COMMAND"
gh-ost $GHOST_COMMAND --host mysql --user your_dev_user --password your_dev_password --database your_dev_database
fi
done
if [[ "$HAS_GHOST" == "false" ]]; then
echo "No gh-ost migrations found."
fi
- name: Run regular migrations if no ghost migration or ghost migration complete
if: steps.check-gh-ost.outputs.has_ghost != 'true'
run: php artisan migrate --force