接盘侠必备 Laravel migration 逆向生成工具
同类型的文章(旧包支持到LV5.6)
031. 逆向 Migration 生成器 ——xethron/migrations-generator
下面这个新包,香的地方是已经支持到 Laravel 9.x
Laravel Migrations Generator
github.com/kitloong/laravel-migrat...
Generate Laravel Migrations from an existing database, including indexes and foreign keys!
This package is cloned from github.com/Xethron/migrations-gene... and updated to support Laravel 5.6 and above, with more features.
Supported Database
Laravel Migrations Generator supports all five Laravel first-party support databases:
- MariaDB
- MySQL
- PostgreSQL
- SQL Server
- SQLite
Version Compatibility
Laravel | Version |
---|---|
9.x | 6.x |
8.x | 6.x |
7.x | 6.x |
6.x | 6.x |
5.8.x | 6.x |
5.7.x | 6.x |
5.6.x | 6.x |
5.5 and below | github.com/Xethron/migrations-gene... |
Install
The recommended way to install this is through composer:
composer require --dev kitloong/laravel-migrations-generator
Usage
To generate migrations from a database, you need to have your database setup in Laravel’s config (config/database.php
).
To create migrations for all the tables, run:
php artisan migrate:generate
You can specify the tables you wish to generate using:
php artisan migrate:generate --tables="table1,table2,table3,table4,table5"
You can also ignore tables with:
php artisan migrate:generate --ignore="table3,table4,table5"
Laravel Migrations Generator will first generate all the tables, columns and indexes, and afterwards setup all the foreign key constraints.
So make sure you include all the tables listed in the foreign keys so that they are present when the foreign keys are created.
You can also specify the connection name if you are not using your default connection with:
php artisan migrate:generate --connection="connection_name"
Squash Migrations
By default, Generator will generate multiple migration files for each table.
You can squash all migrations into a single file with:
php artisan migrate:generate --squash
本作品采用《CC 协议》,转载必须注明作者和本文链接