dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

1.0.0 2024-03-15 22:37 UTC

This package is auto-updated.

Last update: 2024-09-10 20:17:46 UTC


README

the dragon code database data dumper

Stable Version Total Downloads Github Workflow Status License

Introduction

The squashing migrations in Laravel does not export data from tables?

There is a solution!

How it works?

After installing and configuring the package, you simply run the console command php artisan schema:dump (with or without flags - it's up to you), and the final SQL dump file will contain the data structure including the contents of the tables you specified at the configuration stage.

This will allow you to painlessly execute the php artisan schema:dump --prune command, which will remove unnecessary migration files.

Requirements

  • Laravel 10, 11
  • PHP 8.2 or higher
  • Databases:
    • Sqlite 3
    • MySQL 5.7, 8, 9
    • PostgreSQL 12, 13, 14, 15, 16

Installation

To get the latest version of Database Data Dumper, simply require the project using Composer:

composer require dragon-code/laravel-data-dumper --dev

Or manually update require-dev block of composer.json and run composer update.

{
    "require-dev": {
        "dragon-code/laravel-data-dumper": "^1.0"
    }
}

Configuration

Since Laravel's mechanism for publishing configuration files does not allow them to be merged on the fly, a new array element must be added to the config/database.php file:

return [
    /*
    |--------------------------------------------------------------------------
    | Schema Settings
    |--------------------------------------------------------------------------
    |
    | This block will contain the names of the tables for which it is
    | necessary to export data along with the table schema.
    |
    */

    'schema' => [
        'tables' => [
            // 'foo',
            // 'bar',
            // App\Models\Article::class,
        ],
    ],
];

After that, add to the array the names of the tables for which you want to export data.

That's it. Now you can run the php artisan schema:dump console command and enjoy the result.

License

This package is licensed under the MIT License.