netsells / laravel-mutex-migrations
同时从多个服务器运行互斥迁移
v2.0.0
2024-03-28 10:13 UTC
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0
- illuminate/contracts: ^10.0|^11.0
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- spatie/fork: ^1.1
README
同时从多个服务器运行互斥迁移。
使用 Laravel 的 原子锁 功能,此包扩展了内置的 MigrateCommand
类,以便在可能同时针对同一数据库运行迁移的情况下安全地运行迁移。
安装
使用以下命令安装包
composer require netsells/laravel-mutex-migrations
可选:发布包配置文件
php artisan vendor:publish --tag=mutex-migrations-config
使用方法
使用默认的 database
存储运行互斥迁移需要存在一个用于存储缓存锁的表。如果不存在,命令将自动回退到标准迁移。
php artisan migrate --mutex
如果有两个或多个迁移同时运行,则第一个获取锁的将阻塞下一个迁移的运行,直到它完成,或者直到锁超时 - 默认为 60 秒。
测试
./vendor/bin/phpunit