kitloong/laravel-migrations-generator
Composer 安装命令:
composer require kitloong/laravel-migrations-generator
包简介
Generates Laravel Migrations from an existing database
README 文档
README
Generate Laravel Migrations from an existing database, including indexes and foreign keys!
Documentation
Checkout the documentation for more details.
Supported Database
Laravel Migrations Generator supports all five Laravel first-party support databases:
- MariaDB
- MySQL
- PostgreSQL
- SQL Server
- SQLite
Install
The recommended way to install this is through composer:
composer require --dev kitloong/laravel-migrations-generator
Laravel Setup
Laravel will automatically register service provider for you.
Lumen Setup
Expand
Auto-discovery is not available in Lumen, you need some modification on bootstrap/app.php.
Enable Facade
Uncomment the following line.
$app->withFacades();
Register Provider
Add following line into the Register Service Providers section.
$app->register(\KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);
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 afterward 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
Options
Run php artisan help migrate:generate for a list of options.
| Options | Description |
|---|---|
| -c, --connection[=CONNECTION] | The database connection to use |
| -t, --tables[=TABLES] | A list of tables or views you wish to generate migrations for separated by a comma: users,posts,comments |
| -i, --ignore[=IGNORE] | A list of tables or views you wish to ignore, separated by a comma: users,posts,comments |
| -p, --path[=PATH] | Where should the file be created? |
| -tp, --template-path[=TEMPLATE-PATH] | The location of the template for this generator |
| --date[=DATE] | Migrations will be created with specified date. Views and foreign keys will be created with + 1 second. Date should be in format supported by Carbon::parse |
| --table-filename[=TABLE-FILENAME] | Define table migration filename, default pattern: [datetime]\_create_[name]_table.php |
| --view-filename[=VIEW-FILENAME] | Define view migration filename, default pattern: [datetime]\_create_[name]_view.php |
| --proc-filename[=PROC-FILENAME] | Define stored procedure filename, default pattern: [datetime]\_create_[name]_proc.php |
| --fk-filename[=FK-FILENAME] | Define foreign key migration filename, default pattern: [datetime]\_add_foreign_keys_to_[name]_table.php |
| --log-with-batch[=LOG-WITH-BATCH] | Log migrations with given batch number. We recommend using batch number 0 so that it becomes the first migration |
| --default-index-names | Don't use DB index names for migrations |
| --default-fk-names | Don't use DB foreign key names for migrations |
| --use-db-collation | Generate migrations with existing DB collation |
| --skip-log | Don't log into migrations table |
| --skip-vendor | Don't generate vendor migrations |
| --skip-views | Don't generate views |
| --skip-proc | Don't generate stored procedures |
| --skip-foreign-keys | Don't generate foreign keys |
| --squash | Generate all migrations into a single file |
| --with-has-table | Check for the existence of a table using hasTable |
Thank You
Thanks to Bernhard Breytenbach for his great work. This package is based on https://github.com/Xethron/migrations-generator.
Our Amazing Sponsor 🎉
A huge thank you to our sponsor for supporting this project!
Want to support this project? Become a sponsor today!
Contributors
License
The Laravel Migrations Generator is open-sourced software licensed under the MIT license
kitloong/laravel-migrations-generator 适用场景与选型建议
kitloong/laravel-migrations-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.34M 次下载、GitHub Stars 达 2.86k, 最近一次更新时间为 2020 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「migrations」 「generator」 「migration」 「laravel」 「artisan」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kitloong/laravel-migrations-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kitloong/laravel-migrations-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kitloong/laravel-migrations-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
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)
Lets you add foreign keys in a swift! Foreign key adder in laravel migration.
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.
统计信息
- 总下载量: 8.34M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2878
- 点击次数: 23
- 依赖项目数: 29
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-20