Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The rating depends on the installed text processing backend. See [the rating ove

Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud.com/blog/nextcloud-ethical-ai-rating/).
]]></description>
<version>5.6.0-alpha.3</version>
<version>5.6.0-alpha.4</version>
<licence>agpl</licence>
<author homepage="https://github.com/ChristophWurst">Christoph Wurst</author>
<author homepage="https://github.com/GretaD">GretaD</author>
Expand Down
30 changes: 18 additions & 12 deletions lib/Migration/Version3500Date20231115184458.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

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

$indexNew = 'mail_mb_account_id_name_hash';

/**
* Variant 1 - with table prefix
* The migration "Version0161Date20190902103701" created a unique index for account_id and name without
* specifying a name. Unfortunately, this resulted in different index names depending on the table
* prefix, which means we now have to loop through the indexes to find the correct one.
*
* This migration is from 2023-11 and, by now, most people should already have it. Although it is not
* recommended to change migrations after they have been released, we are still updating this
* one for correctness as it was supposed to drop the index here.
*
* On newer versions, this will be a no-op, as creating the index
* in "Version0161Date20190902103701" is commented out.
*
* @see \OCA\Mail\Migration\Version0161Date20190902103701::changeSchema
*/
if ($mailboxesTable->hasIndex('UNIQ_22DEBD839B6B5FBA5E237E06')) {
$mailboxesTable->dropIndex('UNIQ_22DEBD839B6B5FBA5E237E06');
}
/**
* Variant 2 - without table prefix
* @see \OCA\Mail\Migration\Version5006Date20250927130132::changeSchema
*/
if ($mailboxesTable->hasIndex('UNIQ_45754FF89B6B5FBA5E237E06')) {
$mailboxesTable->dropIndex('UNIQ_45754FF89B6B5FBA5E237E06');
foreach ($mailboxesTable->getIndexes() as $index) {
if ($index->isUnique() && $index->spansColumns(['account_id', 'name'])) {
$mailboxesTable->dropIndex($index->getName());
}
}

$indexNew = 'mail_mb_account_id_name_hash';

if (!$mailboxesTable->hasIndex($indexNew)) {
$mailboxesTable->addUniqueIndex(['account_id', 'name_hash'], $indexNew);
}
Expand Down
21 changes: 17 additions & 4 deletions lib/Migration/Version5006Date20250927130132.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,33 @@
#[ModifyColumn(table: 'mail_mailboxes', name: 'name', type: ColumnType::STRING, description: 'Increase the column length from 255 to 1024')]
class Version5006Date20250927130132 extends SimpleMigrationStep {

/**
* @psalm-param Closure():ISchemaWrapper $schemaClosure
*/
#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$mailboxes = $schema->getTable('mail_mailboxes');

/**
* Make sure the old account_id+name index is gone. The DB won't allow
* the name length increase otherwise
* The migration "Version0161Date20190902103701" created a unique index for account_id and name without
* specifying a name. Unfortunately, this resulted in different index names depending on the table
* prefix, which means we now have to loop through the indexes to find the correct one.
*
* The index on account_id and name were supposed to be dropped in "Version3500Date20231115184458",
* but this did not work on every setup due to the name mismatch caused by different table prefixes.
*
* Although it is not recommended to change migrations after release,
* we are updating this one with a safeguard to drop any existing index on account_id and name.
*
* @see \OCA\Mail\Migration\Version0161Date20190902103701::changeSchema
* @see \OCA\Mail\Migration\Version3500Date20231115184458::changeSchema
*/
if ($mailboxes->hasIndex('UNIQ_45754FF89B6B5FBA5E237E06')) {
$mailboxes->dropIndex('UNIQ_45754FF89B6B5FBA5E237E06');
foreach ($mailboxes->getIndexes() as $index) {
if ($index->isUnique() && $index->spansColumns(['account_id', 'name'])) {
$mailboxes->dropIndex($index->getName());
}
}

$mailboxes->modifyColumn(
Expand Down
9 changes: 8 additions & 1 deletion lib/Migration/Version5006Date20251015082003.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$schema = $schemaClosure();

/**
* Make sure the old account_id+name index is gone for good
* The migration "Version0161Date20190902103701" created a unique index for account_id and name without
* specifying a name. Unfortunately, this resulted in different index names depending on the table
* prefix, which means we now have to loop through the indexes to find the correct one.
*
* The index on account_id and name were supposed to be dropped in "Version3500Date20231115184458",
* but this did not work on every setup due to the name mismatch caused by different table prefixes.
*
* @see \OCA\Mail\Migration\Version0161Date20190902103701::changeSchema
* @see \OCA\Mail\Migration\Version3500Date20231115184458::changeSchema
* @see \OCA\Mail\Migration\Version5006Date20250927130132::changeSchema
*/
$mailboxesTable = $schema->getTable('mail_mailboxes');
if (!$mailboxesTable->hasIndex('UNIQ_45754FF89B6B5FBA5E237E06')) {
Expand Down
60 changes: 60 additions & 0 deletions lib/Migration/Version5006Date20251023191023.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

class Version5006Date20251023191023 extends SimpleMigrationStep {

/**
* @param Closure(): ISchemaWrapper $schemaClosure
*/
#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$mailboxes = $schema->getTable('mail_mailboxes');

/**
* The migration "Version0161Date20190902103701" created a unique index for account_id and name without
* specifying a name. Unfortunately, this resulted in different index names depending on the table
* prefix, which means we now have to loop through the indexes to find the correct one.
*
* The index on account_id and name were supposed to be dropped in "Version3500Date20231115184458",
* but this did not work on every setup due to the name mismatch caused by different table prefixes.
*
* On MySQL or MariaDB versions before 10.5, changing the length of the name column to 1024 fails if the
* index on account_id and name still exists, with the error "Specified key was too long; max key length is 3072 bytes."
* However, this change works on MariaDB 10.5 or newer.
*
* The reason is that MariaDB automatically converts a unique index using btree to hash if the key exceeds
* the maximum length and is supported by the storage engine: https://mariadb.com/docs/server/mariadb-quickstart-guides/mariadb-indexes-guide#unique-index
*
* This means that on setups with a different table prefix using MariaDB 10.5, the index on account_id and name
* might still exist. Since we don't need it, we will make another attempt to drop it here.
*
* @see \OCA\Mail\Migration\Version0161Date20190902103701::changeSchema
* @see \OCA\Mail\Migration\Version3500Date20231115184458::changeSchema
* @see \OCA\Mail\Migration\Version5006Date20250927130132::changeSchema
* @see \OCA\Mail\Migration\Version5006Date20251015082003::changeSchema
*/
foreach ($mailboxes->getIndexes() as $index) {
if ($index->isUnique() && $index->spansColumns(['account_id', 'name'])) {
$mailboxes->dropIndex($index->getName());
}
}

return $schema;
}
}
Loading