From 99a5a038bcc2a4ca72e09516ab3cdbe4da195eab Mon Sep 17 00:00:00 2001 From: Anish Paudel <32244578+Rpaudel379@users.noreply.github.com> Date: Wed, 13 May 2026 19:51:10 +0545 Subject: [PATCH] fix(server): add Apple seed workspace as fallback for single-workspace mode (#20498) ## Issue As per the developer docs, the local setup uses the `npx nx database:reset twenty-server` command, which seeds 4 workspaces. This works correctly for multi-workspace mode (`IS_MULTIWORKSPACE_ENABLED=true`) and integration tests but causes issues in single-workspace mode (`IS_MULTIWORKSPACE_ENABLED=false`) or when switching from multi-workspace mode back to single-workspace mode. Also, the default mode is single-workspace but 4 workspaces are already seeded in the database. As a result, `WorkspaceDomainsService.getDefaultWorkspace()` selects the newest workspace (Empty4), which is intended only for integration testing and contains no user data. There is also an existing warning log mentioning fallback to the Apple seed workspace when multiple workspaces are found in single-workspace mode i.e `IS_MULTIWORKSPACE_ENABLED=true`, but it was never implemented. ``` if (workspaces.length > 1) { Logger.warn( ` ${workspaces.length} workspaces found in database. In single-workspace mode, there should be only one workspace. Apple seed workspace will be used as fallback if it found.`, ); } ``` Although we could replace with `"nx command-no-deps -- workspace:seed:dev --light"` in `project.json` for `database:reset`, which will only seed one workspace but it wont resolve issue when switching from multi-workspace mode back to single-workspace mode or for integration test `with-db-reset`. ## Changes - Implement fallback behavior already hinted by existing warning logs. - Ensure the Apple seed workspace is used as the fallback in single-workspace mode when multiple workspaces exist. This improves: - Local developer onboarding experience. - Switching between multi-workspace and single-workspace development modes. - Consistency during local development and integration testing. ## Related PR - #19822 - #20464 These PRs only resolves the issue for docker environments but not for local development setup. --------- Co-authored-by: Charles Bochet --- .../services/workspace-domains.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/twenty-server/src/engine/core-modules/domain/workspace-domains/services/workspace-domains.service.ts b/packages/twenty-server/src/engine/core-modules/domain/workspace-domains/services/workspace-domains.service.ts index 8a8a09cc07..f34cd2682e 100644 --- a/packages/twenty-server/src/engine/core-modules/domain/workspace-domains/services/workspace-domains.service.ts +++ b/packages/twenty-server/src/engine/core-modules/domain/workspace-domains/services/workspace-domains.service.ts @@ -11,6 +11,7 @@ import { PublicDomainEntity } from 'src/engine/core-modules/public-domain/public import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service'; import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity'; import { WorkspaceNotFoundDefaultError } from 'src/engine/core-modules/workspace/workspace.exception'; +import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant'; @Injectable() export class WorkspaceDomainsService { @@ -73,11 +74,14 @@ export class WorkspaceDomainsService { if (workspaces.length > 1) { Logger.warn( - ` ${workspaces.length} workspaces found in database. In single-workspace mode, there should be only one workspace. Apple seed workspace will be used as fallback if it found.`, + `${workspaces.length} workspaces found in database. In single-workspace mode, there should be only one workspace. The Apple seed workspace will be used as fallback if present.`, ); } - const foundWorkspace = workspaces[0]; + const foundWorkspace = + workspaces.find( + (workspace) => workspace.id === SEED_APPLE_WORKSPACE_ID, + ) ?? workspaces[0]; assertIsDefinedOrThrow(foundWorkspace, WorkspaceNotFoundDefaultError);