Skip to content

Commit 6193a10

Browse files
committed
fix: Add prefix when adding foreign key
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 7dd9f40 commit 6193a10

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

lib/private/DB/Schema/Table.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\DBAL\Schema\SchemaException as DBALSchemaException;
1616
use Doctrine\DBAL\Schema\Table as DBALTable;
1717
use Doctrine\DBAL\Types\Type as DBALType;
18+
use OC\DB\Connection;
1819
use OCP\DB\Schema\ColumnType;
1920
use OCP\DB\Schema\IColumn;
2021
use OCP\DB\Schema\IForeignKeyConstraint;
@@ -27,7 +28,8 @@
2728
*/
2829
class Table implements ITable {
2930
public function __construct(
30-
private DBALTable $table,
31+
private readonly DBALTable $table,
32+
private readonly Connection $connection,
3133
) {
3234
}
3335

@@ -117,7 +119,7 @@ public function getPrimaryKey(): ?IIndex {
117119

118120
#[\Override]
119121
public function hasPrimaryKey(): bool {
120-
return $this->table->hasPrimaryKey();
122+
return $this->table->getPrimaryKey() !== null;
121123
}
122124

123125
#[\Override]
@@ -206,7 +208,7 @@ public function addForeignKeyConstraint(
206208
): self {
207209
try {
208210
$this->table->addForeignKeyConstraint(
209-
$foreignTable instanceof self ? $foreignTable->getWrappedTable() : $foreignTable,
211+
$foreignTable instanceof self ? $foreignTable->getWrappedTable() : $this->connection->getPrefix() . $foreignTable,
210212
$localColumnNames,
211213
$foreignColumnNames,
212214
$options,

lib/private/DB/SchemaWrapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getTableNames(): array {
7575
#[\Override]
7676
public function getTable(string $tableName): ITable {
7777
try {
78-
return new Table($this->schema->getTable($this->connection->getPrefix() . $tableName));
78+
return new Table($this->schema->getTable($this->connection->getPrefix() . $tableName), $this->connection);
7979
} catch (DBALSchemaException $e) {
8080
throw new SchemaException($e->getMessage(), $e->getCode(), $e);
8181
}
@@ -93,7 +93,7 @@ public function hasTable(string $tableName): bool {
9393
public function createTable(string $tableName): ITable {
9494
unset($this->tablesToDelete[$tableName]);
9595
try {
96-
return new Table($this->schema->createTable($this->connection->getPrefix() . $tableName));
96+
return new Table($this->schema->createTable($this->connection->getPrefix() . $tableName), $this->connection);
9797
} catch (DBALSchemaException $e) {
9898
throw new SchemaException($e->getMessage(), $e->getCode(), $e);
9999
}

0 commit comments

Comments
 (0)