diff options
author | Salvatore Martire <4652631+salmart-dev@users.noreply.github.com> | 2025-07-21 13:03:01 +0200 |
---|---|---|
committer | Salvatore Martire <4652631+salmart-dev@users.noreply.github.com> | 2025-07-21 13:03:01 +0200 |
commit | 41da907ff05b4e7d09ad67a76ddba93c27b0bbf9 (patch) | |
tree | 56e3e8b39fc4f26e152ebbfb611692bde0222bc2 | |
parent | d659e15fa4ac6b47869451cab2aa86ba8b86dd9d (diff) | |
download | nextcloud-server-fix/addUniqueMountpointIndex.tar.gz nextcloud-server-fix/addUniqueMountpointIndex.zip |
fixup! fix: add unique index for users' mountpointsfix/addUniqueMountpointIndex
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
-rw-r--r-- | core/Listener/AddMissingIndicesListener.php | 6 | ||||
-rw-r--r-- | core/Migrations/Version13000Date20170718121200.php | 2 | ||||
-rw-r--r-- | core/Migrations/Version32000Date20250721125100.php | 42 |
3 files changed, 45 insertions, 5 deletions
diff --git a/core/Listener/AddMissingIndicesListener.php b/core/Listener/AddMissingIndicesListener.php index 7592af12b47..1619413e9d2 100644 --- a/core/Listener/AddMissingIndicesListener.php +++ b/core/Listener/AddMissingIndicesListener.php @@ -187,12 +187,10 @@ class AddMissingIndicesListener implements IEventListener { ['mount_provider_class'] ); - $event->replaceIndex( + $event->addMissingUniqueIndex( 'mounts', - ['mounts_user_root_path_index'], - 'mounts_user_root_path_unique_i', + 'mounts_user_root_path_index', ['user_id', 'root_id', 'mount_point'], - true, ['lengths' => [null, null, 128]], ); diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php index 0eec147f83f..58446aabe47 100644 --- a/core/Migrations/Version13000Date20170718121200.php +++ b/core/Migrations/Version13000Date20170718121200.php @@ -121,7 +121,7 @@ class Version13000Date20170718121200 extends SimpleMigrationStep { $table->addIndex(['storage_id'], 'mounts_storage_index'); $table->addIndex(['root_id'], 'mounts_root_index'); $table->addIndex(['mount_id'], 'mounts_mount_id_index'); - $table->addUniqueIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_unique_i', ['lengths' => [null, null, 128]]); + $table->addUniqueIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', ['lengths' => [null, null, 128]]); } else { $table = $schema->getTable('mounts'); if (!$table->hasColumn('mount_id')) { diff --git a/core/Migrations/Version32000Date20250721125100.php b/core/Migrations/Version32000Date20250721125100.php new file mode 100644 index 00000000000..d30e2ee9bb9 --- /dev/null +++ b/core/Migrations/Version32000Date20250721125100.php @@ -0,0 +1,42 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OC\Core\Migrations; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\Attributes\AddIndex; +use OCP\Migration\Attributes\DropIndex; +use OCP\Migration\Attributes\IndexType; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Replace user mounts index with a version with a unique constraint. + */ +#[DropIndex(table: 'mounts', type: IndexType::INDEX, description: 'remove non-unique user mounts index', notes: ['will be re-created to make it unique'])] +#[AddIndex(table: 'mounts', type: IndexType::INDEX, description: 'new unique index for user mounts')] +class Version32000Date20250721125100 extends SimpleMigrationStep { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('mounts'); + // replacing index with unique version, to avoid duplicate rows + if ($table->hasIndex('mounts_user_root_path_index')) { + $table->dropIndex('mounts_user_root_path_index'); + $table->addUniqueIndex( + ['user_id', 'root_id', 'mount_point'], + 'mounts_user_root_path_index', + ['lengths' => [null, null, 128]] + ); + } + + return $schema; + } +} |