PHPackages                             bellangelo/phpstan-migration-rules - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bellangelo/phpstan-migration-rules

ActivePhpstan-extension[Utility &amp; Helpers](/categories/utility)

bellangelo/phpstan-migration-rules
==================================

PHPStan rules for database migration tools (Phinx, Symfony, Laravel)

v0.4.3(1mo ago)553.8k↓17.7%1[1 PRs](https://github.com/Bellangelo/phpstan-migration-rules/pulls)MITPHPPHP ^7.4 || ^8.0CI passing

Since Dec 28Pushed 1mo agoCompare

[ Source](https://github.com/Bellangelo/phpstan-migration-rules)[ Packagist](https://packagist.org/packages/bellangelo/phpstan-migration-rules)[ RSS](/packages/bellangelo-phpstan-migration-rules/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (12)Used By (0)

PHPStan Rules for Database Migrations
=====================================

[](#phpstan-rules-for-database-migrations)

A collection of PHPStan rules to enforce best practices and standards in database migration files for Phinx and Laravel / Illuminate.

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

[](#installation)

```
composer require --dev bellangelo/phpstan-migration-rules
```

The extension will be automatically registered if you have `phpstan/extension-installer` installed. Otherwise, add it manually to your `phpstan.neon`:

```
includes:
    - vendor/bellangelo/phpstan-migration-rules/extension.neon
```

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

[](#configuration)

All rules are enabled by default. You can customize behavior in your `phpstan.neon`:

```
parameters:
    migrationRules:
        requiredCollation: utf8mb4 # Default is utf8

        phinx:
            enforceCollation: true
            forbidAfter: true
            forbidEnumColumn: true
            forbidRawSql: true
            forbidMultipleTableCreations: true

        laravel:
            enforceCollation: true
            forbidAfter: true
            forbidEnumColumn: true
            forbidRawSql: true
            forbidMultipleTableCreations: true
```

If you only use one framework, disable the other to avoid unnecessary processing:

```
parameters:
    migrationRules:
        phinx:
            enforceCollation: false
            forbidAfter: false
            forbidEnumColumn: false
            forbidRawSql: false
            forbidMultipleTableCreations: false
```

Rule catalog
------------

[](#rule-catalog)

Each rule below applies to migration files for both Phinx and Laravel, unless stated otherwise.

### Rule: `EnforceCollationRule`

[](#rule-enforcecollationrule)

Enforces that table definitions explicitly define a collation.

> Prevents relying on database defaults, which may differ between environments.

FrameworkHow collation is detected[Phinx](./src/Rules/Phinx/EnforceCollationRule.php)`table('name', ['collation' => '…'])`[Laravel](./src/Rules/Laravel/EnforceCollationRule.php)`$table->collation('…')` or `$table->collation = '…'` inside the Blueprint callback---

### Rule: `ForbidAfterRule`

[](#rule-forbidafterrule)

Forbids column positioning via `after`.

> May trigger full table rewrites or long locks, unsafe for large or production tables.

FrameworkForbidden usage[Phinx](./src/Rules/Phinx/ForbidAfterRule.php)`addColumn(..., ['after' => 'column'])`[Laravel](./src/Rules/Laravel/ForbidAfterRule.php)`$table->string('x')->after('y')`---

### Rule: `ForbidEnumColumnRule`

[](#rule-forbidenumcolumnrule)

Forbids the use of `enum` column types in migrations.

> Modifying enum values requires a full `ALTER TABLE`, which can cause long locks on large tables. Use a string column with application-level validation instead.

FrameworkForbidden usage[Phinx](./src/Rules/Phinx/ForbidEnumColumnRule.php)`addColumn('col', 'enum', ['values' => [...]])`[Laravel](./src/Rules/Laravel/ForbidEnumColumnRule.php)`$table->enum('col', [...])`---

### Rule: `ForbidRawSqlRule`

[](#rule-forbidrawsqlrule)

Forbids raw SQL execution inside migrations.

> Raw SQL bypasses the schema builder, making migrations harder to review, less portable, and prone to errors.

FrameworkForbidden usage[Phinx](./src/Rules/Phinx/ForbidRawSqlRule.php)`$this->execute('...')`, `$this->query('...')`[Laravel](./src/Rules/Laravel/ForbidRawSqlRule.php)`DB::statement('...')`, `DB::unprepared('...')`---

### Rule: `ForbidMultipleTableCreationsRule`

[](#rule-forbidmultipletablecreationsrule)

Ensures each migration creates at most one table.

> Improves rollback safety and migration clarity.

FrameworkWhat counts as a table creation[Phinx](./src/Rules/Phinx/ForbidMultipleTableCreationsRule.php)Multiple calls to `create()` on table instances[Laravel](./src/Rules/Laravel/ForbidMultipleTableCreationsRule.php)Multiple `Schema::create()` calls in the same migration

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~9 days

Recently: every ~22 days

Total

11

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63b436ff6324681c11dc5b9f21ba2ae07cbdb25859ab63a9cbc6212cb3051b07?d=identicon)[Bellangelo](/maintainers/Bellangelo)

---

Top Contributors

[![Bellangelo](https://avatars.githubusercontent.com/u/9512427?v=4)](https://github.com/Bellangelo "Bellangelo (68 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bellangelo-phpstan-migration-rules/health.svg)

```
[![Health](https://phpackages.com/badges/bellangelo-phpstan-migration-rules/health.svg)](https://phpackages.com/packages/bellangelo-phpstan-migration-rules)
```

PHPackages © 2026

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