๐ค CI/CD Integration
Laravel Migration Linter integrates seamlessly with GitHub Actions, GitLab CI, and other continuous integration pipelines.
It ensures no unsafe schema changes reach production by failing builds when risky migrations are detected.
๐งฐ GitHub Actions Exampleโ
name: Laravel Migration Linter
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
lint-migrations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: mbstring, pdo, bcmath, curl, dom, xml
tools: composer:v2
# ๐งฉ Example: setting up a test Laravel project using your local package
- run: composer create-project laravel/laravel test-laravel-app --quiet
- name: Install Laravel Migration Linter (local path)
run: |
cd test-laravel-app
composer config repositories.sufyandev path ../
composer require sufyandev/laravel-migration-linter:@dev --no-interaction
- name: Run Migration Linter
run: |
cd test-laravel-app
php artisan migrate:lint --json > lint-report.json
๐งช Example in CI Consoleโ
๐ Running Laravel Migration Linter...
โ ๏ธ Lint Report
+-------------------------------------+-------------------------------------------+-----------+----------+----------------------------------------------------------+
| File | Rule | Column | Severity | Message |
+-------------------------------------+-------------------------------------------+-----------+----------+----------------------------------------------------------+
| 0001_01_01_000000_create_users.php | AddNonNullableColumnWithoutDefault | email | warning | Adding NOT NULL column without default value. |
| 2025_10_15_000000_create_orders.php | FloatColumnForMoney | price | warning | Using float() for price โ use decimal(10,2) instead. |
+-------------------------------------+-------------------------------------------+-----------+----------+----------------------------------------------------------+
[Suggestion #1] AddNonNullableColumnWithoutDefault:
Option 1: Add a default value to the column (e.g., ->default('value'))
Option 2: Make it nullable with ->nullable(), backfill existing rows, then alter
๐ Learn more: https://docs.example.com/rules#AddNonNullableColumnWithoutDefault
[Suggestion #2] FloatColumnForMoney:
Use decimal(10,2) or decimal(19,4) for precise monetary calculations
๐ Learn more: https://docs.example.com/rules#FloatColumnForMoney
๐ Exit Codes and Build Behaviorโ
| Severity Threshold | Description | Exit Code | Build Result |
|---|---|---|---|
info | Advisory messages only | 0 | โ Pass |
warning | Potential issues found, not fatal | 0 | โ Pass |
error | Migration-breaking or data-loss risks | 1 | โ Fail |
You can adjust this threshold via config/migration-linter.php:
'severity_threshold' => 'error',
When set to 'error', only error-level issues cause your CI pipeline to fail.
๐ง Tips for CI/CD Integrationโ
- ๐พ Commit the baseline file (migration-linter-baseline.json) once generated.
- This prevents known legacy issues from reappearing in reports.
- ๐งฉ Use --json output to generate structured reports for custom dashboards.
- You can also upload the JSON artifact for analysis.
- ๏ฟฝ Suggestions are included in both CLI and JSON output โ use them to guide developers on fixes.
- ๏ฟฝ๐ฆ Fail fast: set 'severity_threshold' => 'error' in config to stop deployments on risky migrations.
- ๐ Run on every PR โ this ensures every migration is linted before merge.
๐งพ GitLab CI Exampleโ
If you're using GitLab, add a stage like this:
stages:
- lint
lint_migrations:
stage: lint
image: php:8.3
script:
- apt-get update && apt-get install -y unzip git
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install --no-interaction
- php artisan migrate:lint --json > lint-report.json
โ Result: Your CI/CD pipeline now automatically enforces safe, production-ready migrations โ blocking schema-breaking changes before they reach your main branch.