Download the PHP package yui019/hori without Composer
On this page you can find all versions of the php package yui019/hori. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package hori
Short Description Database schema library for Laravel inspired by Prisma.
License
Homepage https://github.com/yui019/hori
Informations about the package hori
Hori
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:
After that, you run:
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:
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:
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
- [x] Creating tables
- [x] Modifying tables
- [x] Dropping tables
- [ ] Renaming tables
- [x] Adding columns
- [x] Dropping columns
- [x] Adding foreign key constraints
- [ ] Changing columns
- [ ] Renaming columns
- [x] 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?)