Skip to content

Commit 5edddf5

Browse files
fix(migration): support the new OCP DB schema API (#13513)
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. Constrain the sort direction in MessageMapper::findByIds() to a literal so it satisfies IQueryBuilder::orderBy()'s tightened, taint-checked parameter. Normalizing in one place keeps every caller working and avoids threading a direction type through the search stack. 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> Co-authored-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
1 parent fc1aa4c commit 5edddf5

6 files changed

Lines changed: 17 additions & 15 deletions

‎lib/Db/MessageMapper.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,13 +1273,14 @@ public function findByIds(string $userId, array $ids, string $sortOrder, string
12731273
if ($ids === []) {
12741274
return [];
12751275
}
1276+
$direction = strtoupper($sortOrder) === 'DESC' ? 'DESC' : 'ASC';
12761277
$qb = $this->db->getQueryBuilder();
12771278
$qb->select('*')
12781279
->from($this->getTableName())
12791280
->where(
12801281
$qb->expr()->in('id', $qb->createParameter('ids'))
12811282
)
1282-
->orderBy($orderBy, $sortOrder);
1283+
->orderBy($orderBy, $direction);
12831284

12841285
$results = [];
12851286
foreach (array_chunk($ids, 1000) as $chunk) {

‎lib/Migration/Version1140Date20220628174152.php‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,20 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $
6161
$alterQuery = 'ALTER TABLE `%s` MODIFY `%s` longtext null;';
6262

6363
$accountsTable = $schema->getTable('mail_accounts');
64-
$accountsSignatureColumn = $accountsTable->getColumn('signature');
6564

6665
$this->connection->executeStatement(
67-
sprintf($alterQuery, $accountsTable->getName(), $accountsSignatureColumn->getName())
66+
sprintf($alterQuery, $accountsTable->getName(), 'signature')
6867
);
6968

7069
$aliasesTable = $schema->getTable('mail_aliases');
71-
$aliasesSignatureColumn = $accountsTable->getColumn('signature');
7270

7371
$this->connection->executeStatement(
74-
sprintf($alterQuery, $aliasesTable->getName(), $aliasesSignatureColumn->getName())
72+
sprintf($alterQuery, $aliasesTable->getName(), 'signature')
7573
);
7674

7775
unset(
7876
$accountsTable,
79-
$accountsSignatureColumn,
80-
$aliasesTable,
81-
$aliasesSignatureColumn
77+
$aliasesTable
8278
);
8379
}
8480
}

‎lib/Migration/Version2300Date20230120085320.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
3030
$schema = $schemaClosure();
3131

3232
$table = $schema->getTable('mail_smime_certificates');
33-
if (!$table->hasPrimaryKey()) {
33+
if ($table->getPrimaryKey() === null) {
3434
$table->setPrimaryKey(['id'], 'mail_smime_certs_id_idx');
3535
}
3636

‎lib/Migration/Version5007Date20251024153423.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
4242
if (!$accountsTable->hasColumn('classification_enabled')) {
4343
$accountsTable->addColumn('classification_enabled', Types::BOOLEAN, [
4444
'default' => true,
45-
'notNull' => false,
45+
'notnull' => false,
4646
]);
4747
}
4848
return $schema;

‎lib/Migration/Version5007Date20260108124422.php‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\DB\Exception;
1515
use OCP\DB\ISchemaWrapper;
1616
use OCP\DB\QueryBuilder\IQueryBuilder;
17+
use OCP\DB\Schema\ITable;
1718
use OCP\IDBConnection;
1819
use OCP\Migration\Attributes\ModifyColumn;
1920
use OCP\Migration\IOutput;
@@ -82,15 +83,17 @@ private function removeInconsistentMailboxEntries(string $mailboxType): void {
8283
}
8384

8485
/**
85-
* @param Table $accountsTable
86-
* @param Table $mailboxesTable
86+
* @param Table|ITable $accountsTable
87+
* @param Table|ITable $mailboxesTable
8788
* @param string $mailboxType
8889
* @return void
8990
*/
90-
private function addMailboxKey(Table $accountsTable, Table $mailboxesTable, string $mailboxType): void {
91+
private function addMailboxKey(Table|ITable $accountsTable, Table|ITable $mailboxesTable, string $mailboxType): void {
92+
/** @var non-empty-lowercase-string $column */
93+
$column = $mailboxType . '_mailbox_id';
9194
$accountsTable->addForeignKeyConstraint(
92-
$mailboxesTable,
93-
["{$mailboxType}_mailbox_id"],
95+
$mailboxesTable->getName(),
96+
[$column],
9497
['id'],
9598
[
9699
'onDelete' => 'SET NULL',

‎psalm.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQL94Platform" />
4141
<referencedClass name="Doctrine\DBAL\Platforms\SqlitePlatform" />
4242
<referencedClass name="Doctrine\DBAL\Schema\Table" />
43+
<referencedClass name="OCP\DB\Schema\ITable" />
4344
<referencedClass name="Doctrine\DBAL\Types\Type" />
4445
<referencedClass name="Doctrine\DBAL\Types\Types" />
4546
<referencedClass name="IPLib\Factory" />
@@ -67,6 +68,7 @@
6768
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
6869
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
6970
<referencedClass name="Doctrine\DBAL\Schema\Table" />
71+
<referencedClass name="OCP\DB\Schema\ITable" />
7072
<referencedClass name="OC\Security\CSP\ContentSecurityPolicyNonceManager" />
7173
<referencedClass name="Symfony\Component\Console\Output\OutputInterface" />
7274
</errorLevel>

0 commit comments

Comments
 (0)