Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Support wiping config stated databases #51503

Closed
wants to merge 2 commits into from

Conversation

mho22
Copy link

@mho22 mho22 commented May 19, 2024

Based on issues [ #42047, #21009 ] and pull request [ #30656 ] :

This pull request suggestion propose a light addition to allow wiping multiple databases if stated in config file.

When using multiple databases in a Laravel project, using the migrate:fresh command will systematically return an error because of second database not being wiped before re-running migrations. Only the default connection database will be wiped.

This PR propose a config value named database.wipes that is empty by default. If this one collects the different connection database names and the db:wipe command has no --database option, this database.wipes config variable will be taken into account and wipe the databases indicated in the config variable.

config/database.php

    /*
    |--------------------------------------------------------------------------
    | Default Wipeable Database Connection Names
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections you wish to wipe
    | by default. These are the database connections which will be utilized
    | unless another database connection is explicitly specified when you
    | execute the wipe command.
    |
    */

    'wipes' => [],

src/Illuminate/Database/Console/WipeCommand.php

    $database = $this->input->getOption('database');

    $wipes = $this->laravel['config']['database.wipes'];

    $databases = $database || empty($wipes) ? [ $database ] : $wipes;

    foreach( $databases as $database) {
        ...

This can also help prevent the RefreshDatabase trait to fail when using multiple databases too.

This might be problematic for people having already used a custom database.wipes config variable. But I suppose adding new config variables always lead to some probable issues like this. Otherwise this shouldn't cause issues to existing projects.

What are your thoughts on this? I hope it helps

@mho22 mho22 changed the title Support wiping default databases [11.x] Support wiping config stated databases May 19, 2024
@mho22
Copy link
Author

mho22 commented May 19, 2024

It seems a test not related to this pull request failed :

There was 1 failure:

1) Illuminate\Tests\Support\SleepTest::testItSleepsForSeconds
Failed asserting that 1.034066915512085 matches expected 1.

D:\a\framework\framework\tests\Support\SleepTest.php

the line 32 of SleepTest.php should maybe become :

- $this->assertEqualsWithDelta(1, $end - $start, 0.03);
+ $this->assertEqualsWithDelta(1, $end - $start, 0.04);

I could suggest a different PR for this if needed.

@crynobone crynobone marked this pull request as draft May 20, 2024 13:14
@crynobone

This comment was marked as outdated.

@crynobone crynobone marked this pull request as ready for review May 20, 2024 13:28
@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants