PHPackages                             a-h-abid/laravel-refresh-module-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. [Database &amp; ORM](/categories/database)
4. /
5. a-h-abid/laravel-refresh-module-database

ActiveLibrary[Database &amp; ORM](/categories/database)

a-h-abid/laravel-refresh-module-database
========================================

A Refresh Database trait that can be used in unit tests with any Laravel Module packages.

v1.0.4(3y ago)2121MITPHP

Since Apr 8Pushed 3y ago1 watchersCompare

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

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

Laravel Refresh Module Database
===============================

[](#laravel-refresh-module-database)

A Laravel database trait that can used in unit test for module packages like nwidart/laravel-modules, pingpong/modules, caffeinated/modules etc.

What it solves
--------------

[](#what-it-solves)

TLDR; **Speeds up Unit Tests** by migrating only the required modules.

### Long Story

[](#long-story)

I have a big laravel project where I'm using the popular `nwidart/laravel-modules` package for modularizing the codebase. There are about 20 modules and each of then have about 10-15 migration files. When I run `php artisan migrate:fresh` command, it takes 15-20 seconds just to complete all the migration. Now you can understand how much it frustrates when I have to unit test a small section, I have to wait 15-20 seconds just to complete migration then the unit test takes 100-200ms.

So I worked on this refresh database trait where I can choose to only migrate by specific modules. This really up the small unit tests by 90%.

Requirement
-----------

[](#requirement)

- Laravel 6.0 or above
- Database: I only tested with MySQL. I think Postgres or SQLite should work fine.

*Note*: This will not work for using in-memory database.

Install
-------

[](#install)

Install using composer

```
composer require a-h-abid/laravel-refresh-module-database

```

Usage
-----

[](#usage)

Import the Trait to your test code. Best to import it on your base test class.

```
class ExampleTest extends TestCase
{
    use \AHAbid\LaravelRefreshModuleDatabase\RefreshModuleDatabase;
}
```

Next, add the below code in your test class for running module migration. Below example is for `nwidart/laravel-modules` package. If you are using any other package or any other mechanism, change the code inside as you need.

```
protected function runModuleMigration($moduleName)
{
    $this->artisan('module:migrate ' . $moduleName);
}
```

Finally add this code in your test class, which indicates the modules to migrate.

```
protected function modulesToMigrate()
{
    return ['ModuleA', 'ModuleB'];
}
```

Now, run your phpunit and see the result. :)

How It Works
------------

[](#how-it-works)

Similar to Laravel's Refresh Database trait, on initiation, it will drop all tables and then migrate the migration files once. Only difference here is that we can choose to only migrate specific modules in test class. Also once a module is migrated, it will not re-migrate / re-fresh on that test session.

Other Usage Options
-------------------

[](#other-usage-options)

1. If you also need to run the migration files in `project-root/database/migrations` directory, add below method and set to `true`.

```
protected function shouldMigrateRootFiles()
{
    return true;
}
```

2. If you need to migrate all files, set this env in your `phpunit.xml` file with value to `true`.

```

```

TODO
----

[](#todo)

- Improve documentation.
- Implement TDD.

License
-------

[](#license)

This project is licensed under the terms of the MIT license.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Total

5

Last Release

1208d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dbe37bafa4bb2d7841d090cac27712c5ef1b8b3815cb2429174fd298c68afa48?d=identicon)[a-h-abid](/maintainers/a-h-abid)

---

Top Contributors

[![a-h-abid](https://avatars.githubusercontent.com/u/2020773?v=4)](https://github.com/a-h-abid "a-h-abid (5 commits)")[![ahmedul-abid](https://avatars.githubusercontent.com/u/207574940?v=4)](https://github.com/ahmedul-abid "ahmedul-abid (1 commits)")

---

Tags

databaselaravelmigrationsmodulesunit-testinglaraveldatabasemodulemodulesrefresh

### Embed Badge

![Health badge](/badges/a-h-abid-laravel-refresh-module-database/health.svg)

```
[![Health](https://phpackages.com/badges/a-h-abid-laravel-refresh-module-database/health.svg)](https://phpackages.com/packages/a-h-abid-laravel-refresh-module-database)
```

###  Alternatives

[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[nevadskiy/laravel-geonames

Populate your database using the GeoNames service.

2715.1k](/packages/nevadskiy-laravel-geonames)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
