Skip to content

Commit

Permalink
Merge pull request #445 from commons-stack/fix/upgrade_issues
Browse files Browse the repository at this point in the history
Fix/upgrade issues
  • Loading branch information
kristoferlund authored Jun 6, 2022
2 parents 9a7cbd0 + 1c99490 commit 8e275c2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 65 deletions.
65 changes: 0 additions & 65 deletions packages/api/src/database/migrations/07_praise_reason_realized.ts

This file was deleted.

43 changes: 43 additions & 0 deletions packages/api/src/database/migrations/12_praise_reason_realized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
realizeDiscordContent,
prepareDiscordClient,
} from '@praise/utils/core';
import { PraiseModel } from '@praise/entities';

const up = async (): Promise<void> => {
const praises = await PraiseModel.find({
reasonRealized: { $exists: false },
});

if (praises.length === 0) return;

const updates = await Promise.all(
praises.map((s) => {
let query = {};

query = {
updateOne: {
filter: { _id: s._id },
update: { $set: { reasonRealized: s.reason } },
},
};

return query;
})
);

await PraiseModel.bulkWrite(updates);
};

const down = async (): Promise<void> => {
await PraiseModel.updateMany(
{
reasonRealized: { $exists: true },
},
{
$unset: { reasonRealized: 1 },
}
);
};

export { up, down };

0 comments on commit 8e275c2

Please sign in to comment.