Skip to content

Commit 60e78b6

Browse files
fix(db): clean-up old mailboxes account_id+name index
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent d04c393 commit 60e78b6

File tree

4 files changed

+80
-8
lines changed

4 files changed

+80
-8
lines changed

lib/Migration/Version0161Date20190902103701.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
7575
'default' => true,
7676
]);
7777
$mailboxTable->setPrimaryKey(['id']);
78-
// We allow each mailbox name just once
79-
$mailboxTable->addUniqueIndex([
80-
'account_id',
81-
'name',
82-
]);
78+
/*
79+
* We allow each mailbox name just once
80+
* @see \OCA\Mail\Migration\Version3500Date20231115184458::changeSchema
81+
*/
82+
// $mailboxTable->addUniqueIndex([
83+
// 'account_id',
84+
// 'name',
85+
// ]);
8386

8487
return $schema;
8588
}

lib/Migration/Version3500Date20231115184458.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
2828

2929
$mailboxesTable = $schema->getTable('mail_mailboxes');
3030

31-
$indexOld = 'UNIQ_22DEBD839B6B5FBA5E237E06';
3231
$indexNew = 'mail_mb_account_id_name_hash';
3332

34-
if ($mailboxesTable->hasIndex($indexOld)) {
35-
$mailboxesTable->dropIndex($indexOld);
33+
/**
34+
* Variant 1 - with table prefix
35+
*/
36+
if ($mailboxesTable->hasIndex('UNIQ_22DEBD839B6B5FBA5E237E06')) {
37+
$mailboxesTable->dropIndex('UNIQ_22DEBD839B6B5FBA5E237E06');
38+
}
39+
/**
40+
* Variant 2 - without table prefix
41+
* @see \OCA\Mail\Migration\Version5006Date20250927130132::changeSchema
42+
*/
43+
if ($mailboxesTable->hasIndex('UNIQ_45754FF89B6B5FBA5E237E06')) {
44+
$mailboxesTable->dropIndex('UNIQ_45754FF89B6B5FBA5E237E06');
3645
}
3746

3847
if (!$mailboxesTable->hasIndex($indexNew)) {

lib/Migration/Version5006Date20250927130132.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
2626
$schema = $schemaClosure();
2727

2828
$mailboxes = $schema->getTable('mail_mailboxes');
29+
30+
/**
31+
* Make sure the old account_id+name index is gone. The DB won't allow
32+
* the name length increase otherwise
33+
*
34+
* @see \OCA\Mail\Migration\Version3500Date20231115184458::changeSchema
35+
*/
36+
if ($mailboxes->hasIndex('UNIQ_45754FF89B6B5FBA5E237E06')) {
37+
$mailboxes->dropIndex('UNIQ_45754FF89B6B5FBA5E237E06');
38+
}
39+
2940
$mailboxes->modifyColumn(
3041
'name',
3142
['length' => 1024]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Mail\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
use Override;
17+
18+
/**
19+
* FIXME Auto-generated migration step: Please modify to your needs!
20+
*/
21+
class Version5006Date20251015082003 extends SimpleMigrationStep {
22+
23+
/**
24+
* @param IOutput $output
25+
* @param Closure(): ISchemaWrapper $schemaClosure
26+
* @param array $options
27+
* @return null|ISchemaWrapper
28+
*/
29+
#[Override]
30+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
31+
$schema = $schemaClosure();
32+
33+
/**
34+
* Make sure the old account_id+name index is gone for good
35+
*
36+
* @see \OCA\Mail\Migration\Version3500Date20231115184458::changeSchema
37+
*/
38+
$mailboxesTable = $schema->getTable('mail_mailboxes');
39+
if (!$mailboxesTable->hasIndex('UNIQ_45754FF89B6B5FBA5E237E06')) {
40+
// Nothing to do
41+
return null;
42+
}
43+
44+
$mailboxesTable->dropIndex('UNIQ_45754FF89B6B5FBA5E237E06');
45+
46+
return $schema;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)