Update migrate.ts

This commit is contained in:
syuilo 2019-04-09 19:14:18 +09:00
parent db4378415e
commit d4bdb5d327
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69

View file

@ -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();