sufyandev / laravel-migration-linter
A lightweight Laravel package that analyzes and warns about risky database migration changes before they reach production.
Installs: 414
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/sufyandev/laravel-migration-linter
Requires
- php: ^8.1|^8.2|^8.3
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/framework: ^10.0|^11.0
- laravel/pint: ^1.0
- nunomaduro/larastan: ^2.9
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^3.0
Conflicts
- laravel/framework: <10.0
This package is auto-updated.
Last update: 2025-12-24 11:32:21 UTC
README
A lightweight Laravel package that analyzes your database migrations and warns you about risky schema changes β before they reach production.
π Features
- π Detects dangerous migration patterns:
- Non-nullable columns without defaults
- Missing indexes on foreign keys
- Unsafe column drops
- Risky unique constraints
- Floating-point money fields
- Unsafe column renaming (table locks)
- Column type changes on large tables (table locks)
- Soft deletes on large tables
- βοΈ Configurable rule severities (
info,warning,error) - π‘ Actionable suggestions β Each warning includes fix recommendations with grouped display
- π Documentation links β Every suggestion has a link to detailed docs
- π§ Baseline support to ignore legacy issues
- π§Ύ JSON or table output for CI/CD (with suggestions included)
- π HTML Reports β Generate beautiful, interactive HTML reports with charts and filtering
- π¨ Clean output β Suggestions grouped by rule type to avoid repetition
- π§© Fully documented & tested (84 tests, 200 assertions)
π Read full rule docs:
π https://muhammad-sufyan5.github.io/sufyan-laravel-migration-lint-package/
π¦ Installation
Install via Composer:
composer require sufyandev/laravel-migration-linter --dev
The package will auto-register via Laravelβs package discovery.
π§© Usage
Run the built-in Artisan command to lint all migration files:
php artisan migrate:lint
Common Options
| Option | Description |
|---|---|
--json |
Output structured JSON (great for CI) |
--html= |
Generate interactive HTML report (default: storage/app/...) |
--path= |
Lint a specific migration file/folder |
--baseline |
Use a custom baseline file |
--generate-baseline |
Create a baseline to ignore current issues |
--rules |
View all rules and their enabled status |
--summary |
Display summary footer in output |
--no-suggestions |
Hide suggestions (show only warnings table) |
Example Usage
Lint all migrations and export JSON:
php artisan migrate:lint --json > storage/lint-report.json
Generate a new baseline file (ignore current issues):
php artisan migrate:lint --generate-baseline
Sample warning output:
[warning] AddUniqueConstraintOnNonEmptyColumn
β Adding unique constraint to 'email' may fail if duplicates exist in 'users'.
π Scope & Limitations
What We Analyze
β
Laravel Schema Builder Operations β All $table-> method calls
β
Schema::create() and Schema::table() methods
β
Column modifications via ->change()
β
Foreign keys, indexes, constraints, timestamps
What We Don't Analyze (By Design)
β οΈ Raw SQL queries (DB::statement(), DB::raw(), etc.)
β οΈ Direct Eloquent operations (User::update(), model factories)
β οΈ Model traits and properties
β οΈ Data seeding operations
Reason: The linter focuses on statically analyzing schema builder patterns, which represent 99% of migration files. Raw SQL analysis requires different tooling.
βοΈ Configuration
You can publish the configuration file to customize rule settings:
php artisan vendor:publish --tag="migration-linter-config"
The config file (config/migration-linter.php) allows you to:
- Set severity threshold (
info,warning,error) - Enable/disable specific rules
- Customize rule severity levels
Example configuration:
return [ 'severity_threshold' => 'warning', 'rules' => [ 'AddNonNullableColumnWithoutDefault' => ['enabled' => true, 'severity' => 'warning'], 'MissingIndexOnForeignKey' => ['enabled' => true, 'severity' => 'warning'], // ... other rules ], ];
π§Ύ CI/CD Integration (GitHub Actions)
name: Laravel Migration Linter on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: 8.3 - run: composer install --no-interaction - run: php artisan migrate:lint --json > lint-report.json
β¨ What's New in v2.0.0
Complete SOLID Principles Refactoring
- ποΈ 8 Core Interfaces β Dependency injection contracts for all components
- π§ 3 Service Classes β Reusable business logic layer (LaravelConfigProvider, SeverityResolver, LintService)
- π¨ 5 Formatter Classes β Modular output system (Table, JSON, Compact, Summary, Base)
- π Dependency Injection β Automatic container bindings via service provider
- π Enhanced Architecture β SOLID principles throughout (SRP, OCP, LSP, ISP, DIP)
- β 144 tests passing β Comprehensive test coverage with 259 assertions
- π 100% backward compatible β No breaking changes, all v1.4.0 commands work identically
- π― Better table formatting β Fixed Symfony Table component for proper alignment
Migration from v1.4.0: All commands work exactly the same. No changes needed:
php artisan migrate:lint # Still works php artisan migrate:lint --json # Still works php artisan migrate:lint --generate-baseline # Still works
β¨ What Was New in v1.4.0
- Suggestions System β Each warning includes actionable fix recommendations
- Documentation Links β Every issue links to detailed docs for the rule
- SoftDeletesOnProduction β New rule for detecting unsafe soft deletes on large tables
- Enhanced Reporter β JSON and table output include suggestions
- 100% test coverage with 43 passing tests
π§βπ» Contributing
Contributions are welcome! If you have an idea for a useful rule or enhancement, feel free to open a PR or issue.
π§Ύ License
Released under the MIT License. Β© 2025 Sufyan. All rights reserved.
π§ Author
Muhammad Sufyan π§ muhammadsufyanwebdeveloper@gmail.com π GitHub: @muhammad-sufyan5
βSmart developers donβt debug production β they lint migrations.β
π Full Documentation:
π https://muhammad-sufyan5.github.io/sufyan-laravel-migration-lint-package/
