fix: migration

This commit is contained in:
Mohamed Marrouchi 2025-01-17 17:50:35 +01:00
parent 356b16aa9d
commit b74c4a4e3a
3 changed files with 103 additions and 93 deletions

View File

@ -259,7 +259,7 @@ module.exports = {
attachmentService: this.attachmentService,
});
if (result && migrationDocument) {
if (result) {
await this.successCallback({
version,
action,

View File

@ -208,6 +208,7 @@ const populateSubscriberAvatars = async ({ logger }: MigrationServices) => {
const cursor = SubscriberModel.find().cursor();
for await (const subscriber of cursor) {
try {
const foreignId = subscriber.foreign_id;
if (!foreignId) {
logger.debug(`No foreign id found for subscriber ${subscriber._id}`);
@ -273,6 +274,10 @@ const populateSubscriberAvatars = async ({ logger }: MigrationServices) => {
`No avatar attachment found for subscriber ${subscriber._id}`,
);
}
} catch (err) {
logger.error(err);
logger.error(`Unable to populate subscriber avatar ${subscriber._id}`);
}
}
};
@ -295,6 +300,7 @@ const unpopulateSubscriberAvatar = async ({ logger }: MigrationServices) => {
const cursor = SubscriberModel.find({ avatar: { $exists: true } }).cursor();
for await (const subscriber of cursor) {
try {
if (subscriber.avatar) {
const attachment = await AttachmentModel.findOne({
_id: subscriber.avatar,
@ -340,6 +346,10 @@ const unpopulateSubscriberAvatar = async ({ logger }: MigrationServices) => {
);
}
}
} catch (err) {
logger.error(err);
logger.error(`Unable to unpopulate subscriber ${subscriber._id} avatar`);
}
}
};

View File

@ -33,7 +33,7 @@ export interface MigrationRunOneParams extends MigrationRunParams {
}
export interface MigrationSuccessCallback extends MigrationRunParams {
migrationDocument: MigrationDocument;
migrationDocument: MigrationDocument | null;
}
export type MigrationServices = {