mybizna/automigrator
Composer 安装命令:
composer require mybizna/automigrator
包简介
Declare database migrations and factory definitions inside Laravel models.
README 文档
README
This package allows you to declare database migrations and factory definitions inside of your Laravel models.
Running the automigrator:migrate command will automatically apply any changes you've made inside your migration methods to the database via Doctrine DBAL. If using the HasNewFactory trait and definition method, it will use the returned array inside the definition method to seed with when using the -s option.
The automigrator:migrate command will also run your file-based (traditional) Laravel migrations first, and then your model method migrations after. If you need your model-based migrations to run in a specific order, you may add a $migrationOrder property to your models with an integer value (default is 0).
Installation
Require this package via Composer:
composer require mybizna/automigrator
Usage
Use the HasNewFactory trait, and declare migration and definition methods in your models:
use Faker\Generator; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Mybizna\Automigrator\Traits\HasNewFactory; class MyModel extends Model { use HasNewFactory; protected $guarded = []; protected $migrationOrder = 1; // optional public function migration(Blueprint $table) { $table->id(); $table->string('name'); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); } public function definition(Generator $faker) { return [ 'name' => $faker->name(), 'created_at' => $faker->dateTimeThisMonth(), ]; } }
Commands
Migrating
Apply the changes inside your migration methods to your database:
php artisan automigrator:migrate {--f|--fresh} {--s|--seed}
Use the -f option for fresh migrations, and/or the -s option to run seeders afterwards.
Making Models
Create a model containing the migration and definition methods:
php artisan automigrator:model {name} {--r|--resource}
Use the -r option to create a Laravel Nova resource for the model at the same time.
Making Nova Resources
Create a Laravel Nova resource without all the comments:
php artisan automigrator:resource {name} {--m|--model}
Use the -m option to create a model for the Nova resource at the same time.
mybizna/automigrator 适用场景与选型建议
mybizna/automigrator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.28k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migrations」 「php」 「factory」 「laravel」 「models」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mybizna/automigrator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mybizna/automigrator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mybizna/automigrator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Laravel table comments loader (part of Diplodocker project)
统计信息
- 总下载量: 1.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-02