n3xt0r / laravel-migration-generator
create migrations from database
Requires
- php: ^8.2
- ext-pdo_mysql: *
- doctrine/dbal: ^3.0
- laravel/framework: ^10.0 || ^11.0 || ^12.0
- marcj/topsort: ^1.1
Requires (Dev)
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0
- phpunit/phpunit: ^10.0 || ^11.0
- dev-master
- 8.0.1
- 8.0.0
- 7.2.0
- 7.1.0
- 7.0.0
- 6.0.0
- 5.0.0
- 4.0.2
- 4.0.1
- 4.0.0
- 3.0.0
- 2.0.0
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feature/7-schema-normalization
- dev-dev-8.x
- dev-develop
- dev-feature/1-model-generator
- dev-dependabot/composer/doctrine/dbal-tw-3.0or-tw-4.0
- dev-dependabot/composer/marcj/topsort-tw-1.1or-tw-2.0
- dev-feature/multi-db-support
- dev-dev-7.x
- dev-dev-6.x
- dev-dev-5.x
This package is auto-updated.
Last update: 2025-06-21 14:05:22 UTC
README
π§± Original project launched in May 2020. Recently reactivated and extended with full CI coverage and support for PostgreSQL, MariaDB, MSSQL and MySQL 8.
β CI: Successfully tested across MySQL 5.7/8.0, PostgreSQL 15, and MSSQL 2022 β on Laravel 10β12 and PHP 8.2β8.4.
π¦ Overview
Laravel Migration Generator
A powerful CLI tool to generate Laravel migration files from an existing MySQL, PostgreSQL or MSSQL database.
This tool provides a structured and extensible approach to reverseβengineering database schemas into Laravelβcompatible migration files. It supports foreign key constraints, correct dependency order and customizable mapping logic β enabling seamless integration into both legacy and modern Laravel projects (Laravel 5β12 supported).
β¨ Features
- β Detects tables, columns, indexes and foreign keys with precision
- π Automatically orders migrations to maintain referential integrity
- π§± Extensible design via modular definition/mapping architecture
- π§© Supports Laravel 5 to 12 (EOL versions maintained in readβonly mode)
- π Clean, testable and maintainable codebase
π Feature Comparison
Feature / Tool | This Package (N3XT0R) | kitloong | bennettβtreptow | Xethron |
---|---|---|---|---|
π οΈ Supported Databases | β MySQL, PostgreSQL, MSSQL | β MySQL, PostgreSQL, MSSQL, SQLite | β MySQL only | β MySQL only |
β Laravel Compatibility | β 5β12 (version-aware testing) | β 5β10+ | β οΈ up to Laravel 11 | β Legacy only |
π§ͺ CI/CD with Matrix Testing | β Full GitHub Actions matrix | β Partial | β Partial | β None |
π§© Extensible Mapping Architecture | β Yes (definition + mapping layers) | β Monolithic | β No | β No |
π Actively Maintained | β Yes (since 2023) | β Yes | β Partially | β No |
π PostgreSQL Support | β Yes | β Yes | β No | β No |
πͺ MSSQL Support | β Yes | β Yes | β No | β No |
π‘ Primary Use Case | β Modern & legacy DB export | βοΈ Feature-rich | π§± MySQL legacy only | π°οΈ Historical tool |
TL;DR: If you need clean, testable, and modern Laravel migration exports across multiple DB engines β this tool is a solid and extensible choice.
π Version Compatibility
Laravel/Lumen | PHP Version | Generator Version | Status |
---|---|---|---|
5.x | 7.2 β 7.4 | 1.0.10 | β EOL |
6.x | 7.2 β 7.4 | 1.0.10 | β EOL |
7.x | 7.2 β 8.0 | 2.0.0 | β EOL |
8.x | 7.3 β 8.0 | 3.0.0 | β EOL |
9.x | 8.0 | 4.0.0 | β EOL |
10.x | 8.1 β 8.3 | 5.0.0 | β EOL |
10.x | 8.1 β 8.3 | 8.0.0 | β Supported |
11.x | 8.2 β 8.4 | 6.0.0 | β EOL |
11.x | 8.2 β 8.4 | 8.0.0 | β Supported |
12.x | 8.2 β 8.4 | 7.0.0 | β EOL |
12.x | 8.2 β 8.4 | 8.0.0 | β Supported |
β οΈ Important: Version 8.0.0 introduces breaking API changes for Laravel 10β12.
All supported Laravel versions receive the new features and updated APIs, requiring updates to dependent code.
β Database Compatibility
The generator works with all major engines:
MySQL
Version | Status |
---|---|
5.7 | β Supported |
8.0 | β Supported |
PostgreSQL
Version | Status |
---|---|
15 | β Supported |
MSSQL
Version | Status |
---|---|
2022-latest | β Supported |
EOL database versions remain functional for legacy compatibility.
β Requirements
- PHP β₯ 8.2
pdo_mysql
,pdo_pgsql
orpdo_sqlsrv
(depending on your database)
- MySQL β₯ 5.7, PostgreSQL 15 or MSSQL 2022
π§° Installation
Install the package via Composer:
composer require n3xt0r/laravel-migration-generator --dev
Laravel will auto-discover the service provider. No manual registration is needed.
For Lumen, register the service provider manually in bootstrap/app.php
:
$app->register(\N3XT0R\MigrationGenerator\Providers\MigrationGeneratorServiceProvider::class);
π Usage
Run the migration generator via Artisan:
php artisan migrate:regenerate
This command will generate migration files from your existing database schema into the database/migrations/
folder.
The files will be ordered automatically to maintain referential integrity β no manual reordering required.
βοΈ Custom Export Strategy
If the default export does not meet your needs, the generator is fully extensible. You can override the export logic through Laravel's Dependency Injection container.
π§ Configuration
First, publish the configuration file:
php artisan vendor:publish --tag=migration-generator-config
Edit config/migration-generator.php
to adjust or override definitions and mappings.
π§© Export Architecture
The export process is divided into two customizable layers:
Definition Classes
These classes extract schema information into a universal, internal representation. This format is decoupled from Laravel and can be reused, extended, or mapped differently.
Mapping Classes
These classes transform the internal representation into valid Laravel migration code (PHP). You can override them to adjust formatting, naming conventions, or structure.
π§ͺ Testing
To run the tests:
# mysql 5.7 DB_CONNECTION=mysql DB_HOST=db_migration DB_PASSWORD=dein_db_passwort ./vendor/bin/phpunit # mysql 8 DB_CONNECTION=mysql DB_HOST=mysql8 DB_PASSWORD=dein_db_passwort ./vendor/bin/phpunit #postgres DB_CONNECTION=pgsql DB_HOST=postgres DB_PASSWORD=dein_db_passwort ./vendor/bin/phpunit # mssql DB_CONNECTION=sqlsrv DB_HOST=mssql DB_PASSWORD=dein_db_passwort ./vendor/bin/phpunit
Docker and CI pipelines are already integrated for continuous validation and quality assurance.
β CI Test Matrix
This package undergoes continuous integration with GitHub Actions, running tests on an extensive environment matrix covering Laravel, PHP, and MySQL versions to guarantee robust compatibility and stability.
Laravel Version | PHP Versions | MySQL Versions | Number of Jobs |
---|---|---|---|
10 | 8.2, 8.3 | 5.7, 8.0 | 4 |
11 | 8.2, 8.3, 8.4 | 5.7, 8.0 | 6 |
12 | 8.2, 8.3, 8.4 | 5.7, 8.0 | 6 |
Total: 16 unique MySQL jobs plus additional tests for PostgreSQL and MSSQL.
Key CI features include:
- Dynamic installation of Laravel versions during test runs via Composer.
- Support for PHPUnit 10 and 11, automatically selected per Laravel version.
- Full code coverage reporting with Xdebug and Clover.
- Version-aware assertions adapting test expectations based on Laravel version.
βΉοΈ Composer Compatibility Strategy
Although the root composer.json
targets Laravel 12 by default, earlier Laravel versions (10, 11) are tested in CI
using dynamic version installation:
run: composer require laravel/framework:^${{ matrix.laravel }} --no-interaction --no-update
This ensures flexible version handling while keeping the default installation aligned with the latest stable Laravel release.
π§ͺ Version-Aware Assertions
Table-based tests (e.g., migration sorting or detection) dynamically adjust expected values based on the Laravel version:
$expectedTables = match (true) { str_starts_with(Application::VERSION, '10.') => [...], default => [...], // Laravel 11+ };
π License
This project is licensed under the MIT License.
π Contributions
Contributions are welcome! Feel free to open issues or submit pull requests to improve the generator, add new database support or enhance the customization layers.
π Links
- π¦ Packagist Package
- π§ͺ CI & Test Coverage
- π Laravel Documentation
This README reflects the repositoryβs current features, including explicit support for MySQL, PostgreSQL and MSSQL, correct PDO extensions and updated CI information.