Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Case sensitive migration and migration of baseWorkspaceName #5205

Merged
merged 6 commits into from
Aug 17, 2024
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,35 @@ public function migratePayloadToValidWorkspaceNames(\Closure $outputFn): void

$eventTableName = DoctrineEventStoreFactory::databaseTableName($this->contentRepositoryId);
$this->connection->beginTransaction();
$statement = <<<SQL
$statementWorkspaceName = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(payload, '$.workspaceName', SUBSTR(MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName'))), 1, 30))
payload = JSON_SET(payload, '$.workspaceName', LEFT(CONCAT('w', MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')))), 30))
Copy link
Member

@bwaidelich bwaidelich Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this should work, if we change the WorkspaceName regex to ^[a-z0-9\-]{0,36}

Suggested change
payload = JSON_SET(payload, '$.workspaceName', LEFT(CONCAT('w', MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')))), 30))
payload = JSON_SET(
payload,
'$.workspaceName',
IF(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')) REGEXP '^[a-z0-9\-]{0,36}$',
LOWER(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName'))),
MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')))
)
)

WHERE
JSON_EXTRACT(payload, '$.workspaceName') IS NOT NULL
AND JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')) NOT REGEXP '^[a-z][a-z0-9\-]{0,30}$'
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')) NOT REGEXP '^[a-z][a-z0-9\-]{0,30}$'
SQL;
$affectedRows = $this->connection->executeStatement($statement);
$affectedRowsWorkspaceName = $this->connection->executeStatement($statementWorkspaceName);

$statementBaseWorkspaceName = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(payload, '$.baseWorkspaceName', LEFT(CONCAT('w', MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName')))), 30))
WHERE
JSON_EXTRACT(payload, '$.baseWorkspaceName') IS NOT NULL
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName')) NOT REGEXP '^[a-z][a-z0-9\-]{0,30}$'
SQL;
$affectedRowsBaseWorkspaceName = $this->connection->executeStatement($statementBaseWorkspaceName);
$this->connection->commit();

if ($affectedRows === 0) {
if ($affectedRowsWorkspaceName === 0 && $affectedRowsBaseWorkspaceName === 0) {
$outputFn('Migration was not necessary.');
return;
}

$outputFn();
$outputFn(sprintf('Migration applied to %s events.', $affectedRows));
$outputFn(sprintf('Migration applied to %s events and changed the workspaceName.', $affectedRowsWorkspaceName));
$outputFn(sprintf('Migration applied to %s events and changed the baseWorkspaceName.', $affectedRowsBaseWorkspaceName));
}

/** ------------------------ */
Expand Down
Loading