Skip to content

Conversation

@prastoin
Copy link
Contributor

@prastoin prastoin commented Nov 18, 2025

Introduction

Cleaner and fewer scope version of #15745 ( removed sync-metadata hack through, too ambitious migration and upgrade )

Please note that this PR won't have any interaction with the existing sync-metadata
Which mean that the sync metadata does not update the standard entities applicationId and universalIdentifier, and it won't we will deprecate it on favor of a workspace migration aka twenty-standard app installation

API Metadata

Any operation going through the api metadata nows automatically scope the related entity to the workspace custom application instance. This breaks the existing "hack" implementation of the synchronize application service that calls all the services atomically.

We need to either ignore the tests or remove the cli status check from the blocking status badges for a PR to be merged

New workspace

Already handled in previous #15625, when a workspace is created it gets created a twenty standard and custom workspace instance

All his views and permissions will be prefilled to the its twenty standard app instance with a specific universalIdentifier

New universalIdentifier

At the contrary as before with standardIds, universalIdentifier are unique for a given workspace
This means that createdAt field of both object company and opportunity will have a unique universalIdentifier whereas they share the same standardId

FlatApplication

Introduced the flatApplication and cache. Will migrate existing MetadataName to be SyncableMetadataName in a following PR

What's next

Next we will describe a twenty standard app configuration as json that will be used to generate a workspace migration that will be run instead of the sync metadata, in a nutshell we aim to deprecated the sync metadata
So we can standardize any entity to have a non nullable applicationId and universalIdentifier

Upgrade command

Introduced an upgrade command that will create a custom workspace instance for any workspace that do not have one in order to align with the new behavior when creating a new workspace

@github-actions
Copy link
Contributor

github-actions bot commented Nov 18, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:49455

This environment will automatically shut down when the PR is closed or after 5 hours.

@prastoin prastoin marked this pull request as ready for review November 18, 2025 18:34
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 18, 2025

Greptile Summary

  • Introduced workspace custom application entity to scope metadata operations, replacing ad-hoc sync-metadata approach with proper application-based architecture
  • All metadata API operations (fields, objects, views, roles, etc.) now automatically assign applicationId and universalIdentifier to entities created through the API
  • Added upgrade command and workspace initialization flow to ensure all workspaces have both twenty-standard and workspace-custom applications with proper cache management

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk after fixing the typo
  • The refactoring systematically adds application scoping to metadata entities with proper cache invalidation. The architecture is sound and changes are well-structured across services. Only issue found is a minor spelling typo in a log message.
  • Pay close attention to the upgrade command file (1-12-create-workspace-custom-application.command.ts) which contains a typo that should be fixed

Important Files Changed

Filename Overview
packages/twenty-server/src/engine/core-modules/application/application.service.ts Introduced workspace custom application creation and retrieval methods with proper cache invalidation
packages/twenty-server/src/database/commands/upgrade-version-command/1-12/1-12-create-workspace-custom-application.command.ts Upgrade command creates workspace custom applications for existing workspaces, contains typo in log message
packages/twenty-server/src/engine/metadata-modules/field-metadata/services/field-metadata.service-v2.ts Updated to retrieve and use workspace custom application ID when creating fields
packages/twenty-server/src/engine/workspace-manager/workspace-manager.service.ts Updated workspace initialization to create applications and pass them through prefill operations
packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts Refactored workspace creation to use new createWorkspaceCustomApplication method with proper cache invalidation

Sequence Diagram

sequenceDiagram
    participant User
    participant SignInUpService
    participant ApplicationService
    participant WorkspaceRepository
    participant Cache as WorkspaceFlatApplicationMapCache
    participant MetadataService as FieldMetadataServiceV2
    
    User->>SignInUpService: "Create new workspace"
    SignInUpService->>ApplicationService: "createWorkspaceCustomApplication(workspaceId)"
    ApplicationService->>WorkspaceRepository: "Create custom application entity"
    WorkspaceRepository-->>ApplicationService: "Return application"
    ApplicationService-->>SignInUpService: "Return custom application"
    SignInUpService->>WorkspaceRepository: "Create workspace with workspaceCustomApplicationId"
    SignInUpService->>Cache: "invalidateCache(workspaceId)"
    SignInUpService-->>User: "Workspace created"
    
    User->>MetadataService: "Create field via API"
    MetadataService->>ApplicationService: "findWorkspaceTwentyStandardAndCustomApplicationOrThrow()"
    ApplicationService->>Cache: "getExistingOrRecomputeFlatMaps()"
    Cache-->>ApplicationService: "Return flat application maps"
    ApplicationService-->>MetadataService: "Return workspace custom application"
    MetadataService->>MetadataService: "Set applicationId to workspaceCustomApplicationId"
    MetadataService-->>User: "Field created with correct scope"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

91 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants