human018/laravel-patch

Perform migrations and database patches within your Laravel application

0.0.6 2022-06-05 05:06 UTC

This package is auto-updated.

Last update: 2024-05-05 09:00:27 UTC


README

Contributors Forks Stargazers Issues MIT License

Laravel Patch

Perform migrations and database patches within your Laravel application

At times you may need to run a database migration and then perform some kind of patch associated with the migration. This package will create both the migration and an associated patch command, it will listen for the migration event and then run the patch command automatically for you.

When might you use this package?

Example 1:

You're changing a model relationship to an immediate relationship (hasMany) rather than a distant relation (hasManyThrough). You need to add a new foreignId column to the target models table and then populate that column with the correct ID's. With this package you can create both the migration and the patch command and then run them within the same migration command.

Index

Usage

Requirements

  • PHP 7.4
  • Laravel 8

Download & Installation

$ composer require human018/laravel-patch

Laravel will auto discover the package.

Performing Patches

Once installed a patch can be created by running the following command in line with the regular Laravel make:migration command.

$ php artisan make:patch {name} {table|create}

This will generate both the migration and an associated patch command.

The package listens for when a migration event is fired, determines if there is an associated patch command and fires the command.

You will find Patch commands created in your projects 'Commands' folder under the subdirectory 'Patches', where you can perform any tasks that need to be done in line with this migration.

Migration Direction

The migration direction is passed to the Patch Command using the 'method' option.

$this->input->getOption('method'); // Returns 'up' or 'down'

So if you need to revert some changes you can detect the 'down' direction.

License

This project is licensed under the MIT License