eyf/laravel-exodus
Composer 安装命令:
composer require eyf/laravel-exodus
包简介
Laravel YAML migrations
README 文档
README
Converts YAML to actual Laravel migration files.
Install
composer require --dev eyf/laravel-exodus
Usage
Step 1: Create database/migrations.yaml file
Define a posts table:
# database/migrations.yaml posts: id: true timestamps: true softDeletes: true slug: string(100).unique title: string content: text excerpt: string.nullable author_id: foreignId.constrained('users')
Step 2: Make migrations (command)
Run exodus command to translate the yaml file into actual Laravel migration files:
php artisan exodus Created Migration: 2020_05_05_100005_create_posts_table
Step 3: migrate as normal
php artisan migrate
Workflow
Exodus is a DEV package, it is meant to ease / speed up development time.
A normal workflow while DEV'ing could be:
- Create
migrations.yamlfile (Add apoststable) php artisan exodusphp artisan migrate- Edit
migrations.yamlfile (Add auserstable) php artisan exodusphp artisan migrate:refresh (--seed)- Edit
migrations.yamlfile - ... (Repeat)
The exodus.lock file
By default the migration file names won't change between multiple exodus runs.
This is because Exodus keeps track of the initial migration file name in database/exodus.lock (to commit in your repository).
This makes sure git sees the edits in the same migration file throughout the whole DEV.
The force option
Sometimes you may want to bypass the exodus.lock file (For example when you want to change the table order creation).
php artisan exodus --force
What happens:
- All "old" migration files will be deleted (the ones in current
exodus.lock) - New migration files will be generated (with newest date in filename)
Syntax
Column
Any column can be written fluently exactly like in the Laravel migration syntax. In fact Exodus is just a light translator of a "dot notation" array to the actual PHP syntax.
my_table: my_column_name: string(50).nullable.unique
Special column
Special column types are the "sugar" methods provided by Laravel for a better developer experience: id(), timestamps(), softDeletes(), rememberToken(), etc...
Since these column types don't have a column name (name is in the convention), just specify true as their value:
my_table: id: true timestamps: true softDeletes: true
Pivot tables
For generating a pivot table, just use two table names as follow:
users: id: true name: string posts: id: true title: string "@users @posts": []
This will create the following pivot migration file:
<?php // database/migrations/2020_05_05_085245_create_post_user_pivot_table.php class CreatePostUserPivotTable extends Migration { public function up() { Schema::create("post_user", function (Blueprint $table) { $table ->foreignId("post_id") ->index() ->constrained(); $table ->foreignId("user_id") ->index() ->constrained(); $table->primary(["post_id", "user_id"]); }); } public function down() { Schema::dropIfExists("post_user"); } }
You can even provide more columns to the pivot table as normal:
"@users @posts": timestamps: true approved_by: foreignId.nullable.constrained('users') approved_at: timestamp.nullable
Phylosophy
This package aims at speedind up development time. It is not meant to be used after you have launched to production. In fact the package does not provide a way to run migrations for adding or removing columns (it used to).
This is by choice.
While DEV'ing you should edit the migrations.yaml file as much as you want and run migrate:refresh (--seed) as often as possible. "This is the way".
By the time you are happy with your Schema, you must have launched in production, and then only you may create normal Laravel migration files for adding or removing column(s) in your tables. This is where the job of this package ends.
TODO: Implement safety guard making sure exodus cannot be run if it detects more migrations files than in exodus.lock.
eyf/laravel-exodus 适用场景与选型建议
eyf/laravel-exodus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 108 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migrations」 「yaml」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eyf/laravel-exodus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eyf/laravel-exodus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eyf/laravel-exodus 相关的其它包
同方向 / 同关键字的高下载量 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)
统计信息
- 总下载量: 108
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-01