netsells/laravel-mutex-migrations

Run mutually exclusive migrations from more than one server at a time
23,161 1
Install
composer require netsells/laravel-mutex-migrations
Latest Version:v3.0.0
PHP:^8.2
License:MIT
Last Updated:Mar 7, 2025
Links: GitHub  ·  Packagist
Maintainer: tomchkk

Mutex Migrations for Laravel

Run mutually exclusive migrations from more than one server at a time.

Using Laravel's functionality for Atomic Locks, this package extends the built-in MigrateCommand class to allow migrations to be run safely when there is the chance that they may be run concurrently against the same database.

Installation

Install the package with:

composer require netsells/laravel-mutex-migrations

Optionally publish the package config file:

php artisan vendor:publish --tag=mutex-migrations-config

Usage

Running a mutex migration using the default database store requires the existence of a table to store cache locks. If it does not exist the command will automatically fallback to a standard migration.

php artisan migrate --mutex

If two or more migrations happen to run concurrently, the first to acquire a lock will block the next one from running until it has finished, or until the lock times out - after 60 seconds, by default.

Testing

./vendor/bin/phpunit

Related Packages

jaybizzle/laravel-migrations-organiser

A Laravel package to help organise migration files.

422,888 112
zingle/laravel5-migrator

Improved version of Laravel 5's Migrator. Adds better error messaging and suppor...

2,316 2
laravel-doctrine/migrations

Doctrine Migrations for Laravel

2,986,498 78
xethron/migrations-generator

Generates Laravel Migrations from an existing database

3,397,555 3,319