xethron / migrations-generator
从现有数据库生成Laravel迁移
Requires
- php: >=5.4.0
- doctrine/dbal: ~2.4
- illuminate/support: >=4.1
- xethron/laravel-4-generators: ~3.1.0
Requires (Dev)
- illuminate/cache: >=4.1.0
- illuminate/console: >=4.1.0
- mockery/mockery: >=0.9.0
- phpunit/phpunit: >=4.0.0
README
从现有数据库生成Laravel迁移,包括索引和外键!
Laravel 5.4 升级
请注意,Laravel 4 生成器的编辑已经移动到 https://github.com/xethron/Laravel-4-Generators.git
以更新兼容性。
Laravel 5 安装
推荐通过composer安装
composer require --dev "xethron/migrations-generator"
In Laravel 5.5 the service providers will automatically get registered.
In older versions of the framework edit config/app.php
and add this to providers section
Way\Generators\GeneratorsServiceProvider::class, Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,
If you want this lib only for dev, you can add the following code to your app/Providers/AppServiceProvider.php
file, within the register()
method
public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Way\Generators\GeneratorsServiceProvider::class); $this->app->register(\Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class); } // ... }
备注
- 感谢 @jamisonvalenta,你现在可以在Laravel 5中生成迁移了!
feature/laravel-five-stable
是从way/generators
3.0.3
分叉而来,并已为Laravel5.0
做准备。Jeffrey Way已停止对Laravel 5的支持,因此其他artisan generate:
命令可能没有与5.0
兼容。调查artisan make:
命令的替代方案,为Laravel贡献以扩展生成支持,或修复并提交PR到jamisonvalenta/feature/laravel-five-stable
。
Laravel 4 安装
运行以下composer命令
composer require --dev "xethron/migrations-generator:~1.3.0"
接下来,添加以下服务提供者
'Way\Generators\GeneratorsServiceProvider', 'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
这样你就设置好了。为了确保它正在工作,运行php artisan
,并查找命令migrate:generate
用法
要从数据库生成迁移,您需要在Laravel的配置中设置您的数据库。
运行php artisan migrate:generate
来创建所有表的迁移,或者您可以使用php artisan migrate:generate table1,table2,table3,table4,table5
指定您想要生成的表。您也可以使用--ignore="table3,table4,table5"
忽略表。
Laravel Migrations Generator将首先生成所有表、列和索引,然后设置所有外键约束。因此,请确保包含外键中列出的所有表,以便在创建外键时它们都存在。
如果您没有使用默认连接,可以使用--connection="connection_name"
指定连接名称
运行php artisan help migrate:generate
以获取选项列表。
查看Chung Tran的博客文章以获取快速的分步介绍: 在Laravel 4中从现有数据库生成迁移
变更日志
Laravel Migrations Generator的变更日志
2016年11月20日:v2.0.0
- Laravel 5支持
2016年11月20日:v1.3.0
- 添加选项--defaultIndexNames和--defaultFKNames以使用Laravel的默认生成名称
- 支持--no-interaction
- 迁移表字段注释
- 如果不是默认连接,将连接添加到迁移中
- 错误修正
- --ignore不忽略列表中的第一个表
- 从索引名称中移除反引号#17
- 错误地使用键名删除外键#34
- 从迁移中移除表前缀
- 转义表名和参数
- 将JSON列映射为文本
- 布尔默认值导致空字符串
2016年7月25日:v1.2.2
- 支持 Laravel 4.2
- 支持命名外键
- 修复 --ignore 选项的错误
5月29日:v1.2.1
- 修复了字符字段显示为 varchar 的问题
- 允许十进制、浮点型和双精度型为无符号
- 允许外键更新/删除时级联
5月16日:v1.2.0
- 现在完全支持枚举字段
- 添加对位字段作为布尔值的支持(Laravel 迁移限制)
5月10日:v1.1.1
- 修复迁移使用枚举字段的表时崩溃的问题
- 添加了测试
- 对代码进行重大重构
3月24日:v1.1.0
- 能够向迁移表添加条目,这样它们就不会像已存在的那样运行。
- 将 Blob 转换为二进制字段
- 少量代码更改
感谢
感谢 Jeffrey Way 的出色 Laravel-4-Generators 包。此包在很大程度上依赖于他的工作。
贡献者
Bernhard Breytenbach (@BBreyten)
许可证
Laravel 迁移生成器是开源软件,许可证为 MIT 许可证