PHPackages                             pristavu/laravel-fast-refresh-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pristavu/laravel-fast-refresh-database

ActiveLibrary

pristavu/laravel-fast-refresh-database
======================================

Refresh your database faster than you've ever seen before 🚀

2.0.0(2y ago)05.7k↓34.4%MITPHPPHP ^8.1

Since Mar 28Pushed 2y agoCompare

[ Source](https://github.com/pristavu/laravel-fast-refresh-database)[ Packagist](https://packagist.org/packages/pristavu/laravel-fast-refresh-database)[ RSS](/packages/pristavu-laravel-fast-refresh-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

FastRefreshDatabase for Laravel 🚀
=================================

[](#fastrefreshdatabase-for-laravel-)

Have you ever come across an issue where the traditional `RefreshDatabase` trait takes ages to run tests when you have lots of migrations? If so, you may be after this package!

The Problem
-----------

[](#the-problem)

Traditionally, the `RefreshDatabase` trait will run `php artisan migrate:fresh` every time you run tests. After the first test, it will use transactions to roll back the data and run the next one, so subsequent tests are fast, but the initial test is slow. This can be really annoying if you are used to running a single test, as it could take seconds to run a single test.

The Solution
------------

[](#the-solution)

You don't need to run `php artisan migrate:fresh` every time you run tests, only when you add a new migration or change an old one. The `FastRefreshDatabase` trait will create a checksum of your `migrations` folder as well as your current Git branch. It will then create a checksum file in your application's `storage/app` directory. When your migrations change or your branch changes, the checksum won't match the cached one and `php artisan migrate:fresh` is run.

When you don't make any changes, it will continue to use the same database without refreshing, which can speed up the test time by 100x!

Benchmarks
----------

[](#benchmarks)

Running a single test, with about 400 migrations.

ProcessorBeforeAfterIntel Core i530 seconds100 millisecondsApple M1 Pro5 seconds100 millisecondsInstallation
------------

[](#installation)

Install the package with Composer

```
composer require plannr/laravel-fast-refresh-database --dev
```

Adding to your TestCase
-----------------------

[](#adding-to-your-testcase)

Next, just replace the existing `RefreshDatabase` trait you are using in your TestCase file with the `FastRefreshDatabase` trait

```
