|
|
|
@ -6,15 +6,12 @@ import {
|
|
|
|
|
Process, |
|
|
|
|
Processor, |
|
|
|
|
} from '@nestjs/bull'; |
|
|
|
|
import { Base, Column, Model, Project } from 'src/models'; |
|
|
|
|
import { Column, Model } from 'src/models'; |
|
|
|
|
import { Job } from 'bull'; |
|
|
|
|
import { ProjectsService } from 'src/services/projects.service'; |
|
|
|
|
import boxen from 'boxen'; |
|
|
|
|
import papaparse from 'papaparse'; |
|
|
|
|
import { |
|
|
|
|
findWithIdentifier, |
|
|
|
|
generateUniqueName, |
|
|
|
|
} from 'src/helpers/exportImportHelpers'; |
|
|
|
|
import { findWithIdentifier } from 'src/helpers/exportImportHelpers'; |
|
|
|
|
import { BulkDataAliasService } from 'src/services/bulk-data-alias.service'; |
|
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
|
import { forwardRef, Inject } from '@nestjs/common'; |
|
|
|
@ -76,6 +73,9 @@ export class DuplicateProcessor {
|
|
|
|
|
|
|
|
|
|
@Process('duplicate') |
|
|
|
|
async duplicateBase(job: Job) { |
|
|
|
|
const { project, base, dupProject, req } = job.data; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
let start = process.hrtime(); |
|
|
|
|
|
|
|
|
|
const debugLog = function (...args: any[]) { |
|
|
|
@ -91,23 +91,7 @@ export class DuplicateProcessor {
|
|
|
|
|
start = process.hrtime(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const param: { projectId: string; baseId?: string; req: any } = job.data; |
|
|
|
|
|
|
|
|
|
const user = (param.req as any).user; |
|
|
|
|
|
|
|
|
|
const project = await Project.get(param.projectId); |
|
|
|
|
|
|
|
|
|
if (!project) { |
|
|
|
|
throw new Error(`Base not found for id '${param.baseId}'`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const base = param?.baseId |
|
|
|
|
? await Base.get(param.baseId) |
|
|
|
|
: (await project.getBases())[0]; |
|
|
|
|
|
|
|
|
|
if (!base) { |
|
|
|
|
throw new Error(`Base not found!`); |
|
|
|
|
} |
|
|
|
|
const user = (req as any).user; |
|
|
|
|
|
|
|
|
|
const models = (await base.getModels()).filter( |
|
|
|
|
(m) => !m.mm && m.type === 'table', |
|
|
|
@ -123,24 +107,6 @@ export class DuplicateProcessor {
|
|
|
|
|
throw new Error(`Export failed for base '${base.id}'`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const projects = await Project.list({}); |
|
|
|
|
|
|
|
|
|
const uniqueTitle = generateUniqueName( |
|
|
|
|
`${project.title} copy`, |
|
|
|
|
projects.map((p) => p.title), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const dupProject = await this.projectsService.projectCreate({ |
|
|
|
|
project: { title: uniqueTitle, status: 'job' }, |
|
|
|
|
user: { id: user.id }, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.jobsGateway.jobStatus({ |
|
|
|
|
name: job.name, |
|
|
|
|
id: job.id.toString(), |
|
|
|
|
status: 'refresh', |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const dupBaseId = dupProject.bases[0].id; |
|
|
|
|
|
|
|
|
|
elapsedTime('projectCreate'); |
|
|
|
@ -150,7 +116,7 @@ export class DuplicateProcessor {
|
|
|
|
|
projectId: dupProject.id, |
|
|
|
|
baseId: dupBaseId, |
|
|
|
|
data: exportedModels, |
|
|
|
|
req: param.req, |
|
|
|
|
req: req, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
elapsedTime('importModels'); |
|
|
|
@ -181,7 +147,9 @@ export class DuplicateProcessor {
|
|
|
|
|
const headers: string[] = []; |
|
|
|
|
let chunk = []; |
|
|
|
|
|
|
|
|
|
const model = await Model.get(findWithIdentifier(idMap, sourceModel.id)); |
|
|
|
|
const model = await Model.get( |
|
|
|
|
findWithIdentifier(idMap, sourceModel.id), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
await new Promise((resolve) => { |
|
|
|
|
papaparse.parse(dataStream, { |
|
|
|
@ -366,5 +334,13 @@ export class DuplicateProcessor {
|
|
|
|
|
status: null, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|
if (dupProject?.id) { |
|
|
|
|
await this.projectsService.projectSoftDelete({ |
|
|
|
|
projectId: dupProject.id, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|