Browse Source

fix: ignore deleted projects audit while migrating metadata (#1723)

re #1722

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1724/head
Pranav C 3 years ago committed by GitHub
parent
commit
5aee6072e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts

24
packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts

@ -45,7 +45,7 @@ export default async function(ctx: NcUpgraderCtx) {
} }
await migrateUsers(ncMeta); await migrateUsers(ncMeta);
await migrateProjects(ncMeta); const projectsObj = await migrateProjects(ncMeta);
await migrateProjectUsers(ncMeta); await migrateProjectUsers(ncMeta);
const migrationCtx = await migrateProjectModels(ncMeta); const migrationCtx = await migrateProjectModels(ncMeta);
@ -54,7 +54,7 @@ export default async function(ctx: NcUpgraderCtx) {
await migrateSharedBase(ncMeta); await migrateSharedBase(ncMeta);
await migratePlugins(ncMeta); await migratePlugins(ncMeta);
await migrateWebhooks(migrationCtx, ncMeta); await migrateWebhooks(migrationCtx, ncMeta);
await migrateAutitLog(migrationCtx, ncMeta); await migrateAutitLog(migrationCtx, projectsObj, ncMeta);
} }
async function migrateUsers(ncMeta = Noco.ncMeta) { async function migrateUsers(ncMeta = Noco.ncMeta) {
@ -67,9 +67,11 @@ async function migrateUsers(ncMeta = Noco.ncMeta) {
return userList; return userList;
} }
async function migrateProjects(ncMeta = Noco.ncMeta) { async function migrateProjects(
ncMeta = Noco.ncMeta
): Promise<{ [projectId: string]: Project }> {
const projects = await ncMeta.projectList(); const projects = await ncMeta.projectList();
const projectList: Project[] = []; const projectsObj: { [projectId: string]: Project } = {};
for (const project of projects) { for (const project of projects) {
const projectConfig = JSON.parse(project.config); const projectConfig = JSON.parse(project.config);
@ -94,9 +96,10 @@ async function migrateProjects(ncMeta = Noco.ncMeta) {
created_at: project.created_at, created_at: project.created_at,
updated_at: project.updated_at updated_at: project.updated_at
}; };
const p = await Project.createProject(projectBody, ncMeta);
projectList.push(await Project.createProject(projectBody, ncMeta)); projectsObj[p.id] = p;
} }
return projectsObj;
} }
async function migrateProjectUsers(ncMeta = Noco.ncMeta) { 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<{ const audits: Array<{
user: string; user: string;
ip: string; ip: string;
@ -1257,6 +1264,9 @@ async function migrateAutitLog(ctx: MigrateCtxV1, ncMeta: any) {
}> = await ncMeta.metaList(null, null, 'nc_audit'); }> = await ncMeta.metaList(null, null, 'nc_audit');
for (const audit of audits) { for (const audit of audits) {
// skip deleted projects audit
if (!(audit.project_id in projectsObj)) continue;
const insertObj: any = { const insertObj: any = {
user: audit.user, user: audit.user,
ip: audit.ip, ip: audit.ip,

Loading…
Cancel
Save