Skip to content

Latest commit

 

History

History
112 lines (75 loc) · 3.7 KB

README.md

File metadata and controls

112 lines (75 loc) · 3.7 KB

Laravel Synchronize

Build Status Downloads Code Intelligence Status Scrutinizer Code Quality StyleCi

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.