dragon-code / laravel-data-dumper
Adding data from certain tables when executing the `php artisan schema:dump` console command
Fund package maintenance!
Boosty
Yoomoney
Donationalerts
Installs: 2 920
Dependents: 0
Suggesters: 4
Security: 0
Stars: 34
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- composer-runtime-api: ^2.2
- dragon-code/support: ^6.13
- illuminate/config: ^10.0 || ^11.0
- illuminate/database: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
Requires (Dev)
- ext-pdo: *
- mockery/mockery: ^1.3.1
- orchestra/testbench: ^8.0 || ^9.0
- pestphp/pest: ^2.34
README
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, 17
Installation
To get the latest version of Database Data Dumper
, simply require the project
using Composer:
composer require dragon-code/laravel-data-dumper
Or manually update require
block of composer.json
and run composer update
.
{ "require": { "dragon-code/laravel-data-dumper": "^1.0" } }
Configuration
Since Laravel 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, // 'qwerty1' => ['column_name_1', 'database/foo'], // 'qwerty2' => ['column_name_2', __DIR__ . '/../bar'], ], ], ];
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.
Note
If you need to delete files from a folder to which a table is related (for example, the migrations
table),
you can specify an array of two values in the parameter, where the first element should be the name of the column
containing the file name, and the second element should be absolute or relative folder path.
Warning
Laravel 11.35.2 and below does not know how to report the presence of the --prune
parameter when calling the
artisan schema:dump
console command, so specifying paths to folders will always delete files from them.
Starting with Laravel version 11.36, files will be deleted only when calling the console command with the
--prune
parameter.
License
This package is licensed under the MIT License.