mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-30 02:37:46 +03:00
UBERF-5321: Fix workspace CLI upgrade (#4534)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
99564ddcb7
commit
68d7a5b5b7
@ -17,7 +17,6 @@
|
|||||||
import {
|
import {
|
||||||
ACCOUNT_DB,
|
ACCOUNT_DB,
|
||||||
assignWorkspace,
|
assignWorkspace,
|
||||||
ClientWorkspaceInfo,
|
|
||||||
confirmEmail,
|
confirmEmail,
|
||||||
createAcc,
|
createAcc,
|
||||||
createWorkspace,
|
createWorkspace,
|
||||||
@ -30,7 +29,8 @@ import {
|
|||||||
replacePassword,
|
replacePassword,
|
||||||
setAccountAdmin,
|
setAccountAdmin,
|
||||||
setRole,
|
setRole,
|
||||||
upgradeWorkspace
|
upgradeWorkspace,
|
||||||
|
WorkspaceInfo
|
||||||
} from '@hcengineering/account'
|
} from '@hcengineering/account'
|
||||||
import { setMetadata } from '@hcengineering/platform'
|
import { setMetadata } from '@hcengineering/platform'
|
||||||
import {
|
import {
|
||||||
@ -276,14 +276,23 @@ export function devTool (
|
|||||||
const workspaces = await listWorkspaces(db, productId)
|
const workspaces = await listWorkspaces(db, productId)
|
||||||
const withError: string[] = []
|
const withError: string[] = []
|
||||||
|
|
||||||
async function _upgradeWorkspace (ws: ClientWorkspaceInfo): Promise<void> {
|
async function _upgradeWorkspace (ws: WorkspaceInfo): Promise<void> {
|
||||||
const t = Date.now()
|
const t = Date.now()
|
||||||
const logger = cmd.console
|
const logger = cmd.console
|
||||||
? consoleModelLogger
|
? consoleModelLogger
|
||||||
: new FileModelLogger(path.join(cmd.logs, `${ws.workspace}.log`))
|
: new FileModelLogger(path.join(cmd.logs, `${ws.workspace}.log`))
|
||||||
console.log('---UPGRADING----', ws.workspace, !cmd.console ? (logger as FileModelLogger).file : '')
|
console.log('---UPGRADING----', ws.workspace, !cmd.console ? (logger as FileModelLogger).file : '')
|
||||||
try {
|
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)
|
console.log('---UPGRADING-DONE----', ws.workspace, Date.now() - t)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
withError.push(ws.workspace)
|
withError.push(ws.workspace)
|
||||||
|
@ -576,7 +576,7 @@ export async function createAccount (
|
|||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export async function listWorkspaces (db: Db, productId: string): Promise<ClientWorkspaceInfo[]> {
|
export async function listWorkspaces (db: Db, productId: string): Promise<WorkspaceInfo[]> {
|
||||||
return (await db.collection<Workspace>(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray())
|
return (await db.collection<Workspace>(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray())
|
||||||
.map((it) => ({ ...it, productId }))
|
.map((it) => ({ ...it, productId }))
|
||||||
.filter((it) => it.disabled !== true)
|
.filter((it) => it.disabled !== true)
|
||||||
@ -750,7 +750,7 @@ export async function upgradeWorkspace (
|
|||||||
}
|
}
|
||||||
const versionStr = versionToString(version)
|
const versionStr = versionToString(version)
|
||||||
|
|
||||||
const currentVersion = await db.collection<Workspace>(WORKSPACE_COLLECTION).findOne({ workspace: workspaceUrl })
|
const currentVersion = await db.collection<Workspace>(WORKSPACE_COLLECTION).findOne({ workspace: ws.workspace })
|
||||||
console.log(
|
console.log(
|
||||||
`${forceUpdate ? 'force-' : ''}upgrade from "${
|
`${forceUpdate ? 'force-' : ''}upgrade from "${
|
||||||
currentVersion?.version !== undefined ? versionToString(currentVersion.version) : ''
|
currentVersion?.version !== undefined ? versionToString(currentVersion.version) : ''
|
||||||
@ -761,13 +761,13 @@ export async function upgradeWorkspace (
|
|||||||
return versionStr
|
return versionStr
|
||||||
}
|
}
|
||||||
await db.collection(WORKSPACE_COLLECTION).updateOne(
|
await db.collection(WORKSPACE_COLLECTION).updateOne(
|
||||||
{ workspace: workspaceUrl },
|
{ workspace: ws.workspace },
|
||||||
{
|
{
|
||||||
$set: { version }
|
$set: { version }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
await (
|
await (
|
||||||
await upgradeModel(getTransactor(), getWorkspaceId(workspaceUrl, productId), txes, migrationOperation, logger)
|
await upgradeModel(getTransactor(), getWorkspaceId(ws.workspace, productId), txes, migrationOperation, logger)
|
||||||
).close()
|
).close()
|
||||||
return versionStr
|
return versionStr
|
||||||
}
|
}
|
||||||
@ -881,7 +881,7 @@ export type ClientWorkspaceInfo = Omit<Workspace, '_id' | 'accounts' | 'workspac
|
|||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export type WorkspaceInfo = Omit<Workspace, '_id' | 'accounts' | 'workspaceUrl'>
|
export type WorkspaceInfo = Omit<Workspace, '_id' | 'accounts'>
|
||||||
|
|
||||||
function mapToClientWorkspace (ws: Workspace): ClientWorkspaceInfo {
|
function mapToClientWorkspace (ws: Workspace): ClientWorkspaceInfo {
|
||||||
const { _id, accounts, ...data } = ws
|
const { _id, accounts, ...data } = ws
|
||||||
|
Loading…
Reference in New Issue
Block a user