PHPackages                             emirkefi/laravel-schema-drift - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. emirkefi/laravel-schema-drift

ActiveLibrary

emirkefi/laravel-schema-drift
=============================

Zero-config database vs. migration drift detector for Laravel.

00PHP

Since Aug 28Pushed todayCompare

[ Source](https://github.com/emirkefi/laravel-schema-drift)[ Packagist](https://packagist.org/packages/emirkefi/laravel-schema-drift)[ RSS](/packages/emirkefi-laravel-schema-drift/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Schema Drift Detector
=============================

[](#laravel-schema-drift-detector)

[![Packagist License](https://camo.githubusercontent.com/03dfd81fa7fed3dbdaa4e1b196126d4ee5cd27a782d80229c3035f47f0762257/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656d69726b6566692f6c61726176656c2d736368656d612d6472696674)](https://camo.githubusercontent.com/03dfd81fa7fed3dbdaa4e1b196126d4ee5cd27a782d80229c3035f47f0762257/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656d69726b6566692f6c61726176656c2d736368656d612d6472696674)[![Packagist Downloads](https://camo.githubusercontent.com/e6b4df57c98b4013eaaea525fc68f924eaf801da303761a2f549887116657357/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d69726b6566692f6c61726176656c2d736368656d612d6472696674)](https://camo.githubusercontent.com/e6b4df57c98b4013eaaea525fc68f924eaf801da303761a2f549887116657357/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d69726b6566692f6c61726176656c2d736368656d612d6472696674)[![Packagist Version](https://camo.githubusercontent.com/b40a5aac517e7fc17814819a78f9c13d2f09928d7c5070969bd012f4cb5e0c10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d69726b6566692f6c61726176656c2d736368656d612d6472696674)](https://camo.githubusercontent.com/b40a5aac517e7fc17814819a78f9c13d2f09928d7c5070969bd012f4cb5e0c10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d69726b6566692f6c61726176656c2d736368656d612d6472696674)

A powerful, zero-config Artisan command to detect schema drift between your live database and your Laravel migration files.

Ever wonder if someone manually tweaked a database column directly in production without writing a migration? Or if a legacy table is sitting in your database completely untracked? This package catches those discrepancies instantly, integrates seamlessly into your CI/CD pipelines, and can even generate the fix migrations for you automatically.

 [![Laravel Schema Drift Preview](art/preview.png)](art/preview.png)

How It Works
------------

[](#how-it-works)

Behind the scenes, the package uses a clever "shadow database" approach:

1. It takes a snapshot of your live database schema.
2. It spins up a temporary in-memory SQLite database (or connects to your configured shadow database) and runs all your migration files.
3. It compares the two schemas and outputs a terminal table highlighting missing tables, untracked columns, nullability mismatches, type drift, default value drift, and index discrepancies.
4. **Instant Fix**: Generate a Laravel migration with a single flag (`--fix`) to bring your migrations in sync.
5. **CI/CD Ready**: Output machine-readable JSON, Markdown, or native GitHub Actions workflow annotations to fail PRs with clickable inline diffs.

Features
--------

[](#features)

- **Zero-Config Drift Detection**: Compare live databases directly against migration files.
- **Automatic Migration Generator (`--fix`)**: Automatically generate a timestamped Laravel migration to synchronize detected drift without writing boilerplate code manually.
- **CI/CD &amp; Pipeline Formats**: Output structured `json`, Markdown tables (`markdown`), or GitHub Actions workflow annotations (`github`).
- **Severity &amp; Failure Controls**: Categorizes drift by severity (`error` vs `warning`) with configurable thresholds (`--min-severity=error|warning`).
- **Cross-Database Type Normalization Engine**: SQLite shadow databases use loose type affinity. Our built-in `TypeNormalizer` accurately maps dialect-specific column types across **MySQL**, **PostgreSQL**, **SQLite**, and **SQL Server** to canonical types (`integer`, `bigint`, `boolean`, `decimal`, `string`, `datetime`, `json`, `binary`), eliminating false-positive type mismatches (e.g. MySQL `TINYINT(1)` vs SQLite boolean/integer).
- **Smart Default Value Normalization**: Strips dialect-specific default wrappers (such as Postgres casts `'val'::character varying`, SQL Server `((0))`, MySQL bit literals `b'1'`, and boolean string variants) to ensure accurate default comparisons.
- **Custom Shadow Connections**: Have migrations containing raw SQL statements, full-text indexes, GIS/spatial types, or stored procedures that fail on SQLite? Pass a real shadow connection (e.g. `--shadow-connection=mysql_testing`) to run migrations against a dedicated test database.
- **Built-in Safety Guardrails**: Prevents accidentally running shadow migrations against your target live/production connection.
- **Fine-Grained Strictness Checks**: Enable or disable checks for indexes, foreign keys, column types, and defaults.
- **Ignore Patterns**: Exclude vendor, framework, or legacy tables with wildcard support (e.g. `pma__*`).

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 11.0, 12.0, or 13.0
- SQLite PHP extension enabled (when using the default in-memory shadow database)

Installation
------------

[](#installation)

You can install the package via Composer as a `dev` dependency:

```
composer require emirkefi/laravel-schema-drift --dev
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=schema-drift-config
```

Usage
-----

[](#usage)

### Basic Drift Check

[](#basic-drift-check)

Run the drift check against your default database connection:

```
php artisan schema:drift
```

### Auto-Fix with Migration Generation

[](#auto-fix-with-migration-generation)

Automatically generate a Laravel migration to fix detected drift:

```
php artisan schema:drift --fix
```

To include destructive drop operations (e.g. dropping columns or tables in migration that do not exist in the live database):

```
php artisan schema:drift --fix --destructive
```

### CI/CD &amp; Pipeline Formats

[](#cicd--pipeline-formats)

Output machine-readable JSON:

```
php artisan schema:drift --format=json
```

Output GitHub Actions workflow annotations with inline errors/warnings:

```
php artisan schema:drift --format=github
```

Output Markdown summary table:

```
php artisan schema:drift --format=markdown >> $GITHUB_STEP_SUMMARY
```

Fail CI only on critical errors (e.g. missing tables/columns, type mismatches):

```
php artisan schema:drift --min-severity=error
```

### GitHub Actions Workflow Example

[](#github-actions-workflow-example)

Add this job step to your CI pipeline:

```
- name: Check Schema Drift
  run: php artisan schema:drift --format=github --min-severity=warning
```

### Standalone Migration Generator Command

[](#standalone-migration-generator-command)

You can also invoke the migration generator directly:

```
php artisan schema:drift:generate-migration --name=sync_legacy_schema
```

### Custom Live Connection or Migration Path

[](#custom-live-connection-or-migration-path)

Check a specific database connection or custom migration directory:

```
php artisan schema:drift --connection=mysql --path=database/migrations
```

### Custom Shadow Connection (MySQL / PostgreSQL / SQL Server)

[](#custom-shadow-connection-mysql--postgresql--sql-server)

When migrations contain engine-specific SQL or spatial indexes that SQLite doesn't support, supply a dedicated test database connection:

```
php artisan schema:drift --connection=mysql --shadow-connection=mysql_testing --fresh-shadow
```

Configuration
-------------

[](#configuration)

In `config/schema-drift.php`, you can customize formats, severity thresholds, shadow connections, strictness checks, and ignored tables:

```
return [
    /*
    | Shadow Database Connection
    | Set to null for default in-memory SQLite, or specify a test connection name
    */
    'shadow_connection' => env('SCHEMA_DRIFT_SHADOW_CONNECTION', null),
    'fresh_shadow' => env('SCHEMA_DRIFT_FRESH_SHADOW', true),

    /*
    | CI/CD & Output Settings
    */
    'default_format' => env('SCHEMA_DRIFT_FORMAT', 'table'),
    'min_severity' => env('SCHEMA_DRIFT_MIN_SEVERITY', 'warning'),

    /*
    | Ignore system or vendor tables from drift analysis
    */
    'ignore_tables' => [
        'migrations',
        'failed_jobs',
        'job_batches',
        'sessions',
        'cache',
        'cache_locks',
        'password_reset_tokens',
        'pma__*',
    ],

    /*
    | Strictness checks
    */
    'check_indexes' => true,
    'check_foreign_keys' => true,
    'check_types' => true,
    'check_defaults' => true,
];
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/318289066?v=4)[emirkefi](/maintainers/emirkefi)[@emirkefi](https://github.com/emirkefi)

---

Top Contributors

[![emirkefi](https://avatars.githubusercontent.com/u/318289066?v=4)](https://github.com/emirkefi "emirkefi (14 commits)")[![Mirmir-dev](https://avatars.githubusercontent.com/u/188556904?v=4)](https://github.com/Mirmir-dev "Mirmir-dev (4 commits)")

### Embed Badge

![Health badge](/badges/emirkefi-laravel-schema-drift/health.svg)

```
[![Health](https://phpackages.com/badges/emirkefi-laravel-schema-drift/health.svg)](https://phpackages.com/packages/emirkefi-laravel-schema-drift)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
