From 68d7a5b5b74963bf7091c16addaa29dc78296e32 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Tue, 6 Feb 2024 11:06:18 +0700 Subject: [PATCH] UBERF-5321: Fix workspace CLI upgrade (#4534) Signed-off-by: Andrey Sobolev --- dev/tool/src/index.ts | 17 +++++++++++++---- server/account/src/index.ts | 10 +++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index f806987eaf..d165bd0f83 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -17,7 +17,6 @@ import { ACCOUNT_DB, assignWorkspace, - ClientWorkspaceInfo, confirmEmail, createAcc, createWorkspace, @@ -30,7 +29,8 @@ import { replacePassword, setAccountAdmin, setRole, - upgradeWorkspace + upgradeWorkspace, + WorkspaceInfo } from '@hcengineering/account' import { setMetadata } from '@hcengineering/platform' import { @@ -276,14 +276,23 @@ export function devTool ( const workspaces = await listWorkspaces(db, productId) const withError: string[] = [] - async function _upgradeWorkspace (ws: ClientWorkspaceInfo): Promise { + async function _upgradeWorkspace (ws: WorkspaceInfo): Promise { const t = Date.now() const logger = cmd.console ? consoleModelLogger : new FileModelLogger(path.join(cmd.logs, `${ws.workspace}.log`)) console.log('---UPGRADING----', ws.workspace, !cmd.console ? (logger as FileModelLogger).file : '') try { - await upgradeWorkspace(version, txes, migrateOperations, productId, db, ws.workspace, logger, cmd.force) + await upgradeWorkspace( + version, + txes, + migrateOperations, + productId, + db, + ws.workspaceUrl ?? ws.workspace, + logger, + cmd.force + ) console.log('---UPGRADING-DONE----', ws.workspace, Date.now() - t) } catch (err: any) { withError.push(ws.workspace) diff --git a/server/account/src/index.ts b/server/account/src/index.ts index 4567a11380..10cb738e4d 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -576,7 +576,7 @@ export async function createAccount ( /** * @public */ -export async function listWorkspaces (db: Db, productId: string): Promise { +export async function listWorkspaces (db: Db, productId: string): Promise { return (await db.collection(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray()) .map((it) => ({ ...it, productId })) .filter((it) => it.disabled !== true) @@ -750,7 +750,7 @@ export async function upgradeWorkspace ( } const versionStr = versionToString(version) - const currentVersion = await db.collection(WORKSPACE_COLLECTION).findOne({ workspace: workspaceUrl }) + const currentVersion = await db.collection(WORKSPACE_COLLECTION).findOne({ workspace: ws.workspace }) console.log( `${forceUpdate ? 'force-' : ''}upgrade from "${ currentVersion?.version !== undefined ? versionToString(currentVersion.version) : '' @@ -761,13 +761,13 @@ export async function upgradeWorkspace ( return versionStr } await db.collection(WORKSPACE_COLLECTION).updateOne( - { workspace: workspaceUrl }, + { workspace: ws.workspace }, { $set: { version } } ) await ( - await upgradeModel(getTransactor(), getWorkspaceId(workspaceUrl, productId), txes, migrationOperation, logger) + await upgradeModel(getTransactor(), getWorkspaceId(ws.workspace, productId), txes, migrationOperation, logger) ).close() return versionStr } @@ -881,7 +881,7 @@ export type ClientWorkspaceInfo = Omit +export type WorkspaceInfo = Omit function mapToClientWorkspace (ws: Workspace): ClientWorkspaceInfo { const { _id, accounts, ...data } = ws