Skip to content

Commit 85c752b

Browse files
committed
feat: skip unsupported entities in SqlEntityManager
1 parent 297ccb4 commit 85c752b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/Grammars/Grammar.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function compileDrop(SqlEntity $entity): string
4343
return $this->clean($statement);
4444
}
4545

46+
/** Determine if the grammar supports the entity. */
47+
public function supportsEntity(SqlEntity $entity): bool
48+
{
49+
return match (true) {
50+
$entity instanceof View => true,
51+
default => false,
52+
};
53+
}
4654
abstract protected function compileViewCreate(View $entity): string;
4755

4856
protected function compileViewDrop(View $entity): string

src/SqlEntityManager.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ class SqlEntityManager
2727
{
2828
use SortsTopologically;
2929

30+
/** @var TEntities */
31+
public Collection $entities;
32+
3033
/**
3134
* The active connection instances.
3235
*
3336
* @var array<string, Connection>
3437
*/
3538
protected array $connections = [];
3639

37-
/** @var TEntities */
38-
public Collection $entities;
39-
4040
/**
4141
* The active grammar instances.
4242
*
@@ -112,6 +112,18 @@ public function create(SqlEntity|string $entity): void
112112

113113
$grammar = $this->grammar($connection);
114114

115+
if (! $grammar->supportsEntity($entity)) {
116+
logger()->warning(
117+
sprintf(
118+
'Skipping creation of entity [%s]: not supported by %s.',
119+
$entity::class,
120+
$grammar::class,
121+
),
122+
);
123+
124+
return;
125+
}
126+
115127
$connection->statement($grammar->compileCreate($entity));
116128
$entity->created($connection);
117129
$this->states[$entity::class] = 'created';
@@ -141,6 +153,18 @@ public function drop(SqlEntity|string $entity): void
141153

142154
$grammar = $this->grammar($connection);
143155

156+
if (! $grammar->supportsEntity($entity)) {
157+
logger()->warning(
158+
sprintf(
159+
'Skipping dropping of entity [%s]: not supported by %s.',
160+
$entity::class,
161+
$grammar::class,
162+
),
163+
);
164+
165+
return;
166+
}
167+
144168
$connection->statement($grammar->compileDrop($entity));
145169
$entity->dropped($connection);
146170
$this->states[$entity::class] = 'dropped';

0 commit comments

Comments
 (0)