{"record":{"id":"34cd69277fce163a","repo":"twentyhq/twenty","slug":"failed-to-add-coreworkflowversionid-field-for-work","errorCode":null,"errorMessage":"Failed to add coreWorkflowVersionId field for workspace ${workspaceId}","messagePattern":"Failed to add coreWorkflowVersionId field for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-22/2-22-workspace-command-1784193206000-add-workflow-version-core-soft-ref-field.command.ts","lineNumber":134,"sourceCode":"          workspaceId,\n          applicationUniversalIdentifier:\n            twentyStandardFlatApplication.universalIdentifier,\n          allFlatEntityOperationByMetadataName: {\n            fieldMetadata: {\n              flatEntityToCreate: [flatFieldMetadataToCreate],\n              flatEntityToDelete: [],\n              flatEntityToUpdate: [],\n            },\n          },\n        },\n      );\n\n    if (result.status === 'fail') {\n      this.logger.error(\n        `Failed to add coreWorkflowVersionId field:\\n${JSON.stringify(result, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to add coreWorkflowVersionId field for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(\n      `Added coreWorkflowVersionId field for workspace ${workspaceId}`,\n    );\n  }\n}\n","sourceCodeStart":116,"sourceCodeEnd":144,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-22/2-22-workspace-command-1784193206000-add-workflow-version-core-soft-ref-field.command.ts#L116-L144","documentation":"Thrown by the 2.22 command that adds the coreWorkflowVersionId field, after the standard field was successfully resolved. The command calls validateBuildAndRunLegacyWorkspaceMigration with a fieldMetadata creation operation. If the legacy pipeline returns status 'fail', the result is logged to logger.error and the generic error is thrown. The legacy path replays a state the engine convention already defines without side-effect expansion.","triggerScenarios":"validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' when creating the coreWorkflowVersionId FlatFieldMetadata. Caused by: the workflowVersion object not existing in workspace metadata at build time, a universal identifier collision (field already exists under a different identifier), stale flatFieldMetadataMaps cache, or a DB error during column creation.","commonSituations":"Workspace cache is stale and reports the field as missing when it actually exists; a prior partial run created the DB column but not the metadata row; concurrent workspace operations modified fieldMetadata during the upgrade.","solutions":["Read the logger.error JSON output for the specific failure report","Flush flatFieldMetadataMaps from workspace cache and retry — the command is idempotent (skips if the field already exists)","Verify the workflowVersion object exists in flatObjectMetadataMaps before the command runs","Run with --dryRun to confirm the operation shape"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running, flush field metadata cache to ensure the builder sees fresh state\nawait workspaceCacheService.invalidateAndRecompute(workspaceId, [\n  'flatFieldMetadataMaps',\n  'flatObjectMetadataMaps',\n]);\n\n// Confirm the workflowVersion object exists\nconst { flatObjectMetadataMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [\n  'flatObjectMetadataMaps',\n]);\n\nconst hasWorkflowVersion = isDefined(\n  flatObjectMetadataMaps.byUniversalIdentifier[STANDARD_OBJECTS.workflowVersion.universalIdentifier]\n);\n\nif (!hasWorkflowVersion) {\n  console.log('workflowVersion object does not exist — command will skip');\n}","typeGuard":null,"tryCatchPattern":"// Retry once after flushing cache — the command is idempotent\ntry {\n  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n} catch (error) {\n  if (error.message.includes('Failed to add coreWorkflowVersionId field')) {\n    await workspaceCacheService.flush(workspaceId, ['flatFieldMetadataMaps']);\n    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n  } else {\n    throw error;\n  }\n}","preventionTips":["Run with --dryRun first to validate the operation shape","Flush flatFieldMetadataMaps cache before retrying — the command skips if the field already exists","Parse the logger.error JSON for the specific fieldMetadata validation failure","Ensure no concurrent workspace metadata modifications"],"tags":["metadata","upgrade-command","workspace-migration","validate-build-run","flat-field-metadata","workflow"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}