Laravel Schema Sentinel: Detect and Fix Database Schema Drift

https://picperf.io/https://laravelnews.s3.amazonaws.com/featured-images/minimal-db-featured.png

Laravel Schema Sentinel by Ahtesham at Broadway Web Service detects schema drift— to help identify when your actual database no longer matches your migrations. It builds a shadow database from your migrations, diffs it against the live schema, and can generate a corrective migration when the two diverge.

  • Deep drift detection — audits tables, columns, data types, nullability, defaults, indexes, and foreign keys
  • Cross-environment comparison — verify local migrations match staging or production
  • Auto-generated migrations — create corrective migrations with interactive review
  • Visual dashboard — built-in Livewire component for database health monitoring
  • Pre-migration guard — automatically block php artisan migrate if drift is detected
  • And more…

Detecting Drift

The core command runs your migrations into a temporary shadow database, then compares that shadow against your live connection:

php artisan schema:drift

It checks tables, columns, data types, nullability, defaults, indexes, and foreign keys. Running with --strict also flags columns or tables present in the live database that have no corresponding migration.

Generating a Fix

When drift is found, you can have Sentinel generate a migration to close the gap:

php artisan schema:drift --fix --interactive

Interactive mode walks you through each detected difference before writing anything. A --sql flag skips file creation and prints the migration code to the terminal for review.

Cross-Environment Comparison

You can point the diff at a different environment’s database connection instead of your local one:

php artisan schema:drift --compare-env=staging

This uses the named connection from your config/database.php, so you can verify your local migrations match what’s deployed to staging or production before running them.

Programmatic API

A Sentinel facade exposes the same diff as a DTO, which you can use in controllers, Livewire components, or admin dashboards:

use Sentinel\SchemaSentinel\Facades\Sentinel;

 

$diff = Sentinel::check(strict: true);

 

return response()->json([

'in_sync' => !$diff->hasDifferences(),

'drift' => $diff->toArray(),

]);

The package also ships a Blade-embeddable Livewire component for a visual health dashboard, though it only renders in local environments:

<livewire:sentinel-database-health />

The package supports Laravel 11.x through 13.x. You can find Laravel Schema Sentinel on GitHub.

Laravel News