laravel-sync maintained by ldavidsp
Laravel Sync Database
This package contains some useful Artisan commands to work the synchronization of the local database with the production one.
Requirements
This package requires Laravel 6 or newer.
Installation
You can install the package via Composer:
composer require ldavidsp/laravel-sync
Publish the config file with:
php artisan vendor:publish --tag=sync-config
Add tables to synchronize in config/sync.php:
/*
|--------------------------------------------------------------------------
| Sync tables
|--------------------------------------------------------------------------
*/
'sync_tables' => [
'table_name_1',
],
Add the configuration for the production database to config/database.php:
'live-db' => [
'driver' => env('DB_LIVE_CONNECTION', 'mysql'),
'host' => env('DB_LIVE_HOST', 'your live server database host here'),
'port' => env('DB_LIVE_PORT', '3306'),
'database' => env('DB_LIVE_DATABASE', 'forge'),
'username' => env('DB_LIVE_USERNAME', 'forge'),
'password' => env('DB_LIVE_PASSWORD', ''),
],
Add the configuration in .env:
DB_LIVE_CONNECTION=mysql
DB_LIVE_HOST=
DB_LIVE_PORT=3306
DB_LIVE_DATABASE=
DB_LIVE_USERNAME=
DB_LIVE_PASSWORD=
Usage
Synchronize database:
php artisan sync:prod
or
Add the configuration in app/Console/Kernel.php:
/**
* Sync local database with production.
*/
if (App::environment('local')) {
$schedule->command('sync:prod')->everyTenMinutes();
}
License
The MIT License (MIT). Please see License File for more information.