yui019/hori
Composer 安装命令:
composer require yui019/hori
包简介
Database schema library for Laravel inspired by Prisma.
README 文档
README
Database schema library for Laravel inspired by Prisma.
How is this different from normal laravel migrations?
In case you've never used the NodeJS library Prisma, what it does is that it handles creating migrations for you. You have a single schema file where you write all the tables you have and migrations to add/drop tables or columns are automatically generated according to it.
So if you want to remove a column from a table, all you need to do is remove it in the schema file and run php artisan hori:generate, which automatically generates a migration that removes that column.
There's 2 advantages to this approach:
- It's much easier and faster for you to directly work on a single schema file than to manually create migrations for each change
- You don't need to look at all migrations or the database to know what tables and rows you currently have - you just look at the schema file instead
Usage
You can install Hori with the command:
composer require yui019/hori
After that, you run:
php artisan hori:install
which will create a hori directory in the database directory with a schema.php file inside.
This is what that file looks like by default:
<?php use Illuminate\Database\Schema\Blueprint; use Yui019\Hori\Schema; return new class extends Schema { public function create(): void { $this->table('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); $this->createDefaultLaravelTables(); // ... } };
The $this->createDefaultLaravelTables() line creates the default laravel tables such as password_reset_tokens, cache, jobs, etc. - i.e. all tables created by the 3 migrations present by default in every laravel project, except for the users table.
That table is created in the schema.php file right above instead. The reason why I made this choice is that it's very common to want to change something about the default users table, whereas all the other ones are left as is 99% of the time, and it felt too cramped to have all those tables in there by default.
This command also deletes those 3 default migrations. You can optionally pass the --dont-delete-default-migrations option to avoid that.
Next, you run the command:
php artisan hori:generate
and give it a name for the migration.
This will create a migration in the database/migrations directory which will create all those tables.
Now, say you want to add a photo column to the users table. Normally, you would need to manually create an add_photo_column migration which adds the column (and drops it in the down method).
With Hori, all you do is add a line such as $table->string('photo'); to the schema file and run php artisan hori:generate again. This will automatically create a migration which does the same thing.
Features
- Creating tables
- Modifying tables
- Dropping tables
- Renaming tables
- Adding columns
- Dropping columns
- Adding foreign key constraints
- Changing columns
- Renaming columns
- Automatic reordering of created tables according to foreign key constraints
- Automatically generate models and controllers from schema
- Automatically generate Laravel Filament resources from schema (maybe like a separate library?)
yui019/hori 适用场景与选型建议
yui019/hori 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yui019/hori 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yui019/hori 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 130
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-06-17