Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(workspaces): non region enabled workspace project creation #3847

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/server/modules/workspaces/services/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ import { mainDb } from '@/db/knex'
import { storeModelFactory } from '@/modules/core/repositories/models'
import { getProjectFactory } from '@/modules/core/repositories/streams'
import { getEventBus } from '@/modules/shared/services/eventBus'
import {
getWorkspaceFactory,
upsertWorkspaceFactory
} from '@/modules/workspaces/repositories/workspaces'

export const queryAllWorkspaceProjectsFactory = ({
getStreams
Expand Down Expand Up @@ -264,6 +268,9 @@ export const updateWorkspaceProjectRoleFactory =
export const createWorkspaceProjectFactory =
(deps: { getDefaultRegion: GetDefaultRegion }) =>
async (params: { input: WorkspaceProjectCreateInput; ownerId: string }) => {
// yes, i know, this is not aligned with our current definition of a service, but this was already this way
// we need to figure out a good pattern for these situations, where we can not figure out the DB-s up front
// its also hard to add a unit test for this in the current setup...
const { input, ownerId } = params
const workspaceDefaultRegion = await deps.getDefaultRegion({
workspaceId: input.workspaceId
Expand All @@ -273,6 +280,18 @@ export const createWorkspaceProjectFactory =
const projectDb = await getDb({ regionKey })
const db = mainDb

const regionalWorkspace = await getWorkspaceFactory({ db: projectDb })({
workspaceId: input.workspaceId
})

if (!regionalWorkspace) {
const workspace = await getWorkspaceFactory({ db })({
workspaceId: input.workspaceId
})
if (!workspace) throw new WorkspaceNotFoundError()
await upsertWorkspaceFactory({ db: projectDb })({ workspace })
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this effectively migrating a workspace to a region from the main DB?

}

// todo, use the command factory here, but for that, we need to migrate to the event bus
// deps not injected to ensure proper DB injection
const createNewProject = createNewProjectFactory({
Expand Down