From 5aee6072e3e4ba7ab78abaf9bab94aa4828fdd23 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sun, 17 Apr 2022 13:24:13 +0530 Subject: [PATCH] fix: ignore deleted projects audit while migrating metadata (#1723) re #1722 Signed-off-by: Pranav C --- .../jobs/ncProjectUpgraderV2_0090000.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts b/packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts index 5db8986e56..c216361f91 100644 --- a/packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts +++ b/packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts @@ -45,7 +45,7 @@ export default async function(ctx: NcUpgraderCtx) { } await migrateUsers(ncMeta); - await migrateProjects(ncMeta); + const projectsObj = await migrateProjects(ncMeta); await migrateProjectUsers(ncMeta); const migrationCtx = await migrateProjectModels(ncMeta); @@ -54,7 +54,7 @@ export default async function(ctx: NcUpgraderCtx) { await migrateSharedBase(ncMeta); await migratePlugins(ncMeta); await migrateWebhooks(migrationCtx, ncMeta); - await migrateAutitLog(migrationCtx, ncMeta); + await migrateAutitLog(migrationCtx, projectsObj, ncMeta); } async function migrateUsers(ncMeta = Noco.ncMeta) { @@ -67,9 +67,11 @@ async function migrateUsers(ncMeta = Noco.ncMeta) { return userList; } -async function migrateProjects(ncMeta = Noco.ncMeta) { +async function migrateProjects( + ncMeta = Noco.ncMeta +): Promise<{ [projectId: string]: Project }> { const projects = await ncMeta.projectList(); - const projectList: Project[] = []; + const projectsObj: { [projectId: string]: Project } = {}; for (const project of projects) { const projectConfig = JSON.parse(project.config); @@ -94,9 +96,10 @@ async function migrateProjects(ncMeta = Noco.ncMeta) { created_at: project.created_at, updated_at: project.updated_at }; - - projectList.push(await Project.createProject(projectBody, ncMeta)); + const p = await Project.createProject(projectBody, ncMeta); + projectsObj[p.id] = p; } + return projectsObj; } async function migrateProjectUsers(ncMeta = Noco.ncMeta) { @@ -1239,7 +1242,11 @@ async function migrateWebhooks(ctx: MigrateCtxV1, ncMeta: any) { } } -async function migrateAutitLog(ctx: MigrateCtxV1, ncMeta: any) { +async function migrateAutitLog( + ctx: MigrateCtxV1, + projectsObj: { [projectId: string]: Project }, + ncMeta: any +) { const audits: Array<{ user: string; ip: string; @@ -1257,6 +1264,9 @@ async function migrateAutitLog(ctx: MigrateCtxV1, ncMeta: any) { }> = await ncMeta.metaList(null, null, 'nc_audit'); for (const audit of audits) { + // skip deleted projects audit + if (!(audit.project_id in projectsObj)) continue; + const insertObj: any = { user: audit.user, ip: audit.ip,