PHPackages                             antonkomarev/php-db-migration-validator - 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. [Database &amp; ORM](/categories/database)
4. /
5. antonkomarev/php-db-migration-validator

ActiveLibrary[Database &amp; ORM](/categories/database)

antonkomarev/php-db-migration-validator
=======================================

Validate PHP database migration files

1.0.2(4y ago)191.5k3MITPHPPHP ^7.1|^8.0

Since Jan 15Pushed 4y ago2 watchersCompare

[ Source](https://github.com/antonkomarev/php-db-migration-validator)[ Packagist](https://packagist.org/packages/antonkomarev/php-db-migration-validator)[ Docs](https://komarev.com/sources/php-db-migration-validator)[ Fund](https://paypal.me/antonkomarev)[ RSS](/packages/antonkomarev-php-db-migration-validator/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

PHP DB Migration Validator
==========================

[](#php-db-migration-validator)

[![php-db-migration-validator](https://user-images.githubusercontent.com/1849174/149624430-88547f33-9a48-4124-b648-d73c82a6e869.gif)](https://user-images.githubusercontent.com/1849174/149624430-88547f33-9a48-4124-b648-d73c82a6e869.gif)

[![Discord](https://camo.githubusercontent.com/86e83e2f2ffe2f5caffed9d8886bb512bf42bf927dd8bb8e864d9e9983313ff7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6f676f3d646973636f7264266c6162656c3d266d6573736167653d446973636f726426636f6c6f723d333633393366267374796c653d666c61742d737175617265)](https://discord.gg/83Yd8MgYp9)[![Releases](https://camo.githubusercontent.com/0fe46e3eb9d8bb1602820b44bbc094aebde78708483eb6d893e3152724f00868/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f616e746f6e6b6f6d617265762f7068702d64622d6d6967726174696f6e2d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/antonkomarev/php-db-migration-validator/releases)[![License](https://camo.githubusercontent.com/51f506c76cf263bf845671a6bf5554f758f663ed58d90e7a3e64d0695ef36496/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616e746f6e6b6f6d617265762f7068702d64622d6d6967726174696f6e2d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/antonkomarev/php-db-migration-validator/blob/master/LICENSE)

Introduction
------------

[](#introduction)

In modern PHP frameworks such as Symfony and Laravel, migrations usually have `up` and `down` methods. In `up` method of migration definition you had to write code which is called only on running migration forward and in `down` — the code which is called only on rolling migration back. It is standard practice to make database migrations irreversible. Migrations should be backward compatible and only go forward.

In Laravel, a missing or empty `down` method does not prevent rollback migration on execution of `php artisan migrate:rollback` CLI command. The state of the database will not change, but the migration will be removed from the registry of applied migrations, and the next execution of `php artisan migrate` will call the `up` method again. To prevent this behavior, all migrations should have `down` method that will throw an Exception, nothing more.

PHP DB Migration Validator checks whether all migration files meet this requirement. You can add it to the server's git hooks to prevent migration rollback, or add validation step to CI.

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

[](#installation)

Pull in the package through Composer.

```
php composer require antonkomarev/php-db-migration-validator
```

Usage
-----

[](#usage)

### Validate migrations are irreversible

[](#validate-migrations-are-irreversible)

**Validate file**

```
php vendor/bin/php-db-migration-validator --rule=irreversible migrations/file.php
```

**Validate many files**

```
php vendor/bin/php-db-migration-validator --rule=irreversible migrations/file.php migrations/file2.php
```

**Validate many files by wildcard**

```
php vendor/bin/php-db-migration-validator --rule=irreversible migrations/2022_*
```

**Validate files in directory**

```
php vendor/bin/php-db-migration-validator --rule=irreversible migrations/
```

**Validate files in many directories**

```
php vendor/bin/php-db-migration-validator --rule=irreversible app/migrations/ vendor/migrations/
```

### CI automation

[](#ci-automation)

Automating the validation of all contributions to the repository as part of the Continuous Integration is one of the possible ways to use this tool.

#### GitHub Action

[](#github-action)

Create file `.github/workflows/db-migration-validation.yaml` in the application repository.

```
name: DB Migration Validation

on:
    push:

jobs:
    db-migration-validation:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v2
            - uses: shivammathur/setup-php@v2
              with:
                  php-version: 8.1
                  extensions: tokenizer
                  coverage: none
            - name: Install PHP DB Migration Validator dependency
              run: composer global require antonkomarev/php-db-migration-validator --no-interaction
            - name: Ensure all database migrations are irreversible
              run: php-db-migration-validator --rule=irreversible ./database/migrations
```

### Command usage instructions

[](#command-usage-instructions)

```
$ php vendor/bin/php-db-migration-validator --help
PHP DB Migration Validator
--------------------------
by Anton Komarev

Usage: php-db-migration-validator --rule=

  The following commands are available:

    help  Shows this usage instructions.

  Options:

    --rules=   Validates the database migration(s) in the specified .
                     Exits with code 1 on validation errors, 2 on other errors and 0 on success.
                     Available rules (at least one should be specified):
                     - irreversible — ensure if migration file has `down` method and this method throws an Exception.

```

License
-------

[](#license)

- `PHP DB Migration Validator` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev](https://komarev.com).

Support the project
-------------------

[](#support-the-project)

If you'd like to support the development of PHP DB Migration Validator, then please consider [sponsoring me](https://paypal.me/antonkomarev). Thanks so much!

About CyberCog
--------------

[](#about-cybercog)

[CyberCog](https://cybercog.su) is a Social Unity of enthusiasts. Research the best solutions in product &amp; software development is our passion.

- [Follow us on Twitter](https://twitter.com/cybercog)

[![CyberCog](https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png)](https://cybercog.su)

###  Health Score

31

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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 ~0 days

Total

3

Last Release

1665d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3fddc40462126bbc119e373ed6a3f942a90a400f30c076c447c0625b841c4ef?d=identicon)[antonkomarev](/maintainers/antonkomarev)

---

Top Contributors

[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (57 commits)")

---

Tags

best-practicebest-practicescidatabasedatabase-migrationdatabase-migrationsdb-migrationdb-migrationsirreversible-migrationphpphp-libraryvalidatevalidationvalidationmigrationdatabasedb

### Embed Badge

![Health badge](/badges/antonkomarev-php-db-migration-validator/health.svg)

```
[![Health](https://phpackages.com/badges/antonkomarev-php-db-migration-validator/health.svg)](https://phpackages.com/packages/antonkomarev-php-db-migration-validator)
```

###  Alternatives

[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2613.3M481](/packages/ssch-typo3-rector)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136411.0k14](/packages/rector-rector-src)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k19](/packages/tempest-framework)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

166292.8k1](/packages/cybercog-laravel-clickhouse)[dbout/wp-orm

WordPress ORM with Eloquent.

12910.5k1](/packages/dbout-wp-orm)

PHPackages © 2026

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