Download the PHP package malikad778/laravel-migration-guard without Composer
On this page you can find all versions of the php package malikad778/laravel-migration-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download malikad778/laravel-migration-guard
More information about malikad778/laravel-migration-guard
Files in malikad778/laravel-migration-guard
Package laravel-migration-guard
Short Description Catch dangerous database migrations before they reach production. The strong_migrations equivalent for Laravel. Zero configuration. Framework-native.
License MIT
Informations about the package laravel-migration-guard

The Problem
Every Laravel team doing zero-downtime deployments has eventually had a migration incident. These operations succeed without errors in development, then cause production outages anywhere from immediately to hours later:
| Operation | What breaks in production |
|---|---|
dropColumn() |
Old app instances still query the dropped column โ immediate DB errors during the deployment window |
NOT NULL without default |
Full table rewrite on MySQL < 8.0 โ locks reads and writes for minutes on large tables |
renameColumn() |
Old instances use old name, new instances use new name โ one of them is always wrong |
addIndex() without INPLACE |
MySQL < 8.0 holds a full write lock while building the index โ minutes on busy tables |
change() column type |
Full table rewrite, potential silent data truncation (e.g. VARCHAR(50) โ VARCHAR(40)) |
Schema::rename() |
Every Eloquent model and raw query referencing the old table name breaks immediately |
truncate() in a migration |
Production data permanently destroyed โ migrations are the wrong place for data deletion |
Rails developers have had strong_migrations (4,000+ GitHub stars) for years. The Laravel ecosystem has no maintained equivalent. Every team solves this by hand: code review checklists, tribal knowledge, and hoping nobody forgets to check.
laravel-migration-guard eliminates that risk by making artisan migrate production-aware โ without changing your workflow.
Installation
The package auto-discovers via Laravel's package discovery. No manual registration required.
Optionally publish the config file:
That's it. Out of the box, with zero configuration, the guard:
- โ
Hooks into
artisan migrateand warns before any dangerous migration runs - โ
Is active only when
APP_ENVisproductionorstaging - โ
Is completely silent in
localandtestingenvironments - โ
Outputs warnings inline before execution, allowing you to abort with
Ctrl+C
How It Works
The package uses static analysis โ it parses your migration PHP files into an Abstract Syntax Tree (AST) using nikic/php-parser and walks the tree looking for dangerous method call patterns.
This means:
- No database connection needed โ analysis works against raw PHP files in any environment, including CI/CD pipelines
- Sub-millisecond per file โ PHP AST parsing is extremely fast; 200 migration files takes under a second
- Only the
up()method is analysed โdown()rollbacks are intentionally excluded Schema::create()is excluded โ creating a fresh table with no existing rows is always safe; onlySchema::table()operations are checked
Analysis Pipeline
Safety Checks
Nine checks are included. All enabled by default, individually configurable.
| Check ID | Severity | What It Detects |
|---|---|---|
drop_column |
๐ด BREAKING | dropColumn() or dropColumns() on an existing table |
drop_table |
๐ด BREAKING | Schema::drop() or Schema::dropIfExists() |
rename_column |
๐ด BREAKING | renameColumn() on any table |
rename_table |
๐ด BREAKING | Schema::rename() |
modify_primary_key |
๐ด BREAKING | dropPrimary() or primary() on an existing table |
truncate |
๐ด BREAKING | DB::table()->truncate() inside a migration |
add_column_not_null |
๐ก HIGH | Column added without ->nullable() or ->default() |
change_column_type |
๐ก HIGH | ->change() modifying an existing column type |
add_index |
๐ต MEDIUM | Index added to a critical or large table |
Check Details & Safe Alternatives
Drop Column โ BREAKING
Why: During a zero-downtime deployment, old app instances run alongside the new schema. Any query touching the dropped column fails immediately with a database error.
Safe approach:
- Deploy 1: Remove all code references to the column (models, queries,
$fillable,$casts) - Deploy 2: Drop the column after confirming no running instance references it
Add NOT NULL Column Without Default โ HIGH
Why: MySQL < 8.0 requires a full table rewrite when adding a NOT NULL column without a default. On a large table this blocks all reads and writes for minutes.
Safe approach:
- Add the column as
->nullable()(instant, no lock) - Backfill existing rows:
User::whereNull('status')->update(['status' => 'active']) - Add the
NOT NULLconstraint in a separate migration after backfill completes
Rename Column / Table โ BREAKING
Why: Old instances use the old name, new instances use the new name โ one is always wrong during the deployment window. Eloquent models, raw queries, and $fillable arrays all break.
Safe approach: Add new column โ copy data โ update code โ deploy โ drop old column in a follow-up migration.
Add Index (on critical/large tables) โ MEDIUM
Why: MySQL < 8.0 holds a full write lock while building an index. MySQL 8.0+ and PostgreSQL support online index builds but require specific syntax that Laravel migrations do not use by default.
Change Column Type โ HIGH
Why: A full table rewrite is required in most databases. Implicit type coercions can silently corrupt data (e.g. VARCHAR(255) โ VARCHAR(100) truncates existing values). Indexes on the column may be dropped.
Safe approach: Add new column of the correct type โ migrate data โ update code โ deploy โ drop old column.
Example Warning Output
Configuration
Environment Variable Overrides
| Variable | Description |
|---|---|
MIGRATION_GUARD_MODE |
warn or block. Overrides config file. |
MIGRATION_GUARD_DISABLE |
Set to true to disable entirely (e.g. in CI seed steps). |
MIGRATION_GUARD_ROW_THRESHOLD |
Row count above which a table is treated as critical for index checks. Default: 500000. |
Artisan Commands
php artisan migration:guard:analyse
Standalone command for CI/CD pipelines. Analyses all pending migrations and outputs a report without running them. Exits with code 1 if dangerous operations are found.
Exit codes:
| Code | Meaning |
|---|---|
0 |
No issues found, or all issues below --fail-on threshold |
1 |
One or more issues at or above threshold |
2 |
Analysis error (parse failure, permission error) |
php artisan migration:guard:ignore
Adds a suppression entry to config/migration-guard.php for a specific check and table โ or check, table, and column.
Valid check IDs: drop_column, drop_table, rename_column, rename_table, add_column_not_null, change_column_type, add_index, modify_primary_key, truncate
JSON Output Schema
CI/CD Integration
GitHub Actions
The --format=github flag produces GitHub Actions annotation syntax, placing inline warnings directly on the pull request diff at the relevant migration file line.
GitLab CI
Package Architecture
Requirements
| Version | |
|---|---|
| PHP | 8.2 or higher |
| Laravel | 10.x, 11.x, 12.x |
| MySQL | 5.7+ or 8.0+ |
| PostgreSQL | 13+ |
| SQLite | 3+ |
nikic/php-parser |
^5.0 (installed automatically) |
Comparison: strong_migrations vs laravel-migration-guard
| Feature | strong_migrations | laravel-migration-guard |
|---|---|---|
| Drop column detection | โ | โ |
| Drop table detection | โ | โ |
| Rename detection | โ | โ |
| NOT NULL without default | โ | โ |
| Index safety | โ | โ |
| CI/CD JSON output | โ | โ |
| GitHub Annotations | โ | โ |
| Per-table suppression | โ | โ |
| Per-column suppression | โ | โ |
| Warn vs Block mode | โ | โ |
| Zero config defaults | โ | โ |
| Framework | Rails only | Laravel only |
Roadmap
v1.0.0 โ Launch (current)
- All 9 checks fully implemented and tested
artisan migratehookmigration:guard:analysewith table, JSON, GitHub outputmigration:guard:ignorecommand- Full documentation
v1.1.0 โ Database Awareness
- Query the live database to get actual row counts for index safety thresholds
- Show estimated lock duration based on table size
- PostgreSQL-specific checks:
CONCURRENTLYindex builds,VACUUMconsiderations
v1.2.0 โ Reporting
- Weekly migration safety digest: summary of all migrations run in the past 7 days
- Slack / email notification when dangerous migrations are bypassed in production
- Audit log of every migration run with who triggered it
v2.0.0 โ Safe Alternative Code Generation
- For each detected issue, generate the safe equivalent migration stub automatically
migration:guard:fixcommand that rewrites the migration file with the safe pattern
Contributing
Contributions are welcome. Adding a new check requires only:
- Create a class implementing
CheckInterfaceinsrc/Checks/ - Register it in
MigrationGuardServiceProvider::register() - Add the check ID to the
checksarray inconfig/migration-guard.php - Write unit tests covering both the unsafe pattern and the safe equivalent (false positive tests are required)
License
MIT โ free forever. See LICENSE.md.
All versions of laravel-migration-guard with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/console Version ^10.0|^11.0|^12.0
illuminate/events Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/notifications Version ^10.0|^11.0|^12.0
nikic/php-parser Version ^5.0