File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 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
342342}
343343```
344344
345+ The listener will also create all entities if there's no pending migrations,
346+ ensuring any new entities are created automatically.
347+
345348## 🤝 Contributing
346349
347350Thank you for considering contributing! You can read the contribution guide [ here] ( CONTRIBUTING.md ) .
Original file line number Diff line number Diff line change 77use CalebDW \SqlEntities \SqlEntityManager ;
88use Illuminate \Database \Events \MigrationsEnded ;
99use Illuminate \Database \Events \MigrationsStarted ;
10+ use Illuminate \Database \Events \NoPendingMigrations ;
1011
1112class SyncSqlEntities
1213{
@@ -41,15 +42,27 @@ public function handleEnded(MigrationsEnded $event): void
4142 $ this ->manager ->createAll ();
4243 }
4344
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+
4456 /**
4557 * @codeCoverageIgnore
4658 * @return array<string, string>
4759 */
4860 public function subscribe (): array
4961 {
5062 return [
51- MigrationsStarted::class => 'handleStarted ' ,
52- MigrationsEnded::class => 'handleEnded ' ,
63+ MigrationsStarted::class => 'handleStarted ' ,
64+ MigrationsEnded::class => 'handleEnded ' ,
65+ NoPendingMigrations::class => 'handleNoPending ' ,
5366 ];
5467 }
5568}
Original file line number Diff line number Diff line change 66use CalebDW \SqlEntities \SqlEntityManager ;
77use Illuminate \Database \Events \MigrationsEnded ;
88use Illuminate \Database \Events \MigrationsStarted ;
9+ use Illuminate \Database \Events \NoPendingMigrations ;
910
1011beforeEach (function () {
1112 test ()->manager = Mockery::mock (SqlEntityManager::class);
6364 );
6465 });
6566});
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