File tree 3 files changed +37
-2
lines changed
3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -342,6 +342,9 @@ class AppServiceProvider extends ServiceProvider
342
342
}
343
343
```
344
344
345
+ The listener will also create all entities if there's no pending migrations,
346
+ ensuring any new entities are created automatically.
347
+
345
348
## 🤝 Contributing
346
349
347
350
Thank you for considering contributing! You can read the contribution guide [ here] ( CONTRIBUTING.md ) .
Original file line number Diff line number Diff line change 7
7
use CalebDW \SqlEntities \SqlEntityManager ;
8
8
use Illuminate \Database \Events \MigrationsEnded ;
9
9
use Illuminate \Database \Events \MigrationsStarted ;
10
+ use Illuminate \Database \Events \NoPendingMigrations ;
10
11
11
12
class SyncSqlEntities
12
13
{
@@ -41,15 +42,27 @@ public function handleEnded(MigrationsEnded $event): void
41
42
$ this ->manager ->createAll ();
42
43
}
43
44
45
+ public function handleNoPending (NoPendingMigrations $ event ): void
46
+ {
47
+ if ($ event ->method !== 'up ' ) {
48
+ return ;
49
+ }
50
+
51
+ // We still need to create the entities if there are no pending
52
+ // migrations because new entities may have been added to the code.
53
+ $ this ->manager ->createAll ();
54
+ }
55
+
44
56
/**
45
57
* @codeCoverageIgnore
46
58
* @return array<string, string>
47
59
*/
48
60
public function subscribe (): array
49
61
{
50
62
return [
51
- MigrationsStarted::class => 'handleStarted ' ,
52
- MigrationsEnded::class => 'handleEnded ' ,
63
+ MigrationsStarted::class => 'handleStarted ' ,
64
+ MigrationsEnded::class => 'handleEnded ' ,
65
+ NoPendingMigrations::class => 'handleNoPending ' ,
53
66
];
54
67
}
55
68
}
Original file line number Diff line number Diff line change 6
6
use CalebDW \SqlEntities \SqlEntityManager ;
7
7
use Illuminate \Database \Events \MigrationsEnded ;
8
8
use Illuminate \Database \Events \MigrationsStarted ;
9
+ use Illuminate \Database \Events \NoPendingMigrations ;
9
10
10
11
beforeEach (function () {
11
12
test ()->manager = Mockery::mock (SqlEntityManager::class);
63
64
);
64
65
});
65
66
});
67
+
68
+ describe ('no pending ' , function () {
69
+ it ('does nothing if the method is not "up" ' , function () {
70
+ test ()->manager ->shouldNotReceive ('createAll ' );
71
+ test ()->listener ->handleNoPending (
72
+ new NoPendingMigrations (method: 'down ' ),
73
+ );
74
+ });
75
+ it ('creates all entities ' , function () {
76
+ test ()->manager
77
+ ->shouldReceive ('createAll ' )
78
+ ->once ();
79
+
80
+ test ()->listener ->handleNoPending (
81
+ new NoPendingMigrations (method: 'up ' ),
82
+ );
83
+ });
84
+ });
You can’t perform that action at this time.
0 commit comments