From 961637e8516de12cb01a9f106e0cdbf904751049 Mon Sep 17 00:00:00 2001 From: Tom Moore Date: Fri, 10 Mar 2023 15:39:09 +0000 Subject: [PATCH 1/4] Tweak variable name for clarity --- src/Mutex/MutexRelay.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Mutex/MutexRelay.php b/src/Mutex/MutexRelay.php index c606420..68e2d98 100644 --- a/src/Mutex/MutexRelay.php +++ b/src/Mutex/MutexRelay.php @@ -3,7 +3,6 @@ namespace Netsells\LaravelMutexMigrations\Mutex; use Illuminate\Contracts\Cache\Lock; -use Illuminate\Contracts\Cache\LockProvider; use Illuminate\Contracts\Cache\Repository; use Illuminate\Database\QueryException; use Illuminate\Support\Str; @@ -48,10 +47,10 @@ private function getLock(): Lock return $this->lock; } - /** @var LockProvider $provider */ - $provider = $this->cache->getStore(); + /** @var \Illuminate\Contracts\Cache\LockProvider $store */ + $store = $this->cache->getStore(); - return $this->lock = $provider->lock(self::KEY . '.lock'); + return $this->lock = $store->lock(self::KEY . '.lock'); } private function isCacheTableNotFoundException(\Throwable $th): bool From 59a551cbf383aa7382926126ddf1ca4db5e3e344 Mon Sep 17 00:00:00 2001 From: Tom Moore Date: Fri, 10 Mar 2023 15:41:48 +0000 Subject: [PATCH 2/4] Alter messaging when terminating processor --- src/Processors/MutexMigrationProcessor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Processors/MutexMigrationProcessor.php b/src/Processors/MutexMigrationProcessor.php index 9d4f5cf..aadd610 100644 --- a/src/Processors/MutexMigrationProcessor.php +++ b/src/Processors/MutexMigrationProcessor.php @@ -37,6 +37,10 @@ public function start(): void public function terminate(): void { + if ($this->relay instanceof NullRelay) { + return; + } + if (! $this->relay->releaseLock()) { $this->components->info('The mutex lock was not released'); From 547993a8571a2af82f9f5db84e2e827793ebac91 Mon Sep 17 00:00:00 2001 From: Tom Moore Date: Fri, 10 Mar 2023 15:54:07 +0000 Subject: [PATCH 3/4] Allow fallback to standard migration --- src/MigrateCommandExtension.php | 7 ++++++- src/MutexMigrateCommand.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/MigrateCommandExtension.php b/src/MigrateCommandExtension.php index 4f451c5..a8560a5 100644 --- a/src/MigrateCommandExtension.php +++ b/src/MigrateCommandExtension.php @@ -6,6 +6,7 @@ use Illuminate\Database\Console\Migrations\MigrateCommand; use Illuminate\Database\Migrations\Migrator; use Illuminate\Support\Collection; +use Netsells\LaravelMutexMigrations\Mutex\DatabaseCacheTableNotFoundException; class MigrateCommandExtension extends MigrateCommand { @@ -19,7 +20,11 @@ public function __construct(Migrator $migrator, Dispatcher $dispatcher) public function handle(): int { if ($this->option(MutexMigrateCommand::OPTION_MUTEX)) { - return $this->call(MutexMigrateCommand::class, $this->getCommandOptions()); + try { + return $this->call(MutexMigrateCommand::class, $this->getCommandOptions()); + } catch (DatabaseCacheTableNotFoundException $e) { + $this->components->warn('Falling back to a standard migration'); + } } return parent::handle(); diff --git a/src/MutexMigrateCommand.php b/src/MutexMigrateCommand.php index c63cc53..c289bef 100644 --- a/src/MutexMigrateCommand.php +++ b/src/MutexMigrateCommand.php @@ -42,7 +42,7 @@ public function handle() } catch (DatabaseCacheTableNotFoundException $e) { $this->components->error($e->getMessage()); - return self::FAILURE; + throw $e; } finally { $this->processor->terminate(); } From 92a4e4685cda0a19cdfc7e382379d9d7f51ce5aa Mon Sep 17 00:00:00 2001 From: Tom Moore Date: Fri, 10 Mar 2023 16:15:05 +0000 Subject: [PATCH 4/4] Update documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb413b9..91ba1ce 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Optionally publish the package config file: ## Usage -Before a mutex migration can be run using the default `database` store, the store's `cache_locks` table **must** already have been created by running `php artisan cache:table` followed by a standard migration - i.e. `php artisan migrate`. Once this table exists migrations can be run safely as follows: +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`