File tree Expand file tree Collapse file tree 6 files changed +119
-6
lines changed Expand file tree Collapse file tree 6 files changed +119
-6
lines changed Original file line number Diff line number Diff line change @@ -319,6 +319,14 @@ re-migrate the last five migrations:
319
319
php artisan migrate:actions:refresh --step=5
320
320
```
321
321
322
+ ### Drop All Actions & Migrate Actions
323
+
324
+ The ` migrate:actions:fresh ` command will drop all actions records from the actions table and then execute the migrate command:
325
+
326
+ ```
327
+ php artisan migrate:actions:fresh
328
+ ```
329
+
322
330
### Actions Status
323
331
324
332
The ` migrate:actions:status ` command displays the execution status of actions. In it you can see which actions were executed and which were not:
@@ -343,17 +351,17 @@ return new class extends Actionable
343
351
{
344
352
//
345
353
}
346
-
354
+
347
355
public function down(): void
348
356
{
349
357
//
350
358
}
351
-
359
+
352
360
public function success(): void
353
361
{
354
362
Log::info('success');
355
363
}
356
-
364
+
357
365
public function failed(): void
358
366
{
359
367
Log::info('failed');
@@ -378,17 +386,17 @@ return new class extends Actionable
378
386
{
379
387
throw new Exeption();
380
388
}
381
-
389
+
382
390
public function down(): void
383
391
{
384
392
throw new Exeption();
385
393
}
386
-
394
+
387
395
public function success(): void
388
396
{
389
397
Log::info('success');
390
398
}
391
-
399
+
392
400
public function failed(): void
393
401
{
394
402
Log::info('failed');
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace DragonCode \LaravelActions \Console ;
6
+
7
+ use DragonCode \LaravelActions \Concerns \Optionable ;
8
+ use DragonCode \LaravelActions \Constants \Names ;
9
+ use Illuminate \Database \Console \Migrations \FreshCommand ;
10
+ use Illuminate \Support \Facades \Schema ;
11
+
12
+ class Fresh extends FreshCommand
13
+ {
14
+ use Optionable;
15
+
16
+ /**
17
+ * The console command name.
18
+ *
19
+ * @var string
20
+ */
21
+ protected $ name = Names::FRESH ;
22
+
23
+ /**
24
+ * The console command description.
25
+ *
26
+ * @var string
27
+ */
28
+ protected $ description = 'Drop and re-run all actions ' ;
29
+
30
+ public function handle ()
31
+ {
32
+ if (! $ this ->confirmToProceed ()) {
33
+ return 1 ;
34
+ }
35
+
36
+ $ database = $ this ->optionDatabase ();
37
+
38
+ $ this ->dropTable ();
39
+ $ this ->migrate ($ database );
40
+
41
+ return 0 ;
42
+ }
43
+
44
+ protected function dropTable (): void
45
+ {
46
+ Schema::dropIfExists ($ this ->getTableName ());
47
+ }
48
+
49
+ protected function migrate (?string $ database ): void
50
+ {
51
+ $ this ->call (Names::MIGRATE ,
52
+ array_filter ([
53
+ '--database ' => $ database ,
54
+ '--force ' => true ,
55
+ ]));
56
+ }
57
+
58
+ protected function getTableName (): string
59
+ {
60
+ return config ('database.actions ' );
61
+ }
62
+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ class Command
12
12
13
13
public const REFRESH = 'command.migration.actions.refresh ' ;
14
14
15
+ public const FRESH = 'command.migration.actions.fresh ' ;
16
+
15
17
public const RESET = 'command.migration.actions.reset ' ;
16
18
17
19
public const ROLLBACK = 'command.migration.actions.rollback ' ;
Original file line number Diff line number Diff line change 4
4
5
5
class Names
6
6
{
7
+ public const FRESH = 'migrate:actions:fresh ' ;
8
+
7
9
public const INSTALL = 'migrate:actions:install ' ;
8
10
9
11
public const MAKE = 'make:migration:action ' ;
Original file line number Diff line number Diff line change 2
2
3
3
namespace DragonCode \LaravelActions ;
4
4
5
+ use DragonCode \LaravelActions \Console \Fresh ;
5
6
use DragonCode \LaravelActions \Console \Install ;
6
7
use DragonCode \LaravelActions \Console \Make ;
7
8
use DragonCode \LaravelActions \Console \Migrate ;
@@ -21,6 +22,7 @@ class ServiceProvider extends BaseServiceProvider
21
22
{
22
23
protected $ commands = [
23
24
'Migrate ' => Command::MIGRATE ,
25
+ 'MigrateFresh ' => Command::FRESH ,
24
26
'MigrateInstall ' => Command::INSTALL ,
25
27
'MigrateMake ' => Command::MAKE ,
26
28
'MigrateRefresh ' => Command::REFRESH ,
@@ -129,6 +131,13 @@ protected function registerMigrateRefreshCommand(): void
129
131
});
130
132
}
131
133
134
+ protected function registerMigrateFreshCommand (): void
135
+ {
136
+ $ this ->app ->singleton (Command::FRESH , function () {
137
+ return new Fresh ();
138
+ });
139
+ }
140
+
132
141
protected function registerConfig (): void
133
142
{
134
143
$ this ->mergeConfigFrom (
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Tests \Commands ;
6
+
7
+ use Tests \TestCase ;
8
+
9
+ class FreshTest extends TestCase
10
+ {
11
+ public function testFreshCommand ()
12
+ {
13
+ $ this ->assertDatabaseDoesntTable ($ this ->table );
14
+
15
+ $ this ->artisan ('migrate:actions:install ' )->run ();
16
+
17
+ $ this ->assertDatabaseHasTable ($ this ->table );
18
+ $ this ->assertDatabaseCount ($ this ->table , 0 );
19
+
20
+ $ this ->artisan ('make:migration:action ' , ['name ' => 'Fresh ' ])->run ();
21
+ $ this ->artisan ('migrate:actions ' )->run ();
22
+
23
+ $ this ->assertDatabaseCount ($ this ->table , 1 );
24
+
25
+ $ this ->artisan ('migrate:actions:fresh ' )->run ();
26
+
27
+ $ this ->assertDatabaseCount ($ this ->table , 1 );
28
+ $ this ->assertDatabaseMigrationHas ($ this ->table , 'fresh ' );
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments