UBERF-5986: Upgrade fixes (#4957)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2024-03-14 11:24:25 +06:00
committed by GitHub
parent 768d57348b
commit 27e46ef3ae
7 changed files with 167 additions and 27 deletions
+22 -1
View File
@@ -604,6 +604,27 @@ export async function listWorkspaces (db: Db, productId: string): Promise<Worksp
.map(trimWorkspaceInfo)
}
/**
* @public
*/
export async function listWorkspacesRaw (db: Db, productId: string): Promise<Workspace[]> {
return (await db.collection<Workspace>(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray()).map(
(it) => ({ ...it, productId })
)
}
/**
* @public
*/
export async function updateWorkspace (
db: Db,
productId: string,
info: Workspace,
ops: Partial<Workspace>
): Promise<void> {
await db.collection<Workspace>(WORKSPACE_COLLECTION).updateOne({ _id: info._id }, { $set: { ...info, ...ops } })
}
/**
* @public
*/
@@ -772,7 +793,7 @@ export async function upgradeWorkspace (
const versionStr = versionToString(version)
console.log(
`${forceUpdate ? 'force-' : ''}upgrade from "${
`${workspaceUrl} - ${forceUpdate ? 'force-' : ''}upgrade from "${
ws?.version !== undefined ? versionToString(ws.version) : ''
}" to "${versionStr}"`
)
+3 -1
View File
@@ -183,7 +183,9 @@ export class MigrateClientImpl implements MigrationClient {
async create<T extends Doc>(domain: Domain, doc: T | T[]): Promise<void> {
if (Array.isArray(doc)) {
await this.db.collection(domain).insertMany(doc as Document[])
if (doc.length > 0) {
await this.db.collection(domain).insertMany(doc as Document[])
}
} else {
await this.db.collection(domain).insertOne(doc as Document)
}