From 0deecaea2d67fe2a238d28d07804928ed857433d Mon Sep 17 00:00:00 2001 From: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:32:01 +0200 Subject: [PATCH] fix(migration): support the new OCP DB schema API ISchemaWrapper::getTable() now returns OCP\DB\Schema\ITable instead of the Doctrine Table on server 35+. Widen addMailboxKey() to accept both so the migrations keep running on server 32-35, and reference the foreign table and column by name so the call type-checks against the stricter interface. Replace the Doctrine-only calls the reduced interface no longer exposes: a column-name literal instead of IColumn::getName(), and getPrimaryKey() instead of hasPrimaryKey(). Fix the mis-cased notNull option on classification_enabled so the boolean column stays nullable, which the new schema validation now enforces. ITable exists only in the newer OCP stubs, so it is suppressed in psalm for the older matrix versions. Version1130's foreign-key enumeration and column type change forward to Doctrine at runtime and were handled server-side, so that migration is left unchanged. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com> --- lib/Migration/Version1140Date20220628174152.php | 10 +++------- lib/Migration/Version2300Date20230120085320.php | 2 +- lib/Migration/Version5007Date20251024153423.php | 2 +- lib/Migration/Version5007Date20260108124422.php | 13 ++++++++----- psalm.xml | 2 ++ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/Migration/Version1140Date20220628174152.php b/lib/Migration/Version1140Date20220628174152.php index 98dffd062c..76d6a35e70 100644 --- a/lib/Migration/Version1140Date20220628174152.php +++ b/lib/Migration/Version1140Date20220628174152.php @@ -61,24 +61,20 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ $alterQuery = 'ALTER TABLE `%s` MODIFY `%s` longtext null;'; $accountsTable = $schema->getTable('mail_accounts'); - $accountsSignatureColumn = $accountsTable->getColumn('signature'); $this->connection->executeStatement( - sprintf($alterQuery, $accountsTable->getName(), $accountsSignatureColumn->getName()) + sprintf($alterQuery, $accountsTable->getName(), 'signature') ); $aliasesTable = $schema->getTable('mail_aliases'); - $aliasesSignatureColumn = $accountsTable->getColumn('signature'); $this->connection->executeStatement( - sprintf($alterQuery, $aliasesTable->getName(), $aliasesSignatureColumn->getName()) + sprintf($alterQuery, $aliasesTable->getName(), 'signature') ); unset( $accountsTable, - $accountsSignatureColumn, - $aliasesTable, - $aliasesSignatureColumn + $aliasesTable ); } } diff --git a/lib/Migration/Version2300Date20230120085320.php b/lib/Migration/Version2300Date20230120085320.php index 777056d2d4..402d90760e 100644 --- a/lib/Migration/Version2300Date20230120085320.php +++ b/lib/Migration/Version2300Date20230120085320.php @@ -30,7 +30,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $schema = $schemaClosure(); $table = $schema->getTable('mail_smime_certificates'); - if (!$table->hasPrimaryKey()) { + if ($table->getPrimaryKey() === null) { $table->setPrimaryKey(['id'], 'mail_smime_certs_id_idx'); } diff --git a/lib/Migration/Version5007Date20251024153423.php b/lib/Migration/Version5007Date20251024153423.php index 397a4e6bf3..f2f6b1e915 100644 --- a/lib/Migration/Version5007Date20251024153423.php +++ b/lib/Migration/Version5007Date20251024153423.php @@ -42,7 +42,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if (!$accountsTable->hasColumn('classification_enabled')) { $accountsTable->addColumn('classification_enabled', Types::BOOLEAN, [ 'default' => true, - 'notNull' => false, + 'notnull' => false, ]); } return $schema; diff --git a/lib/Migration/Version5007Date20260108124422.php b/lib/Migration/Version5007Date20260108124422.php index 61091082f5..e0aa1b5bca 100644 --- a/lib/Migration/Version5007Date20260108124422.php +++ b/lib/Migration/Version5007Date20260108124422.php @@ -14,6 +14,7 @@ use OCP\DB\Exception; use OCP\DB\ISchemaWrapper; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\DB\Schema\ITable; use OCP\IDBConnection; use OCP\Migration\Attributes\ModifyColumn; use OCP\Migration\IOutput; @@ -82,15 +83,17 @@ private function removeInconsistentMailboxEntries(string $mailboxType): void { } /** - * @param Table $accountsTable - * @param Table $mailboxesTable + * @param Table|ITable $accountsTable + * @param Table|ITable $mailboxesTable * @param string $mailboxType * @return void */ - private function addMailboxKey(Table $accountsTable, Table $mailboxesTable, string $mailboxType): void { + private function addMailboxKey(Table|ITable $accountsTable, Table|ITable $mailboxesTable, string $mailboxType): void { + /** @var non-empty-lowercase-string $column */ + $column = $mailboxType . '_mailbox_id'; $accountsTable->addForeignKeyConstraint( - $mailboxesTable, - ["{$mailboxType}_mailbox_id"], + $mailboxesTable->getName(), + [$column], ['id'], [ 'onDelete' => 'SET NULL', diff --git a/psalm.xml b/psalm.xml index b2d115ea6d..a87b8ac17d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -40,6 +40,7 @@ + @@ -67,6 +68,7 @@ +