diff --git a/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php b/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php index aabe268cae3..ba487eae2e7 100644 --- a/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php +++ b/Neos.Neos/Classes/Domain/Repository/WorkspaceMetadataAndRoleRepository.php @@ -340,7 +340,7 @@ public function addWorkspaceMetadata(ContentRepositoryId $contentRepositoryId, W } } - public function findPrimaryWorkspaceNameForUser(ContentRepositoryId $contentRepositoryId, UserId $userId): ?WorkspaceName + public function findWorkspaceNameByUser(ContentRepositoryId $contentRepositoryId, UserId $userId): ?WorkspaceName { $tableMetadata = self::TABLE_NAME_WORKSPACE_METADATA; $query = <<dbal->fetchOne($query, [ 'contentRepositoryId' => $contentRepositoryId->value, 'personalWorkspaceClassification' => WorkspaceClassification::PERSONAL->value, diff --git a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php index 0b0f63390a4..578f39b7a25 100644 --- a/Neos.Neos/Classes/Domain/Service/WorkspaceService.php +++ b/Neos.Neos/Classes/Domain/Service/WorkspaceService.php @@ -101,7 +101,7 @@ public function setWorkspaceDescription(ContentRepositoryId $contentRepositoryId */ public function getPersonalWorkspaceForUser(ContentRepositoryId $contentRepositoryId, UserId $userId): Workspace { - $workspaceName = $this->metadataAndRoleRepository->findPrimaryWorkspaceNameForUser($contentRepositoryId, $userId); + $workspaceName = $this->metadataAndRoleRepository->findWorkspaceNameByUser($contentRepositoryId, $userId); if ($workspaceName === null) { throw new \RuntimeException(sprintf('No workspace is assigned to the user with id "%s")', $userId->value), 1718293801); } @@ -143,7 +143,7 @@ public function createRootWorkspace(ContentRepositoryId $contentRepositoryId, Wo */ public function createPersonalWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspaceName, UserId $ownerId): void { - $existingUserWorkspace = $this->metadataAndRoleRepository->findPrimaryWorkspaceNameForUser($contentRepositoryId, $ownerId); + $existingUserWorkspace = $this->metadataAndRoleRepository->findWorkspaceNameByUser($contentRepositoryId, $ownerId); if ($existingUserWorkspace !== null) { throw new \RuntimeException(sprintf('Failed to create personal workspace "%s" for user with id "%s", because the workspace "%s" is already assigned to the user', $workspaceName->value, $ownerId->value, $existingUserWorkspace->value), 1733754904); } @@ -193,7 +193,7 @@ public function createSharedWorkspace(ContentRepositoryId $contentRepositoryId, */ public function createPersonalWorkspaceForUserIfMissing(ContentRepositoryId $contentRepositoryId, User $user): void { - $existingWorkspaceName = $this->metadataAndRoleRepository->findPrimaryWorkspaceNameForUser($contentRepositoryId, $user->getId()); + $existingWorkspaceName = $this->metadataAndRoleRepository->findWorkspaceNameByUser($contentRepositoryId, $user->getId()); if ($existingWorkspaceName !== null) { $this->requireWorkspace($contentRepositoryId, $existingWorkspaceName); return; diff --git a/Neos.Neos/Migrations/Mysql/Version20240425223900.php b/Neos.Neos/Migrations/Mysql/Version20240425223900.php index 69bd0305bcd..aca3a3a172a 100644 --- a/Neos.Neos/Migrations/Mysql/Version20240425223900.php +++ b/Neos.Neos/Migrations/Mysql/Version20240425223900.php @@ -29,7 +29,7 @@ public function up(Schema $schema): void $tableWorkspaceMetadata->addColumn('classification', 'string', ['length' => 255]); $tableWorkspaceMetadata->addColumn('owner_user_id', 'string', ['length' => 255, 'notnull' => false]); $tableWorkspaceMetadata->setPrimaryKey(['content_repository_id', 'workspace_name']); - $tableWorkspaceMetadata->addIndex(['owner_user_id']); + $tableWorkspaceMetadata->addIndex(['owner_user_id'], 'IDX_D6197E562B18554A'); $tableWorkspaceRole = $schema->createTable('neos_neos_workspace_role'); $tableWorkspaceRole->addColumn('content_repository_id', 'string', ['length' => 16]); diff --git a/Neos.Neos/Migrations/Mysql/Version20241212000000.php b/Neos.Neos/Migrations/Mysql/Version20241212000000.php new file mode 100644 index 00000000000..260398ed844 --- /dev/null +++ b/Neos.Neos/Migrations/Mysql/Version20241212000000.php @@ -0,0 +1,40 @@ +abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDBPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDBPlatform'." + ); + + $tableWorkspaceMetadata = $schema->getTable('neos_neos_workspace_metadata'); + $tableWorkspaceMetadata->addUniqueIndex(['content_repository_id', 'owner_user_id'], 'owner'); + $tableWorkspaceMetadata->dropIndex('IDX_D6197E562B18554A'); + } + + public function down(Schema $schema): void + { + $this->abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDBPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDBPlatform'." + ); + + $tableWorkspaceMetadata = $schema->getTable('neos_neos_workspace_metadata'); + $tableWorkspaceMetadata->addIndex(['owner_user_id'], 'IDX_D6197E562B18554A'); + $tableWorkspaceMetadata->dropIndex('owner'); + } +} diff --git a/Neos.Neos/Migrations/Postgresql/Version20240425223901.php b/Neos.Neos/Migrations/Postgresql/Version20240425223901.php index b370bd7b9d1..93cb4813b24 100644 --- a/Neos.Neos/Migrations/Postgresql/Version20240425223901.php +++ b/Neos.Neos/Migrations/Postgresql/Version20240425223901.php @@ -26,7 +26,7 @@ public function up(Schema $schema): void $tableWorkspaceMetadata->addColumn('classification', 'string', ['length' => 255]); $tableWorkspaceMetadata->addColumn('owner_user_id', 'string', ['length' => 255, 'notnull' => false]); $tableWorkspaceMetadata->setPrimaryKey(['content_repository_id', 'workspace_name']); - $tableWorkspaceMetadata->addIndex(['owner_user_id']); + $tableWorkspaceMetadata->addIndex(['owner_user_id'], 'IDX_D6197E562B18554A'); $tableWorkspaceRole = $schema->createTable('neos_neos_workspace_role'); $tableWorkspaceRole->addColumn('content_repository_id', 'string', ['length' => 16]); diff --git a/Neos.Neos/Migrations/Postgresql/Version20241212000001.php b/Neos.Neos/Migrations/Postgresql/Version20241212000001.php new file mode 100644 index 00000000000..85e574c2969 --- /dev/null +++ b/Neos.Neos/Migrations/Postgresql/Version20241212000001.php @@ -0,0 +1,40 @@ +abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'." + ); + + $tableWorkspaceMetadata = $schema->getTable('neos_neos_workspace_metadata'); + $tableWorkspaceMetadata->addUniqueIndex(['content_repository_id', 'owner_user_id'], 'owner'); + $tableWorkspaceMetadata->dropIndex('IDX_D6197E562B18554A'); + } + + public function down(Schema $schema): void + { + $this->abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'." + ); + + $tableWorkspaceMetadata = $schema->getTable('neos_neos_workspace_metadata'); + $tableWorkspaceMetadata->addIndex(['owner_user_id'], 'IDX_D6197E562B18554A'); + $tableWorkspaceMetadata->dropIndex('owner'); + } +}