mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: migration
This commit is contained in:
parent
356b16aa9d
commit
b74c4a4e3a
@ -259,7 +259,7 @@ module.exports = {
|
||||
attachmentService: this.attachmentService,
|
||||
});
|
||||
|
||||
if (result && migrationDocument) {
|
||||
if (result) {
|
||||
await this.successCallback({
|
||||
version,
|
||||
action,
|
||||
|
@ -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`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ export interface MigrationRunOneParams extends MigrationRunParams {
|
||||
}
|
||||
|
||||
export interface MigrationSuccessCallback extends MigrationRunParams {
|
||||
migrationDocument: MigrationDocument;
|
||||
migrationDocument: MigrationDocument | null;
|
||||
}
|
||||
|
||||
export type MigrationServices = {
|
||||
|
Loading…
Reference in New Issue
Block a user