Attachment migration, add error logs

This commit is contained in:
Martin Filser 2022-02-16 22:24:54 +01:00 committed by Denis Perov
parent 368fe24956
commit 47ca6829eb
2 changed files with 21 additions and 21 deletions

View file

@ -26,7 +26,7 @@ export const createOnAfterUpload = bucket =>
// and we unlink the file from the fs on any error // and we unlink the file from the fs on any error
// that occurred during the upload to prevent zombie files // that occurred during the upload to prevent zombie files
.on('error', err => { .on('error', err => {
// console.error(err); console.error("[createOnAfterUpload error]", err);
self.unlink(this.collection.findOne(file._id), versionName); // Unlink files from FS self.unlink(this.collection.findOne(file._id), versionName); // Unlink files from FS
}) })

View file

@ -1146,8 +1146,12 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
const readStream = fileObj.createReadStream('attachments'); const readStream = fileObj.createReadStream('attachments');
const writeStream = fs.createWriteStream(filePath); const writeStream = fs.createWriteStream(filePath);
writeStream.on('error', function(err) { writeStream.on('error', error => {
console.log('Writing error: ', err, filePath); console.error('[writeStream error]: ', error, filePath);
});
readStream.on('error', error => {
console.error('[readStream error]: ', error, filePath);
}); });
// Once we have a file, then upload it to our new data storage // Once we have a file, then upload it to our new data storage
@ -1171,11 +1175,11 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
size: fileSize, size: fileSize,
fileId, fileId,
}, },
(err, fileRef) => { (error, fileRef) => {
if (err) { if (error) {
console.log(err); console.error('[Attachments#addFile error]: ', error);
} else { } else {
console.log('File Inserted: ', fileRef._id); console.log('File Inserted: ', fileRef);
// Set the userId again // Set the userId again
Attachments.update({ _id: fileRef._id }, { $set: { userId } }); Attachments.update({ _id: fileRef._id }, { $set: { userId } });
fileObj.remove(); fileObj.remove();
@ -1185,10 +1189,6 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
); // proceedAfterUpload ); // proceedAfterUpload
}); });
readStream.on('error', error => {
console.log('Error: ', filePath, error);
});
readStream.pipe(writeStream); readStream.pipe(writeStream);
}); });
}); });
@ -1213,8 +1213,12 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
const readStream = fileObj.createReadStream('avatars'); const readStream = fileObj.createReadStream('avatars');
const writeStream = fs.createWriteStream(filePath); const writeStream = fs.createWriteStream(filePath);
writeStream.on('error', function(err) { writeStream.on('error', error => {
console.log('Writing error: ', err, filePath); console.error('[writeStream error]: ', error, filePath);
});
readStream.on('error', error => {
console.error('[readStream error]: ', error, filePath);
}); });
// Once we have a file, then upload it to our new data storage // Once we have a file, then upload it to our new data storage
@ -1237,11 +1241,11 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
size: fileSize, size: fileSize,
fileId, fileId,
}, },
(err, fileRef) => { (error, fileRef) => {
if (err) { if (error) {
console.log(err); console.error('[Avatars#addFile error]: ', error);
} else { } else {
console.log('File Inserted: ', newFileName, fileRef._id); console.log('File Inserted: ', newFileName, fileRef);
// Set the userId again // Set the userId again
Avatars.update({ _id: fileRef._id }, { $set: { userId } }); Avatars.update({ _id: fileRef._id }, { $set: { userId } });
Users.find().forEach(user => { Users.find().forEach(user => {
@ -1267,10 +1271,6 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
); );
}); });
readStream.on('error', error => {
console.log('Error: ', filePath, error);
});
readStream.pipe(writeStream); readStream.pipe(writeStream);
}); });
}); });