Looking to hire Laravel developers? Try LaraJobs

laravel-sync maintained by ldavidsp

Description
Synchronize your local or stage database with the production one.
Last update
2023/11/23 00:04 (dev-main)
License
Downloads
282
Tags

Comments
comments powered by Disqus

Laravel Sync Database

Latest Version on Packagist Software License Total Downloads

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.