{"record":{"id":"153d0885258e6c21","repo":"twentyhq/twenty","slug":"failed-to-add-the-messagecampaign-name-field-for-w","errorCode":null,"errorMessage":"Failed to add the messageCampaign name field for workspace ${workspaceId}","messagePattern":"Failed to add the messageCampaign name field for workspace (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-server/src/database/commands/upgrade-version-command/2-25/2-25-workspace-command-1785229970000-add-message-campaign-name-field.command.ts","lineNumber":261,"sourceCode":"              flatEntityToCreate: [],\n              flatEntityToDelete: [],\n              flatEntityToUpdate: flatObjectMetadataToUpdate,\n            },\n            searchFieldMetadata: {\n              flatEntityToCreate: searchFieldMetadatasToCreate,\n              flatEntityToDelete: [],\n              flatEntityToUpdate: [],\n            },\n          },\n        },\n      );\n\n    if (result.status === 'fail') {\n      this.logger.error(\n        `Failed to add the messageCampaign name field:\\n${JSON.stringify(result, null, 2)}`,\n      );\n\n      throw new Error(\n        `Failed to add the messageCampaign name field for workspace ${workspaceId}`,\n      );\n    }\n\n    this.logger.log(\n      `Added the messageCampaign name field for workspace ${workspaceId}`,\n    );\n  }\n\n  // The standard positions assume a freshly provisioned view, where name comes\n  // first and everything else is shifted by one. Existing views keep subject at\n  // position 0, so name is placed relative to the columns already there: below\n  // all of them when it becomes the label identifier (the validator requires\n  // it), above all of them otherwise (the validator forbids anything below the\n  // label identifier).\n  private computeNameViewFieldPosition({\n    campaignIndexFlatView,\n    flatViewFieldMaps,","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-server/src/database/commands/upgrade-version-command/2-25/2-25-workspace-command-1785229970000-add-message-campaign-name-field.command.ts#L243-L279","documentation":"Thrown by the 2.25 command that adds the messageCampaign name field, after all standard entities were resolved. The command calls validateBuildAndRunLegacyWorkspaceMigration with a complex multi-entity operation: fieldMetadata creation, viewField creation, objectMetadata label-identifier update, and searchFieldMetadata creation. If the pipeline fails, the result is logged to logger.error and the generic error is thrown.","triggerScenarios":"validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' when applying the combined field/viewField/objectMetadata/searchFieldMetadata operations. Caused by: the label identifier update referencing a field that doesn't exist, view field position validation failure (the validator requires the label identifier at position 0), a universal identifier collision, stale cache, or a DB error.","commonSituations":"The name view field position computed by computeNameViewFieldPosition conflicts with the validator's label-identifier constraint; a prior partial run created some entities but not others; cache doesn't reflect actual metadata state.","solutions":["Read the logger.error JSON output for the specific failure report","Flush flatFieldMetadataMaps, flatViewFieldMaps, flatObjectMetadataMaps, flatSearchFieldMetadataMaps from workspace cache and retry","Verify the computed name view field position satisfies the label-identifier constraint (label identifier must be strictly first)","Run with --dryRun to inspect the operations"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running, flush all relevant cache keys\nawait workspaceCacheService.invalidateAndRecompute(workspaceId, [\n  'flatObjectMetadataMaps',\n  'flatFieldMetadataMaps',\n  'flatViewMaps',\n  'flatViewFieldMaps',\n  'flatSearchFieldMetadataMaps',\n]);\n\n// Confirm the messageCampaign object exists\nconst { flatObjectMetadataMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [\n  'flatObjectMetadataMaps',\n]);\n\nif (!isDefined(flatObjectMetadataMaps.byUniversalIdentifier[CAMPAIGN.universalIdentifier])) {\n  console.log('messageCampaign 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 the messageCampaign name field')) {\n    await workspaceCacheService.flush(workspaceId, [\n      'flatFieldMetadataMaps', 'flatViewFieldMaps', 'flatObjectMetadataMaps', 'flatSearchFieldMetadataMaps',\n    ]);\n    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });\n  } else {\n    throw error;\n  }\n}","preventionTips":["Run with --dryRun first — the command reports planned operation counts per entity type","Flush all four cache keys (fieldMetadata, viewField, objectMetadata, searchFieldMetadata) before retrying","Parse the logger.error JSON for the specific multi-entity validation failure","Verify the computed name view field position satisfies the label-identifier constraint before committing"],"tags":["metadata","upgrade-command","workspace-migration","validate-build-run","message-campaign","flat-field-metadata"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}