-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from commons-stack/fix/upgrade_issues
Fix/upgrade issues
- Loading branch information
Showing
2 changed files
with
43 additions
and
65 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
packages/api/src/database/migrations/07_praise_reason_realized.ts
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
packages/api/src/database/migrations/12_praise_reason_realized.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |