From d4bdb5d327e9535417af1868846586199c001e7f Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 9 Apr 2019 19:14:18 +0900 Subject: [PATCH] Update migrate.ts --- src/migrate.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/migrate.ts b/src/migrate.ts index 086ab6ab44..16fbc4bf81 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -289,6 +289,20 @@ async function main() { }); } + async function reMigrateUser(user: any) { + const u = await _User.findOne({ + _id: new mongo.ObjectId(user.id) + }); + const avatar = await DriveFiles.findOne(u.avatarId.toHexString()); + const banner = await DriveFiles.findOne(u.bannerId.toHexString()); + await Users.update(user.id, { + avatarId: avatar.id, + bannerId: banner.id, + avatarUrl: avatar.url, + bannerUrl: banner.url + }); + } + const allUsersCount = await _User.count(); for (let i = 0; i < allUsersCount; i++) { const user = await _User.findOne({}, { @@ -404,6 +418,21 @@ async function main() { console.error(e); } } + + const allActualUsersCount = await Users.count(); + for (let i = 0; i < allActualUsersCount; i++) { + const [user] = await Users.find({ + take: 1, + skip: i + }); + try { + await reMigrateUser(user); + console.log(`RE:USER (${i + 1}/${allActualUsersCount}) ${user.id} ${chalk.green('DONE')}`); + } catch (e) { + console.log(`RE:USER (${i + 1}/${allActualUsersCount}) ${user.id} ${chalk.red('ERR')}`); + console.error(e); + } + } } main();