From 32c28f65900d1acfa077f982e9e74924e28b6645 Mon Sep 17 00:00:00 2001 From: Brian Stanley Date: Tue, 5 Aug 2025 15:27:04 -0400 Subject: [PATCH] Added migrate:fresh to array of commands after which migrate:dump will automatically run --- src/Handlers/MigrateFinishedHandler.php | 3 +-- tests/MigrateHookTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Handlers/MigrateFinishedHandler.php b/src/Handlers/MigrateFinishedHandler.php index fa20986..2067bc6 100644 --- a/src/Handlers/MigrateFinishedHandler.php +++ b/src/Handlers/MigrateFinishedHandler.php @@ -11,8 +11,7 @@ class MigrateFinishedHandler public function handle(CommandFinished $event) { if ( - // CONSIDER: Also `migrate:fresh`. - in_array($event->command, ['migrate', 'migrate:rollback'], true) + in_array($event->command, ['migrate', 'migrate:fresh', 'migrate:rollback'], true) && ! $event->input->hasParameterOption(['--help', '--pretend', '-V', '--version']) && config('migration-snapshot.dump', true) && in_array(app()->environment(), explode(',', config('migration-snapshot.environments')), true) diff --git a/tests/MigrateHookTest.php b/tests/MigrateHookTest.php index c9c76d5..9e9082c 100644 --- a/tests/MigrateHookTest.php +++ b/tests/MigrateHookTest.php @@ -28,6 +28,24 @@ public function test_handle() $this->assertStringContainsString('Dumped schema', $output_string); } + public function test_handle_dumpsOnFresh() + { + $this->createTestTablesWithoutMigrate(); + + $output = new BufferedOutput(); + $result = \Artisan::call('migrate:fresh', + [ + '--path' => realpath(__DIR__ . '/migrations/setup'), + '--realpath' => true, + ], + $output + ); + $this->assertEquals(0, $result); + + $output_string = $output->fetch(); + $this->assertStringContainsString('Dumped schema', $output_string); + } + public function test_handle_dumpsOnRollback() { $this->createTestTablesWithoutMigrate();