Skip to content

This package brings `db:export` and `db:import` artisan commands to Laravel, to easily copy database to another environment.

License

Notifications You must be signed in to change notification settings

Hydrat-Agency/laravel-db-dumper

Repository files navigation

Laravel DB dumper

Brings db:export and db:import artisan commands to Laravel, to easily copy database to another environment.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Ever worked with Wordpress and used the WP-Cli ? How handful are wp db:export and wp db:import commands... 😻

This package brings the same functionality to Laravel. You can...

  • ... export database to a SQL file :
❯ php artisan db:export /path/to/file.sql

Exporting database to /path/to/file.sql
Database exported successfully.
  • ... import database from an SQL file :
❯ php artisan db:import /path/to/file.sql

Importing database from /path/to/file.sql
Database imported successfully.

This package uses spatie/db-dumper in the background to generate db exports.

Installation

This package requires php >= 8.1 and laravel >= 8.0.

You can install the package via composer:

composer require hydrat-agency/laravel-db-dumper

Usage

Supported databases

Database Export Import
MySQL
MariaDB 🅾️
PostgreSQL 🅾️ 🅾️
SQLite 🅾️
SQL Server 🅾️ 🅾️

Using Db Dumper from artisan CLI

  • Exporting to a file :
php artisan db:export /path/to/file.sql  # full path
php artisan db:export ../dump.sql        # relative path

ℹ If you don't provide a filename in your path, a name will be automatically generated :

❯ php artisan db:export

Exporting database to /path/to/project/dbname_2022-10-05_09-59-48.sql
Database exported successfully.
  • Importing from a file :
php artisan db:import /path/to/file.sql  # full path
php artisan db:import ../dump.sql        # relative path

Using Db Dumper from your code

# Using instance
$dumper = new Hydrat\LaravelDbDumper\LaravelDbDumper();
$dumper->dumpTo('path/to/file.sql', 'dbname');
$dumper->importFrom('path/to/file.sql');

# Using facade
use Hydrat\LaravelDbDumper\Facades\LaravelDbDumper;

LaravelDbDumper::dumpTo('path/to/file.sql', 'dbname');
LaravelDbDumper::importFrom('path/to/file.sql');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Feel free to contribute !

Security Vulnerabilities

If you find any security vulnerabilities, please don't report it publicly.
Instead, contact me by private message or at [email protected].

Credits

License

The MIT License (MIT). Please see License File for more information.

About

This package brings `db:export` and `db:import` artisan commands to Laravel, to easily copy database to another environment.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages