PlannrCrm / laravel-fast-refresh-database

🚀 Refresh your test databases faster than you've ever seen before
MIT License
415 stars 18 forks source link

[Discussion] Store migration with database name #15

Closed hendrikheil closed 1 year ago

hendrikheil commented 1 year ago

I wanted to put this up for discussion before actually sending a PR. Currently this package doesn't really support parallel testing reliably. I was exploring a few ways this could be solved. One option I really like is just appending the database name to the migration checksum file.

This basically allows you to switch between parallel and sequential testing as each database has its own checksum store. There would be no need to ever delete the migration checksum file. It would just work out of the box.

I think this makes a lot of sense, as the trait is ran per worker process which has a dedicated database. So ideally we store this information too.

I think changing this method to something as simple as

    protected function getMigrationChecksumFile(): string
    {
        $databaseName = \DB::connection()->getDatabaseName();

        return storage_path("app/migrationChecksum-{$databaseName}.txt");
    }

should already work. Note: Not sure if the DB name can always be stored in a filesystem, so this should probably be processed. Also using the DB facade isn't as clean, as we have access to $this->app

What do you think of this?

Sammyjo20 commented 1 year ago

I love this idea! I'd love to see a PR for this 👍 Thank you for the suggestion! We've been having the same issue here internally.

hendrikheil commented 1 year ago

@Sammyjo20 Just created #16 in order to support this

Sammyjo20 commented 1 year ago

This is now fixed!