mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: migration
This commit is contained in:
parent
356b16aa9d
commit
b74c4a4e3a
@ -259,7 +259,7 @@ module.exports = {
|
|||||||
attachmentService: this.attachmentService,
|
attachmentService: this.attachmentService,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result && migrationDocument) {
|
if (result) {
|
||||||
await this.successCallback({
|
await this.successCallback({
|
||||||
version,
|
version,
|
||||||
action,
|
action,
|
||||||
|
@ -208,6 +208,7 @@ const populateSubscriberAvatars = async ({ logger }: MigrationServices) => {
|
|||||||
const cursor = SubscriberModel.find().cursor();
|
const cursor = SubscriberModel.find().cursor();
|
||||||
|
|
||||||
for await (const subscriber of cursor) {
|
for await (const subscriber of cursor) {
|
||||||
|
try {
|
||||||
const foreignId = subscriber.foreign_id;
|
const foreignId = subscriber.foreign_id;
|
||||||
if (!foreignId) {
|
if (!foreignId) {
|
||||||
logger.debug(`No foreign id found for subscriber ${subscriber._id}`);
|
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}`,
|
`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();
|
const cursor = SubscriberModel.find({ avatar: { $exists: true } }).cursor();
|
||||||
|
|
||||||
for await (const subscriber of cursor) {
|
for await (const subscriber of cursor) {
|
||||||
|
try {
|
||||||
if (subscriber.avatar) {
|
if (subscriber.avatar) {
|
||||||
const attachment = await AttachmentModel.findOne({
|
const attachment = await AttachmentModel.findOne({
|
||||||
_id: subscriber.avatar,
|
_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`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export interface MigrationRunOneParams extends MigrationRunParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MigrationSuccessCallback extends MigrationRunParams {
|
export interface MigrationSuccessCallback extends MigrationRunParams {
|
||||||
migrationDocument: MigrationDocument;
|
migrationDocument: MigrationDocument | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MigrationServices = {
|
export type MigrationServices = {
|
||||||
|
Loading…
Reference in New Issue
Block a user