From 6193a1006feed82a0697bec1ef979cd1e4fb58b6 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 18 Aug 2026 16:22:38 +0200 Subject: [PATCH] fix: Add prefix when adding foreign key Signed-off-by: Carl Schwan --- lib/private/DB/Schema/Table.php | 8 +++++--- lib/private/DB/SchemaWrapper.php | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/private/DB/Schema/Table.php b/lib/private/DB/Schema/Table.php index 34eb24379fcb6..3cb0f0b123a2f 100644 --- a/lib/private/DB/Schema/Table.php +++ b/lib/private/DB/Schema/Table.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Schema\SchemaException as DBALSchemaException; use Doctrine\DBAL\Schema\Table as DBALTable; use Doctrine\DBAL\Types\Type as DBALType; +use OC\DB\Connection; use OCP\DB\Schema\ColumnType; use OCP\DB\Schema\IColumn; use OCP\DB\Schema\IForeignKeyConstraint; @@ -27,7 +28,8 @@ */ class Table implements ITable { public function __construct( - private DBALTable $table, + private readonly DBALTable $table, + private readonly Connection $connection, ) { } @@ -117,7 +119,7 @@ public function getPrimaryKey(): ?IIndex { #[\Override] public function hasPrimaryKey(): bool { - return $this->table->hasPrimaryKey(); + return $this->table->getPrimaryKey() !== null; } #[\Override] @@ -206,7 +208,7 @@ public function addForeignKeyConstraint( ): self { try { $this->table->addForeignKeyConstraint( - $foreignTable instanceof self ? $foreignTable->getWrappedTable() : $foreignTable, + $foreignTable instanceof self ? $foreignTable->getWrappedTable() : $this->connection->getPrefix() . $foreignTable, $localColumnNames, $foreignColumnNames, $options, diff --git a/lib/private/DB/SchemaWrapper.php b/lib/private/DB/SchemaWrapper.php index 429d3e5775ade..35e7c0ef285a2 100644 --- a/lib/private/DB/SchemaWrapper.php +++ b/lib/private/DB/SchemaWrapper.php @@ -75,7 +75,7 @@ public function getTableNames(): array { #[\Override] public function getTable(string $tableName): ITable { try { - return new Table($this->schema->getTable($this->connection->getPrefix() . $tableName)); + return new Table($this->schema->getTable($this->connection->getPrefix() . $tableName), $this->connection); } catch (DBALSchemaException $e) { throw new SchemaException($e->getMessage(), $e->getCode(), $e); } @@ -93,7 +93,7 @@ public function hasTable(string $tableName): bool { public function createTable(string $tableName): ITable { unset($this->tablesToDelete[$tableName]); try { - return new Table($this->schema->createTable($this->connection->getPrefix() . $tableName)); + return new Table($this->schema->createTable($this->connection->getPrefix() . $tableName), $this->connection); } catch (DBALSchemaException $e) { throw new SchemaException($e->getMessage(), $e->getCode(), $e); }