Browse Source

fix: better scan and confirm existing ids

nc-feat/attachment-clean-up
mertmit 4 months ago
parent
commit
ad4b5f671c
  1. 1
      packages/nocodb/src/models/FileReference.ts
  2. 27
      packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

1
packages/nocodb/src/models/FileReference.ts

@ -29,6 +29,7 @@ export default class FileReference {
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
const insertObj = extractProps(fileRefObj, [ const insertObj = extractProps(fileRefObj, [
'id',
'storage', 'storage',
'file_url', 'file_url',
'file_size', 'file_size',

27
packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

@ -86,8 +86,13 @@ export class AttachmentMigration {
fileReferenceBuffer.push({ file_path: file }); fileReferenceBuffer.push({ file_path: file });
if (fileReferenceBuffer.length >= 100) { if (fileReferenceBuffer.length >= 100) {
fileScanStream.pause();
try { try {
const processBuffer = fileReferenceBuffer.splice(0); const processBuffer = fileReferenceBuffer.splice(
0,
fileReferenceBuffer.length,
);
filesCount += processBuffer.length; filesCount += processBuffer.length;
@ -124,6 +129,8 @@ export class AttachmentMigration {
this.log(e); this.log(e);
err = e; err = e;
} }
fileScanStream.resume();
} }
}); });
@ -370,6 +377,24 @@ export class AttachmentMigration {
}); });
updateRequired = true; updateRequired = true;
} else {
const fileReference = await FileReference.get(
context,
attachment.id,
);
if (!fileReference) {
await FileReference.insert(context, {
id: attachment.id,
source_id: source.id,
fk_model_id,
fk_column_id: column.id,
file_url: attachment.path || attachment.url,
file_size: attachment.size,
is_external: !source.isMeta(),
deleted: false,
});
}
} }
} }
} catch (e) { } catch (e) {

Loading…
Cancel
Save