Skip to content

Conversation

@ChristophWurst
Copy link
Member

Fixes #11931

@ChristophWurst
Copy link
Member Author

/backport to stable5.5

@kesselb
Copy link
Contributor

kesselb commented Oct 15, 2025

Could you also comment so we are not even adding the migration for fresh installations?

$mailboxTable->addUniqueIndex([
'account_id',
'name',
]);

@kesselb
Copy link
Contributor

kesselb commented Oct 15, 2025

UNIQ_22DEBD839B6B5FBA5E237E06 is the generated name for oc_mail_mailboxes .
UNIQ_45754FF89B6B5FBA5E237E06 is the generated name for mail_mailboxes.

Therefore it's hopefully enough to check for both. We should consider adding a note in our developer documentation to avoid adding indexes without an explicit name.

<?php

$abstractMaxLenght = 63;
$oracleMaxLenght = 30;

function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30) {
	$hash = implode('', array_map(static function ($column): string {
		return dechex(crc32($column));
	}, $columnNames));

	return strtoupper(substr($prefix . '_' . $hash, 0, $maxSize));
}

$indexA = _generateIdentifierName(
	array_merge(['oc_mail_mailboxes'], ['account_id', 'name']),
	'uniq',
	$abstractMaxLenght,
);

$indexB = _generateIdentifierName(
	array_merge(['oc_mail_mailboxes'], ['account_id', 'name']),
	'uniq',
	$oracleMaxLenght,
);

$indexC = _generateIdentifierName(
	array_merge(['mail_mailboxes'], ['account_id', 'name']),
	'uniq',
	$abstractMaxLenght,
);

$indexD = _generateIdentifierName(
	array_merge(['mail_mailboxes'], ['account_id', 'name']),
	'uniq',
	$oracleMaxLenght,
);


var_dump(
	$indexA,
	$indexB,
	$indexC,
	$indexD,
);

@ChristophWurst ChristophWurst force-pushed the fix/db/clean-up-old-mailboxes-name-index branch from 93cabf9 to 60e78b6 Compare October 15, 2025 11:45
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst ChristophWurst force-pushed the fix/db/clean-up-old-mailboxes-name-index branch from 60e78b6 to e77008b Compare October 15, 2025 11:46
@blizzz
Copy link
Member

blizzz commented Oct 15, 2025

UNIQ_22DEBD839B6B5FBA5E237E06 is the generated name for oc_mail_mailboxes .
UNIQ_45754FF89B6B5FBA5E237E06 is the generated name for mail_mailboxes.

Since it seems this is calculated somehow, can we just use the configured prefix (if any) and determine the expected name?

@blizzz
Copy link
Member

blizzz commented Oct 15, 2025

Therefore it's hopefully enough to check for both. We should consider adding a note in our developer documentation to avoid adding indexes without an explicit name.

And perhaps enforce it in new code?

@ChristophWurst ChristophWurst merged commit ed4aa7b into main Oct 15, 2025
43 of 45 checks passed
@ChristophWurst ChristophWurst deleted the fix/db/clean-up-old-mailboxes-name-index branch October 15, 2025 12:17
@kesselb
Copy link
Contributor

kesselb commented Oct 15, 2025

I find it suspicious that on some systems these indexes were created with different names. Since the difference appears to be only the prefix, I suspect there was an unintended change either on our side or in Doctrine that altered how the index names were generated, leading to this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specified key was too long; max key length is 3072 bytes; migration 5006Date20250927130132 - mail_mailboxes.name

3 participants