PHPackages                             justinkekeocha/database-dump - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. justinkekeocha/database-dump

ActiveLibrary

justinkekeocha/database-dump
============================

This package will save you from loosing database records, supposing you run the laravel migrate:fresh command without exporting a database dump

4.1(1y ago)161341[4 PRs](https://github.com/justinkekeocha/database-dump/pulls)MITPHPPHP ^8.1CI passing

Since Oct 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/justinkekeocha/database-dump)[ Packagist](https://packagist.org/packages/justinkekeocha/database-dump)[ Docs](https://github.com/justinkekeocha/database-dump)[ RSS](/packages/justinkekeocha-database-dump/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (26)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/72a160cb72bf2ae60df57e8b09665ee8c9ea4258a9beed52332c634165a80278/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a757374696e6b656b656f6368612f64617461626173652d64756d702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/justinkekeocha/database-dump)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b528fe40018ba585efd65825e1d1753def417662dafb6cc22a4d093e6b97138d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a757374696e6b656b656f6368612f64617461626173652d64756d702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/justinkekeocha/database-dump/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/235024b1115697813ce7cafbc9c17e331981628a54aa2e2a6cfd86b68b44b56b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a757374696e6b656b656f6368612f64617461626173652d64756d702f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/justinkekeocha/database-dump/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/eb15d0410af34297f08d691966af6c775e2452003a938ee0ffb36bcad32960e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a757374696e6b656b656f6368612f64617461626173652d64756d702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/justinkekeocha/database-dump)

This package enhances the `migrate:fresh` command by creating a dump of your database, allowing you to make migration changes and then re-seed the database with the previous data. This is particularly useful for developers who need to preserve their data before running migrations.

Utilizing a memory-efficient method, this package streams records from the dump file, ensuring only one record is in memory at any given time. This approach allows it to handle theoretically infinite file sizes without exhausting memory.

Inspired by the export function in phpMyAdmin, this package not only enables you to restore your data but also provides the flexibility to alter the data during the seeding process.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Dump database data](#dump-database-data)
    - [Seed database with dump file](#seed-database-with-dump-file)
    - [Get specific dump file](#get-specific-dump-file)
    - [Seed table](#seed-table)
- [Sample](#sample)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require justinkekeocha/database-dump
```

You can publish the config file with:

```
php artisan vendor:publish --tag="database-dump-config"
```

These are the contents of the published config file:

```
return [

    /*
     *  Enable or disable the package.
    */
    'enable' => true,

    /*
     *  Set the folder generated dumps should be save in.
    */

    'folder' => database_path('dumps/'),

    /*
     *  Set the chunk length of data to be processed at once.
    */
    'chunk_length' => 5000,

    /*
    *  Set the maximum stream length of data to be processed at once.
    *  This is the maximum size a row in a table is expected to have in your database
    *  This is set to a reasonable default of 1MB
    *  If your database rows are larger than this, you may want to increase this value.
    *  Read more: https://www.php.net/manual/en/function.stream-get-line.php
    */

    'stream_length' => (2 * 1024 * 1024),
];
```

Usage
-----

[](#usage)

### Dump database data

[](#dump-database-data)

```
# Dump database data before running migrations
php artisan migrate:fresh

# Dump database data
php artisan database:dump
```

### Seed database with dump file

[](#seed-database-with-dump-file)

Load dump file from DatabaseSeeder and pass the dump tables through the `$this->call` method in the seeder class:

```
# database/seeders/DatabaseSeeder.php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Justinkekeocha\DatabaseDump\Facades\DatabaseDump;
use Database\Seeders\UserSeeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {

         $databaseDump = DatabaseDump::getLatestDump("save/2024_04_14_233109.json");

        $this->command->outputComponents()->info("Using dump:  $databaseDump->filePath");

        $this->call([
            UserSeeder::class,
        ], parameters: compact('databaseDump'));
    }
}
```

The dump tables data are now available in individual seeder files and you can now seed the table with the data provided:

```
# database/seeders/UserSeeder.php

namespace Database\Seeders;

use App\Models\User;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run($databaseDump): void
    {
        $databaseDump->seed(User::class);

        //You can also use table name instead of model.

        $databaseDump->seed('users');
    }
}
```

You can manipulate the rows before seeding:

```
# database/seeders/CountrySeeder.php

namespace Database\Seeders;

use App\Models\Country;

class CountrySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run($databaseDump): void
    {
        $databaseDump->seed(Country::class, formatRowCallback: function ($row) {
                //331.69 ms
                return [
                    'id' => $row['id'],
                    'name' => $row['name'],
                    'code' => 22
                ];

                //OR

                //338.95 ms
                $changes = [
                    'code' => '22'
                ];

                return  collect($row)->only(['id', 'name'])->merge($changes)->all();
    });
    }
}
```

### Get specific dump file

[](#get-specific-dump-file)

```
use Justinkekeocha\DatabaseDump\Facades\DatabaseDump;

//Get dump by position in array of directory listing
//Array starts from latest dump file in specified config('database-dump.folder')
DatabaseDump::getDump(1); //Get second dump in the array.

//Get dump by dump file name
DatabaseDump::getDump("2024_01_08_165939.json");

//Get the latest dump
DatabaseDump::getLatestDump();
```

### Seed table

[](#seed-table)

```
use Justinkekeocha\DatabaseDump\Facades\DatabaseDump;
use App\Models\Country;
use App\Models\Timezone;
use App\Models\User;

DatabaseDump::getLatestDump()->seed(User::class);

//You can seed multiple tables at once.
DatabaseDump::getLatestDump()->seed(Country::class)
->seed(Timezone::class)
->seed(User::class);
```

When seeding from the same dump file, it is more efficient to call the seed method on the already instantiated class. This is because when the seed method is called first, it reads the whole file and generates a schema that stores the offset of the tables in the file before it starts the seeding action. This schema is created so subsequent seed calls on the same instance (obviously the same file) will just move to the file offset where the table was last found and start reading from the offset.

```
use Justinkekeocha\DatabaseDump\Facades\DatabaseDump;
use App\Models\Country;
use App\Models\Timezone;
use App\Models\User;

//Whole file will be read 3 times
DatabaseDump::getLatestDump()->seed(Country::class);
DatabaseDump::getLatestDump()->seed(Timezone::class);
DatabaseDump::getLatestDump()->seed(User::class);

//Whole file will be read only once.
DatabaseDump::getLatestDump()->seed(Country::class)
->seed(Timezone::class)
->seed(User::class);
```

Sample
------

[](#sample)

Sample dump can be found [here](../../blob/main/sample-dump.json)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Kekeocha Justin Chetachukwu](https://github.com/justinkekeocha)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance65

Regular maintenance activity

Popularity20

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

21

Last Release

626d ago

Major Versions

1.5.1 → 2.02024-04-15

2.1.1 → 3.02024-06-22

3.1 → 4.12024-08-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f11f83fbc8bb272ebcd92e3ff684d70c24ccc9fe0042ed302c53978dd68fffc?d=identicon)[justinkekeocha](/maintainers/justinkekeocha)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (341 commits)")[![justinkekeocha](https://avatars.githubusercontent.com/u/39213342?v=4)](https://github.com/justinkekeocha "justinkekeocha (127 commits)")[![mvdnbrk](https://avatars.githubusercontent.com/u/802681?v=4)](https://github.com/mvdnbrk "mvdnbrk (46 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (25 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (19 commits)")[![pforret](https://avatars.githubusercontent.com/u/474312?v=4)](https://github.com/pforret "pforret (16 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (14 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (14 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (7 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (7 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (7 commits)")[![irfanm96](https://avatars.githubusercontent.com/u/42065936?v=4)](https://github.com/irfanm96 "irfanm96 (5 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (5 commits)")[![IGedeon](https://avatars.githubusercontent.com/u/694313?v=4)](https://github.com/IGedeon "IGedeon (4 commits)")[![abenerd](https://avatars.githubusercontent.com/u/7523903?v=4)](https://github.com/abenerd "abenerd (3 commits)")[![jessarcher](https://avatars.githubusercontent.com/u/4977161?v=4)](https://github.com/jessarcher "jessarcher (3 commits)")[![koossaayy](https://avatars.githubusercontent.com/u/6431084?v=4)](https://github.com/koossaayy "koossaayy (3 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (3 commits)")[![medilies](https://avatars.githubusercontent.com/u/35309918?v=4)](https://github.com/medilies "medilies (3 commits)")

---

Tags

laraveldatabase-dumpjustinkekeocha

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/justinkekeocha-database-dump/health.svg)

```
[![Health](https://phpackages.com/badges/justinkekeocha-database-dump/health.svg)](https://phpackages.com/packages/justinkekeocha-database-dump)
```

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
