-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Ensure that the workspace owner is unique via sql index
We still try to catch the error beforehand via php constraint (so that the `CreateWorkspace` is not handled), but in a race condition this will be thrown at last: > Integrity constraint violation: 1062 Duplicate entry 'default-janedoe' for key 'owner''
- Loading branch information
Showing
6 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Flow\Persistence\Doctrine\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241212000000 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Restricts that the owner_user_id of the neos workspace metadata is unique'; | ||
} | ||
|
||
public function up(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->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Flow\Persistence\Doctrine\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241212000001 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Restricts that the owner_user_id of the neos workspace metadata is unique'; | ||
} | ||
|
||
public function up(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->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'); | ||
} | ||
} |