{"id":16185371,"url":"https://github.com/antonkomarev/php-db-migration-validator","last_synced_at":"2025-07-20T16:33:04.070Z","repository":{"id":56948883,"uuid":"448116964","full_name":"antonkomarev/php-db-migration-validator","owner":"antonkomarev","description":"Validate PHP database migration files for compliance with best practices. Ensure db migrations are irreversible.","archived":false,"fork":false,"pushed_at":"2022-01-16T08:32:43.000Z","size":70,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-22T05:48:08.076Z","etag":null,"topics":["best-practice","best-practices","ci","database","database-migration","database-migrations","db-migration","db-migrations","irreversible-migration","php","php-library","validate","validation"],"latest_commit_sha":null,"homepage":"https://komarev.com/sources/php-db-migration-validator","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonkomarev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-14T21:52:22.000Z","updated_at":"2025-05-17T11:54:09.000Z","dependencies_parsed_at":"2022-08-21T03:10:28.226Z","dependency_job_id":null,"html_url":"https://github.com/antonkomarev/php-db-migration-validator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/antonkomarev/php-db-migration-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonkomarev%2Fphp-db-migration-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonkomarev%2Fphp-db-migration-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonkomarev%2Fphp-db-migration-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonkomarev%2Fphp-db-migration-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonkomarev","download_url":"https://codeload.github.com/antonkomarev/php-db-migration-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonkomarev%2Fphp-db-migration-validator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266160613,"owners_count":23885883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["best-practice","best-practices","ci","database","database-migration","database-migrations","db-migration","db-migrations","irreversible-migration","php","php-library","validate","validation"],"created_at":"2024-10-10T07:14:08.290Z","updated_at":"2025-07-20T16:33:04.044Z","avatar_url":"https://github.com/antonkomarev.png","language":"PHP","readme":"# PHP DB Migration Validator\n\n![php-db-migration-validator](https://user-images.githubusercontent.com/1849174/149624430-88547f33-9a48-4124-b648-d73c82a6e869.gif)\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://discord.gg/83Yd8MgYp9\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?logo=discord\u0026label=\u0026message=Discord\u0026color=36393f\u0026style=flat-square\" alt=\"Discord\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/antonkomarev/php-db-migration-validator/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/release/antonkomarev/php-db-migration-validator.svg?style=flat-square\" alt=\"Releases\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/antonkomarev/php-db-migration-validator/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/antonkomarev/php-db-migration-validator.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\nIn modern PHP frameworks such as Symfony and Laravel, migrations usually have `up` and `down` methods.\nIn `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.\nIt is standard practice to make database migrations irreversible.\nMigrations should be backward compatible and only go forward.\n\nIn Laravel, a missing or empty `down` method does not prevent rollback migration on execution of `php artisan migrate:rollback` CLI command.\nThe state of the database will not change, but the migration will be removed from the registry of applied migrations,\nand the next execution of `php artisan migrate` will call the `up` method again.\nTo prevent this behavior, all migrations should have `down` method that will throw an Exception, nothing more.\n\nPHP DB Migration Validator checks whether all migration files meet this requirement.\nYou can add it to the server's git hooks to prevent migration rollback, or add validation step to CI.\n\n## Installation\n\nPull in the package through Composer.\n\n```shell\nphp composer require antonkomarev/php-db-migration-validator\n```\n\n## Usage\n\n### Validate migrations are irreversible\n\n**Validate file**\n\n```shell\nphp vendor/bin/php-db-migration-validator --rule=irreversible migrations/file.php\n```\n\n**Validate many files**\n\n```shell\nphp vendor/bin/php-db-migration-validator --rule=irreversible migrations/file.php migrations/file2.php\n```\n\n**Validate many files by wildcard**\n\n```shell\nphp vendor/bin/php-db-migration-validator --rule=irreversible migrations/2022_*\n```\n\n**Validate files in directory**\n\n```shell\nphp vendor/bin/php-db-migration-validator --rule=irreversible migrations/\n```\n\n**Validate files in many directories**\n\n```shell\nphp vendor/bin/php-db-migration-validator --rule=irreversible app/migrations/ vendor/migrations/\n```\n\n### CI automation\n\nAutomating the validation of all contributions to the repository as part of the Continuous Integration is one of the possible ways to use this tool.\n\n#### GitHub Action\n\nCreate file `.github/workflows/db-migration-validation.yaml` in the application repository.\n\n```yaml\nname: DB Migration Validation\n\non:\n    push:\n\njobs:\n    db-migration-validation:\n        runs-on: ubuntu-latest\n        steps:\n            - uses: actions/checkout@v2\n            - uses: shivammathur/setup-php@v2\n              with:\n                  php-version: 8.1\n                  extensions: tokenizer\n                  coverage: none\n            - name: Install PHP DB Migration Validator dependency\n              run: composer global require antonkomarev/php-db-migration-validator --no-interaction\n            - name: Ensure all database migrations are irreversible\n              run: php-db-migration-validator --rule=irreversible ./database/migrations\n```\n\n### Command usage instructions\n\n```\n$ php vendor/bin/php-db-migration-validator --help\nPHP DB Migration Validator\n--------------------------\nby Anton Komarev \u003canton@komarev.com\u003e\n\nUsage: php-db-migration-validator --rule=\u003crule\u003e \u003cpath\u003e\n\n  The following commands are available:\n\n    help  Shows this usage instructions.\n\n  Options:\n\n    --rules=\u003crule\u003e   Validates the database migration(s) in the specified \u003cpath\u003e.\n                     Exits with code 1 on validation errors, 2 on other errors and 0 on success.\n                     Available rules (at least one should be specified):\n                     - irreversible — ensure if migration file has `down` method and this method throws an Exception.\n```\n\n## License\n\n- `PHP DB Migration Validator` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev].\n\n## Support the project\n\nIf you'd like to support the development of PHP DB Migration Validator, then please consider [sponsoring me]. Thanks so much!\n\n## About CyberCog\n\n[CyberCog] is a Social Unity of enthusiasts. Research the best solutions in product \u0026 software development is our passion.\n\n- [Follow us on Twitter](https://twitter.com/cybercog)\n\n\u003ca href=\"https://cybercog.su\"\u003e\u003cimg src=\"https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png\" alt=\"CyberCog\"\u003e\u003c/a\u003e\n\n[Anton Komarev]: https://komarev.com\n[CyberCog]: https://cybercog.su\n[sponsoring me]: https://paypal.me/antonkomarev\n","funding_links":["https://paypal.me/antonkomarev"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonkomarev%2Fphp-db-migration-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonkomarev%2Fphp-db-migration-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonkomarev%2Fphp-db-migration-validator/lists"}