mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 12:35:02 +02:00
Qfix: empty where clause (#6793)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
+23
-8
@@ -140,6 +140,7 @@ export async function moveAccountDbFromMongoToPG (
|
||||
mongoDb: AccountDB,
|
||||
pgDb: AccountDB
|
||||
): Promise<void> {
|
||||
// [accountId, workspaceId]
|
||||
const workspaceAssignments: [ObjectId, ObjectId][] = []
|
||||
const accounts = await listAccounts(mongoDb)
|
||||
const workspaces = await listWorkspacesPure(mongoDb)
|
||||
@@ -153,14 +154,18 @@ export async function moveAccountDbFromMongoToPG (
|
||||
|
||||
delete (pgAccount as any).workspaces
|
||||
|
||||
if (pgAccount.createdOn === undefined) {
|
||||
pgAccount.createdOn = Date.now()
|
||||
}
|
||||
|
||||
for (const workspace of mongoAccount.workspaces) {
|
||||
workspaceAssignments.push([pgAccount._id, workspace.toString()])
|
||||
}
|
||||
|
||||
const exists = await getAccount(pgDb, pgAccount.email)
|
||||
if (exists === null) {
|
||||
await pgDb.account.insertOne(pgAccount)
|
||||
ctx.info('Moved account', { email: pgAccount.email })
|
||||
|
||||
for (const workspace of mongoAccount.workspaces) {
|
||||
workspaceAssignments.push([pgAccount._id, workspace.toString()])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,9 +207,19 @@ export async function moveAccountDbFromMongoToPG (
|
||||
}
|
||||
}
|
||||
|
||||
if (workspaceAssignments.length > 0) {
|
||||
for (const [accountId, workspaceId] of workspaceAssignments) {
|
||||
await pgDb.assignWorkspace(accountId, workspaceId)
|
||||
}
|
||||
const pgAssignments = (await listAccounts(pgDb)).reduce<Record<ObjectId, ObjectId[]>>((assignments, acc) => {
|
||||
assignments[acc._id] = acc.workspaces
|
||||
|
||||
return assignments
|
||||
}, {})
|
||||
const assignmentsToInsert = workspaceAssignments.filter(
|
||||
([accountId, workspaceId]) =>
|
||||
pgAssignments[accountId] === undefined || !pgAssignments[accountId].includes(workspaceId)
|
||||
)
|
||||
|
||||
for (const [accountId, workspaceId] of assignmentsToInsert) {
|
||||
await pgDb.assignWorkspace(accountId, workspaceId)
|
||||
}
|
||||
|
||||
ctx.info('Assignments made', { count: assignmentsToInsert.length })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user