framework icon indicating copy to clipboard operation
framework copied to clipboard

[11.x] Add an option to dump data from specified tables

Open Seb33300 opened this issue 1 year ago • 2 comments

I would like to improve the schema:dump by adding an optional config key to dump the data from specified tables.

In a project, it's common to have some tables containing "reference" data such as countries or currencies. This data almost never change and needs to be populated every time we deploy the project in a new environment.

How to use:

    # config/database.php
    'dump' => [
        'data_from_tables' => [
            'countries',
            'currencies',
        ],
    ],
php artisan schema:dump  # generate a dump file containing structure from all tables in the schema
                         # + data from tables countries and currencies (& migrations table)

I would like to suggest this feature as an easier alternative that could be used instead of Database Seeding. When used with migration squashing, this could make life easier to run tests suite on CI with a database pre populated with reference data just by running the artisan migrate command.

Seb33300 avatar May 16 '24 07:05 Seb33300

Wouldn't an “Excluded” option be better?

php artisan schema:dump --except=users,posts

Muetze42 avatar May 16 '24 08:05 Muetze42

The schema:dump generates a "structure only" SQL dump.

That PR is to specify the list of tables we also want to dump the data. This may be an option added to the command, but I think having a list defined in the configuration is better especially when we regularly use the command to squash migrations. (we don't need to remember every time the list of tables we want to keep)

Seb33300 avatar May 16 '24 08:05 Seb33300

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

taylorotwell avatar May 16 '24 21:05 taylorotwell