netcreaties / laravel-synchronize
Laravel Synchronizations will enable you to create one time synchronizations and prevent creating commands you only use once
Installs: 10 023
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 0
Requires (Dev)
- matthewbdaly/artisan-standalone: 0.0.*
- mockery/mockery: ~1.0
- orchestra/testbench: ^3.7
- orchestra/testbench-browser-kit: ^3.7
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.10.5
- phpunit/phpunit: ^7.0
- psy/psysh: ^0.9.8
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: ^3.3
README
This package gives you the ability to create synchronization files and prevent you from having to write one time use commands when you've got for example: A database structure change that will require you to synchronize the old structure data with the new structure.
Documentation
Installation
The best way to install this package is through your terminal via Composer.
Run the following command from your projects root
composer require netcreaties/laravel-synchronize
Laravel 5.5+
This package supports package discovery.
Execute migrations
Getting started
Publish config (optional)
Publishing the config will enable you to overwrite some of the settings this package uses. For example you can define where synchronization files should be stored.
php artisan vendor:publish --provider="LaravelSynchronize\Providers\ServiceProvider" --tag="config"
Publish migration
php artisan vendor:publish --provider="LaravelSynchronize\Providers\ServiceProvider" --tag="migrations"
Execute migrations
php artisan migrate
Usage
Laravel Synchronize executes synchronizations that have the same class name as the migration class name, but with a Synchronization suffix, when executing migrations. This is the advised usage to ensure database integrity, but it is possible to execute synchronizations on their own (see section Synchronize command).
Make command
php artisan make:synchronization {name}
Creates the synchronization file at database/synchronizations
Synchronize command
php artisan synchronize
Using --class and --force
It can happen you need a synchronization before you can perform a migration. Using --class and --force can help you achieving that goal.
All you need to do is using the Laravel 5.8.16+ Migration events.
Example:
public function __construct() { Event::listen(MigrationStarted::class, function (MigrationStarted $listener) { if ($listener->migration instanceof $this && $listener->method === 'up') { Artisan::call('synchronize --class=TestASync --force'); echo Artisan::output(); } }); }
--force
--force will execute the synchronization even when it already has been run. Use with caution.