Snipe Migrations Laravel Package

Snipe Migrations Laravel Package

Snipe Migrations is a Laravel package by Dustin Fraker for “blazing fast” database migrations for tests:

The package takes a snapshot of your mysql database and imports the schema to your test database rather than running all of your migrations when the test suite starts up.

On projects with many migration files, Snipe Migrations may have a huge speed improvement over migrating the database during setup.

It works by adding this method to your base test class that your other tests extend:

public function setUpTraits()
{
    parent::setUpTraits();

    $uses = array_flip(class_uses_recursive(static::class));

    if (isset($uses[DatabaseTransactions::class])) {
        (new Snipe())->importSnapshot();
    }
}

After you’ve added the setUpTraits() method, you then use it by importing the use DatabaseTransactions trait in your tests.

Learn More

In his writeup, Dustin talks about his reasons for creating Snipe Migrations. You should check out his full post about building the package, including a video at the end which goes over his use-case and how to set up the package.

You can learn more about the Snipe Migrations package at drfraker/snipe-migrations. To learn how to install and use the package, check out the Snipe Migration README file.

Congratulations on your first open-source Laravel package Dustin!

Filed in: Laravel Packages / Migrations

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full Stack PHP Developer (Laravel)
Remote
MAPPEN
Senior Laravel Developer
Remote
ACTO
Senior Full-Stack Engineer
[REMOTE: USA Only]
Curricula
Developers for B2B eCommerce SaaS, AWS serverless, Laravel, Vue, Python
Remote, full time EU only
ES Tech Group
Senior PHP Developer (Laravel)
Remote
The Interaction Design Foundation