Skip to content

Commit 93687a1

Browse files
committed
fix(schema): narrow vector() return types and correct MongoDB dropView payload
Table\PostgreSQL/MongoDB/ClickHouse vector() declared base Column return; narrow to Column\X to match the docblock and keep dialect-specific chaining type-safe without a /** @var */ cast. MongoDB dropView() emitted {command: 'drop', view: <name>}; the executor uses 'collection' as the target key for all drop commands (compileDrop already does this). Switch to 'collection' for consistency and add a regression test.
1 parent ef7ed8c commit 93687a1

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/Query/Schema/MongoDB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function createView(string $name, Builder $query): Statement
293293
public function dropView(string $name): Statement
294294
{
295295
return new Statement(
296-
\json_encode(['command' => 'drop', 'view' => $name], JSON_THROW_ON_ERROR),
296+
\json_encode(['command' => 'drop', 'collection' => $name], JSON_THROW_ON_ERROR),
297297
[],
298298
executor: $this->executor,
299299
);

src/Query/Schema/Table/ClickHouse.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ protected function newColumn(string $name, ColumnType $type, ?int $length = null
2222
return new Column\ClickHouse($this, $name, $type, $length, $precision);
2323
}
2424

25-
/**
26-
* @return Column\ClickHouse
27-
*/
28-
public function vector(string $name, int $dimensions): Column
25+
public function vector(string $name, int $dimensions): Column\ClickHouse
2926
{
30-
$col = $this->newColumn($name, ColumnType::Vector)->dimensions($dimensions);
27+
$col = $this->newColumn($name, ColumnType::Vector);
28+
$col->dimensions($dimensions);
3129
$this->columns[] = $col;
3230

3331
return $col;

src/Query/Schema/Table/MongoDB.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ protected function newColumn(string $name, ColumnType $type, ?int $length = null
1818
return new Column\MongoDB($this, $name, $type, $length, $precision);
1919
}
2020

21-
/**
22-
* @return Column\MongoDB
23-
*/
24-
public function vector(string $name, int $dimensions): Column
21+
public function vector(string $name, int $dimensions): Column\MongoDB
2522
{
26-
$col = $this->newColumn($name, ColumnType::Vector)->dimensions($dimensions);
23+
$col = $this->newColumn($name, ColumnType::Vector);
24+
$col->dimensions($dimensions);
2725
$this->columns[] = $col;
2826

2927
return $col;

src/Query/Schema/Table/PostgreSQL.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ protected function newForeignKey(string $column): ForeignKey\PostgreSQL
3131
return new ForeignKey\PostgreSQL($this, $column);
3232
}
3333

34-
/**
35-
* @return Column\PostgreSQL
36-
*/
37-
public function vector(string $name, int $dimensions): Column
34+
public function vector(string $name, int $dimensions): Column\PostgreSQL
3835
{
39-
$col = $this->newColumn($name, ColumnType::Vector)->dimensions($dimensions);
36+
$col = $this->newColumn($name, ColumnType::Vector);
37+
$col->dimensions($dimensions);
4038
$this->columns[] = $col;
4139

4240
return $col;

tests/Query/Schema/MongoDBTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ public function testCreateViewFromAggregation(): void
363363
$this->assertNotEmpty($pipeline);
364364
}
365365

366+
public function testDropView(): void
367+
{
368+
$schema = new Schema();
369+
$result = $schema->dropView('active_users');
370+
371+
$op = $this->decode($result->query);
372+
$this->assertSame('drop', $op['command']);
373+
$this->assertSame('active_users', $op['collection']);
374+
$this->assertArrayNotHasKey('view', $op);
375+
}
376+
366377
public function testCreateCollectionWithAllBsonTypes(): void
367378
{
368379
$schema = new Schema();

0 commit comments

Comments
 (0)