Detect and Resolve Laravel Schema Drift with MigrAlign

Published on by

Detect and Resolve Laravel Schema Drift with MigrAlign image

MigrAlign is a Laravel package that finds the differences between your migration files and your actual database, then applies the changes with safeguards based on how risky each change is. It targets schema drift — the gap that opens up when teams edit tables directly, skip a migration, or run divergent environments.

How It Works

MigrAlign reads the intent from your migration files by scanning Schema::create() and Schema::table() calls, then introspects the live schema from information_schema on MySQL or MariaDB. The diff between the two becomes a set of proposed changes. You can preview everything before anything runs:

php artisan migralign:sync --dry-run

Risk Classification

Rather than applying every change the same way, MigrAlign sorts each change into one of three categories:

  • Safe: adding nullable columns, widening column sizes, and metadata-only changes.
  • Risky: shrinking a type, switching a column from nullable to not-null, or contracting an enum.
  • Destructive: dropping columns or tables.

Safe changes are applied automatically when auto_apply_safe is enabled. Risky and destructive changes prompt for confirmation before MigrAlign touches the database, so a forgotten drop doesn't run unattended.

Targeted Syncing

You can scope a sync to a single table or migration instead of the whole schema, which is useful when you only need to reconcile one area:

# Sync a specific table
php artisan migralign:sync --table=users
 
# Sync changes from a specific migration
php artisan migralign:sync --migration=2024_01_01
 
# Apply all changes without prompts
php artisan migralign:sync --force

After a run, MigrAlign reports each change as applied, skipped, pending, or errored.

Installation and Configuration

Install the package via Composer and publish the config file:

composer require migralign/laravel-migralign
php artisan vendor:publish --tag=migralign-config

The published config controls which migrations path is read, which tables to ignore, and whether safe changes apply automatically:

return [
'migrations_path' => database_path('migrations'),
'ignored_tables' => ['migrations', 'sessions', 'jobs', 'failed_jobs'],
'auto_apply_safe' => true,
'connection' => null,
];

MigrAlign requires PHP 8.2+ (8.3+ on Laravel 13) and supports Laravel 11, 12, and 13. It works with MySQL and MariaDB only, and migrations with highly dynamic logic may still need manual review.

You can learn more and view the source on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Vocalizer: Local Text-to-Speech for PHP image

Vocalizer: Local Text-to-Speech for PHP

Read article
Build a Laravel Scout Search Endpoint With the HTTP QUERY Method image

Build a Laravel Scout Search Endpoint With the HTTP QUERY Method

Read article
Enforce Per-Action Waiting Periods in Laravel with Cooldown image

Enforce Per-Action Waiting Periods in Laravel with Cooldown

Read article
First-Party Image Processing in Laravel 13.20 image

First-Party Image Processing in Laravel 13.20

Read article
Laravel Legacy Bridge: Carry Authenticated Sessions from a Legacy App into Laravel image

Laravel Legacy Bridge: Carry Authenticated Sessions from a Legacy App into Laravel

Read article
Laravel Quota: Usage Budgets for Calendar Periods image

Laravel Quota: Usage Budgets for Calendar Periods

Read article