n3xt0r/laravel-migration-generator
Composer 安装命令:
composer require n3xt0r/laravel-migration-generator
包简介
create migrations from database
README 文档
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 12-13 and PHP 8.3–8.5.
📦 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–13 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
- 🧠 Optional schema normalization (via
--normalizer=), including:- Synthetic primary keys for legacy tables with composite keys
- Automatic preservation of uniqueness constraints
- Better Eloquent compatibility for complex schemas
🔍 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–13 (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 | 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.3.0 >= 8.0.0 | ❌ EOL |
| 11.x | 8.2 – 8.4 | 6.0.0 | ❌ EOL |
| 11.x | 8.2 – 8.4 | 8.x | ❌ EOL |
| 12.x | 8.2 – 8.4 | 7.0.0 | ❌ EOL |
| 12.x | 8.2 – 8.5 | 8.x | ⚠️ Security fixes only |
| 13.x | 8.3 – 8.5 | 9.x | ✅ 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.3
pdo_mysql,pdo_pgsqlorpdo_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.
🧰 Schema Normalizers
Schema Normalizers are optional pre-processing steps that transform your database schema before migration generation. They can help adapt legacy structures for better Laravel compatibility.
Available Normalizers
| Normalizer | Description |
|---|---|
pivot |
Replaces composite primary keys with a synthetic auto-incrementing id() column and converts the original composite key into a named unique() constraint. Useful for legacy tables incompatible with Eloquent. |
Usage
Enable a normalizer via CLI:
php artisan migrate:regenerate --normalizer=pivot
Or configure it in config/migration-generator.php:
'normalizer' => [ 'enabled' => ['pivot'], ],
🧪 Testing
To run the tests:
# mysql 5.7 DB_CONNECTION=mysql DB_HOST=db_migration DB_PASSWORD=your_password ./vendor/bin/phpunit # mysql 8 DB_CONNECTION=mysql DB_HOST=mysql8 DB_PASSWORD=your_password ./vendor/bin/phpunit #postgres DB_CONNECTION=pgsql DB_HOST=postgres DB_PASSWORD=your_password ./vendor/bin/phpunit # mssql DB_CONNECTION=sqlsrv DB_HOST=mssql DB_PASSWORD=your_password ./vendor/bin/phpunit
Docker and CI pipelines are already integrated for continuous validation and quality assurance.
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
This README reflects the repository’s current features, including explicit support for MySQL, PostgreSQL and MSSQL, correct PDO extensions and updated CI information.
n3xt0r/laravel-migration-generator 适用场景与选型建议
n3xt0r/laravel-migration-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 867 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「migrations」 「laravel」 「migration-generator」 「referential integrity」 「php 8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 n3xt0r/laravel-migration-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 n3xt0r/laravel-migration-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 n3xt0r/laravel-migration-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Migration generator for Hyperf.
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
Laravel table comments loader (part of Diplodocker project)
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
Alfabank REST API integration
统计信息
- 总下载量: 867
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-03