Skip to content

Latest commit

 

History

History
121 lines (106 loc) · 3.71 KB

README.md

File metadata and controls

121 lines (106 loc) · 3.71 KB

laravel-mysql-sync [Laravel/Lumen 5.x /6]

Build Status Latest Stable Version Test Coverage Maintainability License

This Tool allows Laravel/Lumen Developers to syncing mysql databases to the local environment from any configured environment like staging or production systems.

Requirements

Remote

- mysqldump
- openssh

Local

- mysql-client

Installation

composer require --dev n3xt0r/laravel-mysql-sync

Add your new provider to the providers array of config/app.php

    'providers' => [
        // ...
        \N3XT0R\MySqlSync\Providers\MySqlSyncServiceProvider::class,
        // ...
      ],

publish the config

php artisan vendor:publish --provider="N3XT0R\MySqlSync\Providers\MySqlSyncServiceProvider"

Lumen

Add the config from the vendor directory to your config dir manually. Dont forget to register it inside of the bootstrap/app.php.

Configuration Example

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Remote Server Connections
    |--------------------------------------------------------------------------
    |
    | These are the servers that will be accessible via the SSH task runner
    | facilities of Laravel. This feature radically simplifies executing
    | tasks on your servers, such as deploying out these applications.
    |
    */
    'connections' => [
        'production' => [
            'host' => 'example.com',
            'username' => 'myUser',
            'password' => '',
            'key' => storage_path('id_rsa'),
            'keytext' => '',
            'keyphrase' => '',
            'agent' => '',
            'timeout' => 10,
        ],
    ],
    /*
    |--------------------------------------------------------------------------
    | Remote Server Databases
    |--------------------------------------------------------------------------
    |
    | These are the databases that will be accessible for syncing.
    |
    */
    'databases' => [
        'laravel' => [
            'connection' => 'production',
            'host' => 'mysql.example.com',
            'database' => 'myApp',
            'user' => 'root',
            'password' => 'myPassword',
        ],
        'secondOptionalDb' => [
            'connection' => 'production',
            'host' => 'mysql.example.com',
            'database' => 'customerDb',
            'user' => 'root',
            'password' => 'myPassword',
        ],
    ],
    'environments' => [
        'production' => [
            /**
            * be careful, this is the same order like on importing databases
            * when you have constraints between database, set them to correct order.
            */
            'databases' => [
                'laravel',
                'secondOptionalDb',
            ],
        ],
    ],
    /**
    * originally it should be the storage dir
    * but you could configure any other directory, too.
    */
    'storage' => storage_path(), 
];

Execute syncing

php artisan db:sync --stage=production