therealsmat / laravel-push-db
:Laravel package to enable easy database exports
Requires
- php: ~5.6|~7.0
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-11-01 23:34:38 UTC
README
This package allows you to easily export your database. It also provides an artisan command, php artisan db:push
to make the process simpler. You can either run manually from the console or use with Laravel scheduler. It's totally a matter of choice.
Requirements
PHP 5.4+, Composer are required.
Installation
Run composer require therealsmat/laravel-push-db
to pull the latest version of the package
Configuration
To start using laravel-push-db, add therealsmat\PushDB\PushDBServiceProvider::class
to the providers array of your app.php
file.
Next, publish the PushDB Service provider by running php artisan vendor:publish --provider="therealsmat\PushDB\PushDBServiceProvider"
.
You will get a config file named pushdb.php
. Feel free to edit it if you wish.
Also out of the box, you will get a new artisan command db:push
. This command alone will get your database exported quickly.
Usage
There are two ways to use this package.
Controller
public function export(PushDB $db) { try{ if ($db->export()) { return 'Database Export Successful'; } return 'Database export not successful'; } catch (ProcessFailedException $e) { return $e->getMessage(); } catch (\Exception $e) { return $e->getMessage(); } }
Command
Simply run php artisan db:push
and your database will be placed in the path you set from the pushdb.php
output_path
option.
As simple as this command is, it can be used in several ways.
- You can use programmatically in your controllers
/** * Call the artisan command */ Artisan::call('db:push'); /** * Get the file from the output path */ Storage::disk('s3')->put('Database.sql', config('pushdb.output_path'));
Of course, you must have set up your s3 disk from the filesystems.php
file.
- You can schedule (1) above to run automatically using Laravel Scheduler e.g
$schedule->command('db:push --force')->daily();
Supported Databases
Only mysql database is supported for now!
TODO
- Implement push to cloud storage feature e.g push to Dropbox, google drive e.t.c.
- Check that the config values are present before sending into the
process
method. - Check to see that the database exists before exporting.
- Write comprehensive tests to make the package more reliable.
- Include support for other databases.
License
The MIT License (MIT). Please see License File for more information.