This packages overhaul laravel's migration with a table absolute state approach instead of a change state approach. What this means? This means that you tell the migration how you want your tables, and it will take care of syncing it with your database, you do not need to tell it how. So you don't have to keep dozens of files that describes changes, just one for your table. Order is not important, because foreign keys and such, are organized to be placed at the end of the migration, so you can be sure all tables were created before it runs.
This is a typical installation Laravel package installation, you can run as follows:
composer require aposoftworks/lohm
Add our provider to the config/app.php to enable it:
'providers' => [
[...]
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
\Aposoftworks\LOHM\Providers\LohmServiceProvider::class,
],
Since the migrations are table based and not change based, you can create only one migration per table. You can also customize it's classname in the configuration file (don't forget to publish it). You can also change the directory that they are placed, so you don't overlap it with laravel's default migration.
php artisan make:table Core\User
If you want to run the migrations, simply run migrate:sync
, this will get the latest version of your migrations and run them. Since we keep in cache what is currently in the database, we compare the missing fields and make the changes accordingly. But beware that some operations can break the database, such as removing fields that are required for foreign keys, or adding values to foreign keys that don't match.
If you would like to change any configuration regarding the package, you can publish it using:
php artisan vendor:publish --tag=lohm-config
You can see that everything is pretty much configurable, file/directory names, cache options, so you can keep it to your taste.
You can also customize the stub used to create the migration using:
php artisan vendor:publish --tag=lohm-stub
It will be placed inside resources/stubs/lohm.php
- make:table {classname} {name?} {--T|template=default}
Creates a table migration
- migrate:sync
Will compare the migrations with the database and apply the differences
- analyze {database?} {table?} {column?}
Will analyze the migrations data
- analyze:current
Will analyze the current database
- analyze:diff {database?} {table?}
Will show the differences between database and migrations without applying it
- migrate:clear
Will clear the database using our custom migrations
With LOHM you can write custom migrations to use as templates when creating new ones, after publishing the default one (using: php artisan vendor:publish --tag=lohm-stub
), you change "default" with the name you want to use and you are good to go. For example, you can use php artisan make:table User --template=user
to use the lohm.user.php
stub.
[ ] Add support for multiple indexes
[x] Add diff command
[x] Add support for removing fields that are not necessary anymore
[x] Add sync functionality
[x] Add support for indexes
[x] Add support for foreign keys
[x] Add analyze command