Skip to content

add: database schema dump action #1

add: database schema dump action

add: database schema dump action #1

Workflow file for this run

name: MySQL Schema Dump
on: [push, pull_request]
jobs:
schema-dump:
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: unit3d
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis:7.2.1
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP 8.4
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: curl, dom, gd, libxml, mbstring, zip, mysql, xml, intl, bcmath, redis-phpredis/phpredis@6.0.1
tools: composer:v2
coverage: none
env:
REDIS_CONFIGURE_OPTS: --enable-redis
- name: Configure Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install Composer Dependencies
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader
- name: Prepare The Laravel Environment
run: cp .env.example .env
- name: Generate Application Key
run: php artisan key:generate
- name: Run Migrations
run: php artisan migrate --force
env:
DB_CONNECTION: mysql
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USERNAME: root
DB_DATABASE: unit3d
DB_PASSWORD: null
- name: Generate Schema Dump
run: php artisan schema:dump --database=mysql --path=database/schema/mysql-schema-new.sql
env:
DB_CONNECTION: mysql
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USERNAME: root
DB_DATABASE: unit3d
DB_PASSWORD: null
- name: Check if schema has changed
id: diff
run: |
if [ -f database/schema/mysql-schema.sql ] && diff -q database/schema/mysql-schema.sql database/schema/mysql-schema-new.sql > /dev/null; then
echo "No changes detected in schema"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in schema"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request branch
if: steps.diff.outputs.has_changes == 'true'
run: |
git config --local user.email "hdinnovations@protonmail.com"
git config --local user.name "HDVinnie"
BRANCH_NAME="update-schema-dump-$(date +%Y-%m-%d-%H-%M-%S)"
git checkout -b $BRANCH_NAME
mv database/schema/mysql-schema-new.sql database/schema/mysql-schema.sql
git add database/schema/mysql-schema.sql
git commit -m "update: MySQL schema dump"
git push --set-upstream origin $BRANCH_NAME
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
- name: Create Pull Request
if: steps.diff.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.branch_name }}
delete-branch: true
title: "(Update) MySQL schema dump"
body: |
This PR updates the MySQL schema dump with the latest migration changes.
**Automated PR generated by GitHub Actions**
base: development
draft: false