Code Monkey home page Code Monkey logo

laravel-db-snapshots's Introduction

Quickly dump and load databases

Latest Version on Packagist Quality Score StyleCI Total Downloads

This package provides Artisan commands to quickly dump and load databases in a Laravel application.

# Create a dump
php artisan snapshot:create my-first-dump

# Make some changes to your db
# ...

# Create another dump
php artisan snapshot:create my-second-dump

# Load up the first dump
php artisan snapshot:load my-first-dump

# List all snapshots
php artisan snapshot:list

This package supports MySQL, PostgreSQL and SQLite.

Installation

You can install the package via Composer:

composer require spatie/laravel-db-snapshots

In Laravel 5.5 and above, the package will autoregister the service provider. For Laravel 5.4 or below you must install this service provider to config/app.php:

'providers' => [
    // ...
    Spatie\DbSnapshots\DbSnapshotsServiceProvider::class,
];

And finally you should add a disk named snapshots to app/config/filesystems.php on which the snapshots will be saved. This would be a typical configuration:

// ...
'disks' => [
    // ...
    'snapshots' => [
        'driver' => 'local',
        'root' => database_path('snapshots'),
    ],
// ...    

Optionally, you may publish the configuration file with:

php artisan vendor:publish --provider="Spatie\DbSnapshots\DbSnapshotsServiceProvider" --tag="config"

This is the content of the published file:

return [

    /**
     * The name of the disk on which the snapshots are stored.
     */
    'disk' => 'snapshots',

    /**
     * The connection to be used to create snapshots. Set this to null
     * to use the default configured in `config/databases.php`
     */
    'default_connection' => null,

    /**
     * The directory where temporary files will be stored.
     */
    'temporary_directory_path' => storage_path('app/laravel-db-snapshots/temp'),
];

Usage

To create a snapshot (which is just a dump from the database) run:

php artisan snapshot:create my-first-dump

Giving your snapshot a name is optional. If you don't pass a name the current date time will be used:

# Creates a snapshot named something like `2017-03-17 14:31`
php artisan snapshot:create

After you've made some changes to the database you can create another snapshot:

php artisan snapshot:create my-second-dump

To load a previous dump issue this command:

php artisan snapshot:load my-first-dump

To load a previous dump to another DB connection:

php artisan snapshot:load my-first-dump --connection=connectionName

To list all the dumps run:

php artisan snapshot:list

A dump can be deleted with:

php artisan snapshot:delete my-first-dump

Events

There are several events fired which can be used to perform some logic of your own:

  • Spatie\DbSnapshots\Events\CreatingSnapshot: will be fired before a snapshot is created
  • Spatie\DbSnapshots\Events\CreatedSnapshot: will be fired after a snapshot has been created
  • Spatie\DbSnapshots\Events\LoadingSnapshot: will be fired before a snapshot is loaded
  • Spatie\DbSnapshots\Events\LoadedSnapshot: will be fired after a snapshot has been loaded
  • Spatie\DbSnapshots\Events\DeletingSnapshot: will be fired before a snapshot is deleted
  • Spatie\DbSnapshots\Events\DeletedSnapshot: will be fired after a snapshot has been deleted

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

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

laravel-db-snapshots's People

Contributors

akoepcke avatar alexvanderbist avatar amaelftah avatar freekmurze avatar g3z avatar gauravmak avatar gummibeer avatar joaorobertopb avatar lex111 avatar m1guelpf avatar mbardelmeijer avatar miclf avatar mstralka avatar sebastiandedeyne avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.