File tree 11 files changed +184
-24
lines changed
11 files changed +184
-24
lines changed Original file line number Diff line number Diff line change 2
2
coverage /
3
3
vendor /
4
4
workbench /vendor
5
+ workbench /storage /
5
6
.phpunit.result.cache
6
7
.pint.cache
7
8
composer.lock
Original file line number Diff line number Diff line change @@ -303,6 +303,24 @@ SqlEntity::withoutEntities(
303
303
304
304
After the callback, all affected entities are automatically recreated in dependency order.
305
305
306
+ ### 💻 Console Commands
307
+
308
+ The package provides console commands to create and drop your SQL entities.
309
+
310
+ ``` bash
311
+ php artisan sql-entities:create [entities] [--connection= CONNECTION ...]
312
+
313
+ # Create all entities
314
+ php artisan sql-entities:create
315
+ # Create a specific entity
316
+ php artisan sql-entities:create ' Database\Entities\Views\RecentOrdersView'
317
+ # Create all entities on a specific connection
318
+ php artisan sql-entities:create -c reporting
319
+
320
+ # Similarly, drop all entities
321
+ php artisan sql-entities:drop
322
+ ```
323
+
306
324
### 🚀 Automatic syncing when migrating (Optional)
307
325
308
326
You may want to automatically drop all SQL entities before migrating, and then
Original file line number Diff line number Diff line change 37
37
},
38
38
"require" : {
39
39
"php" : " ^8.4" ,
40
+ "illuminate/console" : " ^11.0 || ^12.0" ,
40
41
"illuminate/contracts" : " ^11.0 || ^12.0" ,
41
42
"illuminate/database" : " ^11.0 || ^12.0" ,
42
43
"illuminate/support" : " ^11.0 || ^12.0"
Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ parameters:
4
4
level: 8
5
5
paths:
6
6
- src
7
- - workbench/app
8
- - workbench/database
7
+ # - workbench/app
8
+ # - workbench/database
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace CalebDW \SqlEntities \Console \Commands ;
6
+
7
+ use CalebDW \SqlEntities \SqlEntityManager ;
8
+ use Illuminate \Console \Command ;
9
+ use Override ;
10
+ use Symfony \Component \Console \Attribute \AsCommand ;
11
+ use Symfony \Component \Console \Input \InputArgument ;
12
+ use Symfony \Component \Console \Input \InputOption ;
13
+
14
+ #[AsCommand('sql-entities:create ' , 'Create SQL entities. ' )]
15
+ class CreateCommand extends Command
16
+ {
17
+ public function __invoke (SqlEntityManager $ manager ): int
18
+ {
19
+ $ connections = $ this ->option ('connection ' );
20
+ $ entities = $ this ->argument ('entities ' );
21
+
22
+ /** @phpstan-ignore argument.type */
23
+ $ manager ->createAll ($ entities , $ connections );
24
+
25
+ return self ::SUCCESS ;
26
+ }
27
+
28
+ /** @return array<mixed> */
29
+ #[Override]
30
+ protected function getArguments (): array
31
+ {
32
+ return [
33
+ new InputArgument (
34
+ 'entities ' ,
35
+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
36
+ 'The entities to create. ' ,
37
+ null ,
38
+ ),
39
+ ];
40
+ }
41
+
42
+ /** @return array<mixed> */
43
+ #[Override]
44
+ protected function getOptions (): array
45
+ {
46
+ return [
47
+ new InputOption (
48
+ 'connection ' ,
49
+ 'c ' ,
50
+ InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY ,
51
+ 'The connection(s) to use. ' ,
52
+ ),
53
+ ];
54
+ }
55
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace CalebDW \SqlEntities \Console \Commands ;
6
+
7
+ use CalebDW \SqlEntities \SqlEntityManager ;
8
+ use Illuminate \Console \Command ;
9
+ use Override ;
10
+ use Symfony \Component \Console \Attribute \AsCommand ;
11
+ use Symfony \Component \Console \Input \InputArgument ;
12
+ use Symfony \Component \Console \Input \InputOption ;
13
+
14
+ #[AsCommand('sql-entities:drop ' , 'Drop SQL entities. ' )]
15
+ class DropCommand extends Command
16
+ {
17
+ public function __invoke (SqlEntityManager $ manager ): int
18
+ {
19
+ $ connections = $ this ->option ('connection ' );
20
+ $ entities = $ this ->argument ('entities ' );
21
+
22
+ /** @phpstan-ignore argument.type */
23
+ $ manager ->dropAll ($ entities , $ connections );
24
+
25
+ return self ::SUCCESS ;
26
+ }
27
+
28
+ /** @return array<mixed> */
29
+ #[Override]
30
+ protected function getArguments (): array
31
+ {
32
+ return [
33
+ new InputArgument (
34
+ 'entities ' ,
35
+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
36
+ 'The entities to create. ' ,
37
+ null ,
38
+ ),
39
+ ];
40
+ }
41
+
42
+ /** @return array<mixed> */
43
+ #[Override]
44
+ protected function getOptions (): array
45
+ {
46
+ return [
47
+ new InputOption (
48
+ 'connection ' ,
49
+ 'c ' ,
50
+ InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY ,
51
+ 'The connection(s) to use. ' ,
52
+ ),
53
+ ];
54
+ }
55
+ }
Original file line number Diff line number Diff line change 4
4
5
5
namespace CalebDW \SqlEntities ;
6
6
7
+ use CalebDW \SqlEntities \Console \Commands \CreateCommand ;
8
+ use CalebDW \SqlEntities \Console \Commands \DropCommand ;
7
9
use CalebDW \SqlEntities \Contracts \SqlEntity ;
8
10
use CalebDW \SqlEntities \Support \Composer ;
9
11
use Illuminate \Contracts \Foundation \Application ;
10
- use Illuminate \Contracts \Support \DeferrableProvider ;
11
12
use Illuminate \Support \Collection ;
12
13
use Illuminate \Support \ServiceProvider as IlluminateServiceProvider ;
13
14
use Override ;
14
15
use ReflectionClass ;
15
16
use Symfony \Component \Finder \Finder ;
16
17
17
- class ServiceProvider extends IlluminateServiceProvider implements DeferrableProvider
18
+ class ServiceProvider extends IlluminateServiceProvider
18
19
{
19
- /** @return list<string> */
20
- #[Override]
21
- public function provides (): array
22
- {
23
- return [SqlEntityManager::class, 'sql-entities ' ]; // @codeCoverageIgnore
24
- }
25
-
26
20
#[Override]
27
21
public function register (): void
28
22
{
@@ -37,6 +31,16 @@ public function register(): void
37
31
$ this ->app ->alias (SqlEntityManager::class, 'sql-entities ' );
38
32
}
39
33
34
+ public function boot (): void
35
+ {
36
+ if ($ this ->app ->runningInConsole ()) {
37
+ $ this ->commands ([
38
+ CreateCommand::class,
39
+ DropCommand::class,
40
+ ]);
41
+ }
42
+ }
43
+
40
44
/** @return Collection<int, SqlEntity> */
41
45
protected function getEntities (Application $ app ): Collection
42
46
{
Original file line number Diff line number Diff line change 1
1
---
2
+ laravel : ./workbench
2
3
providers :
3
4
- CalebDW\SqlEntities\ServiceProvider
4
- laravel : ./workbench
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use CalebDW \SqlEntities \SqlEntityManager ;
6
+
7
+ beforeEach (function () {
8
+ test ()->manager = test ()->mock (SqlEntityManager::class);
9
+ });
10
+
11
+ it ('can create entities ' , function () {
12
+ test ()->manager
13
+ ->shouldReceive ('createAll ' )
14
+ ->once ()
15
+ ->with (null , null );
16
+
17
+ test ()->artisan ('sql-entities:create ' )
18
+ ->assertExitCode (0 );
19
+ });
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use CalebDW \SqlEntities \SqlEntityManager ;
6
+
7
+ beforeEach (function () {
8
+ test ()->manager = test ()->mock (SqlEntityManager::class);
9
+ });
10
+
11
+ it ('can drop entities ' , function () {
12
+ test ()->manager
13
+ ->shouldReceive ('dropAll ' )
14
+ ->once ()
15
+ ->with (null , null );
16
+
17
+ test ()->artisan ('sql-entities:drop ' )
18
+ ->assertExitCode (0 );
19
+ });
Original file line number Diff line number Diff line change 4
4
5
5
namespace CalebDW \SqlEntities \Tests ;
6
6
7
- use Illuminate \Foundation \Testing \RefreshDatabase ;
8
7
use Orchestra \Testbench \Concerns \WithWorkbench ;
9
8
use Orchestra \Testbench \TestCase as OrchestraTestCase ;
10
9
11
- use function Orchestra \Testbench \workbench_path ;
12
-
13
10
abstract class TestCase extends OrchestraTestCase
14
11
{
15
- use RefreshDatabase;
16
12
use WithWorkbench;
17
-
18
- /** @inheritDoc */
19
- protected function defineDatabaseMigrations (): void
20
- {
21
- $ this ->loadMigrationsFrom (
22
- workbench_path ('database/migrations ' ),
23
- );
24
- }
25
13
}
You can’t perform that action at this time.
0 commit comments