From d44fc3db2f3160f487e622d9c578304c60578783 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 9 Apr 2019 18:45:21 +0900 Subject: [PATCH] Update migrate.ts --- src/migrate.ts | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/migrate.ts b/src/migrate.ts index ceaec4185d..7ee699116b 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -20,6 +20,7 @@ import { genId } from './misc/gen-id'; import { Poll } from './models/entities/poll'; import { PollVote } from './models/entities/poll-vote'; import { NoteFavorite } from './models/entities/note-favorite'; +import { NoteReaction } from './models/entities/note-reaction'; const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null; const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null; @@ -51,6 +52,7 @@ const _Note = db.get('notes'); const _Following = db.get('following'); const _PollVote = db.get('pollVotes'); const _Favorite = db.get('favorites'); +const _NoteReaction = db.get('noteReactions'); const getDriveFileBucket = async (): Promise => { const db = await nativeDbConn(); const bucket = new mongo.GridFSBucket(db, { @@ -69,6 +71,7 @@ async function main() { const Polls = getRepository(Poll); const PollVotes = getRepository(PollVote); const NoteFavorites = getRepository(NoteFavorite); + const NoteReactions = getRepository(NoteReaction); async function migrateUser(user: any) { await Users.insert({ @@ -255,6 +258,16 @@ async function main() { }); } + async function migrateNoteReaction(reaction: any) { + await NoteReactions.save({ + id: reaction._id.toHexString(), + createdAt: reaction.createdAt, + noteId: reaction.noteId.toHexString(), + userId: reaction.userId.toHexString(), + reaction: reaction.reaction + }); + } + const allUsersCount = await _User.count(); for (let i = 0; i < allUsersCount; i++) { const user = await _User.findOne({}, { @@ -290,9 +303,9 @@ async function main() { }); try { await migrateDriveFolder(folder); - console.log(`DRIVEFOLDER (${i + 1}/${allDriveFoldersCount}) ${folder._id} ${chalk.green('DONE')}`); + console.log(`FOLDER (${i + 1}/${allDriveFoldersCount}) ${folder._id} ${chalk.green('DONE')}`); } catch (e) { - console.log(`DRIVEFOLDER (${i + 1}/${allDriveFoldersCount}) ${folder._id} ${chalk.red('ERR')}`); + console.log(`FOLDER (${i + 1}/${allDriveFoldersCount}) ${folder._id} ${chalk.red('ERR')}`); console.error(e); } } @@ -304,9 +317,9 @@ async function main() { }); try { await migrateDriveFile(file); - console.log(`DRIVEFILE (${i + 1}/${allDriveFilesCount}) ${file._id} ${chalk.green('DONE')}`); + console.log(`FILE (${i + 1}/${allDriveFilesCount}) ${file._id} ${chalk.green('DONE')}`); } catch (e) { - console.log(`DRIVEFILE (${i + 1}/${allDriveFilesCount}) ${file._id} ${chalk.red('ERR')}`); + console.log(`FILE (${i + 1}/${allDriveFilesCount}) ${file._id} ${chalk.red('ERR')}`); console.error(e); } } @@ -336,9 +349,9 @@ async function main() { }); try { await migratePollVote(vote); - console.log(`POLLVOTE (${i + 1}/${allPollVotesCount}) ${vote._id} ${chalk.green('DONE')}`); + console.log(`VOTE (${i + 1}/${allPollVotesCount}) ${vote._id} ${chalk.green('DONE')}`); } catch (e) { - console.log(`POLLVOTE (${i + 1}/${allPollVotesCount}) ${vote._id} ${chalk.red('ERR')}`); + console.log(`VOTE (${i + 1}/${allPollVotesCount}) ${vote._id} ${chalk.red('ERR')}`); console.error(e); } } @@ -356,6 +369,20 @@ async function main() { console.error(e); } } + + const allNoteReactionsCount = await _NoteReaction.count(); + for (let i = 0; i < allNoteReactionsCount; i++) { + const reaction = await _NoteReaction.findOne({}, { + skip: i + }); + try { + await migrateNoteReaction(reaction); + console.log(`REACTION (${i + 1}/${allNoteReactionsCount}) ${reaction._id} ${chalk.green('DONE')}`); + } catch (e) { + console.log(`REACTION (${i + 1}/${allNoteReactionsCount}) ${reaction._id} ${chalk.red('ERR')}`); + console.error(e); + } + } } main();