Skip to content

Commit

Permalink
5201 - Add missing workspace property name handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed Aug 16, 2024
1 parent 695f8eb commit 09faadc
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function migratePayloadToValidWorkspaceNames(\Closure $outputFn): void
UPDATE {$eventTableName}
SET
payload = JSON_SET(
payload,
payload,
'$.workspaceName',
IF(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')) REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$',
LOWER(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName'))),
Expand All @@ -406,7 +406,7 @@ public function migratePayloadToValidWorkspaceNames(\Closure $outputFn): void
UPDATE {$eventTableName}
SET
payload = JSON_SET(
payload,
payload,
'$.baseWorkspaceName',
IF(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName')) REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$',
LOWER(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName'))),
Expand All @@ -418,16 +418,52 @@ public function migratePayloadToValidWorkspaceNames(\Closure $outputFn): void
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName')) NOT REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$'
SQL;
$affectedRowsBaseWorkspaceName = $this->connection->executeStatement($statementBaseWorkspaceName);

$sourceWorkspaceNameStatement = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(
payload,
'$.sourceWorkspaceName',
IF(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.sourceWorkspaceName')) REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$',
LOWER(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.sourceWorkspaceName'))),
MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.sourceWorkspaceName')))
)
)
WHERE
JSON_EXTRACT(payload, '$.sourceWorkspaceName') IS NOT NULL
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.sourceWorkspaceName')) NOT REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$'
SQL;
$sourceWorkspaceAffectedRows = $this->connection->executeStatement($sourceWorkspaceNameStatement);

$targetWorkspaceNameStatement = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(
payload,
'$.targetWorkspaceName',
IF(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.targetWorkspaceName')) REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$',
LOWER(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.targetWorkspaceName'))),
MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.targetWorkspaceName')))
)
)
WHERE
JSON_EXTRACT(payload, '$.targetWorkspaceName') IS NOT NULL
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.targetWorkspaceName')) NOT REGEXP '^[a-z0-9][a-z0-9\-]{0,35}$'
SQL;
$targetWorkspaceAffectedRows = $this->connection->executeStatement($targetWorkspaceNameStatement);
$this->connection->commit();

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

$outputFn();
$outputFn(sprintf('Migration applied to %s events and changed the workspaceName.', $affectedRowsWorkspaceName));
$outputFn(sprintf('Migration applied to %s events and changed the baseWorkspaceName.', $affectedRowsBaseWorkspaceName));
$outputFn(sprintf('Migration applied to %s events and changed the sourceWorkspaceName.', $sourceWorkspaceAffectedRows));
$outputFn(sprintf('Migration applied to %s events and changed the targetWorkspaceName.', $targetWorkspaceAffectedRows));
$outputFn(sprintf('You need to replay your projection for workspaces. Please run: ./flow cr:projectionreplay --projection=workspace'));
}

Expand Down

0 comments on commit 09faadc

Please sign in to comment.