Skip to content

Commit 482c0ee

Browse files
author
Paul Rogers
committed
Accept after-dump and after-load as array for Artisan call.
1 parent 52ef54a commit 482c0ee

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

config/migration-snapshot.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@
8080
| After Dump
8181
|--------------------------------------------------------------------------
8282
|
83-
| Run this closure after dumping snapshot. Helps when output may vary by
84-
| environment in unimportant ways which would just pollute the SCM history
85-
| with noisy changes.
83+
| Run this Artisan command or closure after dumping snapshot. Helps when
84+
| output may vary by environment in unimportant ways which would just
85+
| pollute the SCM history with noisy changes.
8686
|
87-
| Must accept two arguments: `function ($schema_sql_path, $data_sql_path)`.
87+
| If an array values must align with arguments to `Artisan::call()`.
88+
| If a closure it must be: `function ($schema_sql_path, $data_sql_path)`.
8889
|
8990
*/
9091
'after-dump' => null,
@@ -94,10 +95,11 @@
9495
| After Load
9596
|--------------------------------------------------------------------------
9697
|
97-
| Run this closure after loading snapshot. Helps when one needs to refresh
98-
| materialized views or otherwise prep a fresh DB.
98+
| Run this Artisan command or closure after loading snapshot. Helps when
99+
| one needs to refresh materialized views or otherwise prep a fresh DB.
99100
|
100-
| Must accept two arguments: `function ($schema_sql_path, $data_sql_path)`.
101+
| If an array values must align with arguments to `Artisan::call()`.
102+
| If a closure it must be: `function ($schema_sql_path, $data_sql_path)`.
101103
|
102104
*/
103105
'after-load' => null,

src/Commands/MigrateDumpCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace AlwaysOpen\MigrationSnapshot\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
67
use Illuminate\Support\Facades\DB;
78

89
final class MigrateDumpCommand extends Command
@@ -84,9 +85,14 @@ public function handle()
8485
$this->info('Dumped Data');
8586
}
8687

87-
$after_dump = config('migration-snapshot.after-dump');
88-
if ($after_dump) {
89-
$after_dump($schema_sql_path, $data_path);
88+
if ($after_dump = config('migration-snapshot.after-dump')) {
89+
if (is_string($after_dump)) {
90+
Artisan::call($after_dump);
91+
} elseif (is_array($after_dump)) {
92+
Artisan::call($after_dump[0], $after_dump[1] ?? [], $after_dump[2] ?? null);
93+
} else {
94+
$after_dump($schema_sql_path, $data_path);
95+
}
9096
$this->info('Ran After-dump');
9197
}
9298
}

src/Commands/MigrateLoadCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace AlwaysOpen\MigrationSnapshot\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
67
use Illuminate\Support\Facades\DB;
78
use Illuminate\Support\Str;
89
use InvalidArgumentException;
@@ -89,7 +90,13 @@ public function handle()
8990
}
9091

9192
if ($after_load = config('migration-snapshot.after-load')) {
92-
$after_load($schema_sql_path, $data_path);
93+
if (is_string($after_load)) {
94+
Artisan::call($after_load);
95+
} elseif (is_array($after_load)) {
96+
Artisan::call($after_load[0], $after_load[1] ?? [], $after_load[2] ?? null);
97+
} else {
98+
$after_load($schema_sql_path, $data_path);
99+
}
93100
$this->info('Ran After-load');
94101
}
95102
}

0 commit comments

Comments
 (0)