diff --git a/dev/tool/src/db.ts b/dev/tool/src/db.ts index d55013cb73..34f376ae3d 100644 --- a/dev/tool/src/db.ts +++ b/dev/tool/src/db.ts @@ -154,12 +154,20 @@ export async function moveAccountDbFromMongoToPG ( delete (pgAccount as any).workspaces - if (pgAccount.createdOn === undefined) { + if (pgAccount.createdOn == null) { pgAccount.createdOn = Date.now() } - for (const workspace of mongoAccount.workspaces) { - workspaceAssignments.push([pgAccount._id, workspace.toString()]) + if (pgAccount.first == null) { + pgAccount.first = 'NotSet' + } + + if (pgAccount.last == null) { + pgAccount.last = 'NotSet' + } + + for (const workspaceString of new Set(mongoAccount.workspaces.map((w) => w.toString()))) { + workspaceAssignments.push([pgAccount._id, workspaceString]) } const exists = await getAccount(pgDb, pgAccount.email) @@ -175,6 +183,10 @@ export async function moveAccountDbFromMongoToPG ( _id: mongoWorkspace._id.toString() } + if (pgWorkspace.createdOn == null) { + pgWorkspace.createdOn = Date.now() + } + // delete deprecated fields delete (pgWorkspace as any).createProgress delete (pgWorkspace as any).creating