diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-07-24 23:35:19 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-07-24 23:35:19 +0900 |
| commit | 5e9fb8bd848d97da2e00f4e7f7fbe5e77e82b9b8 (patch) | |
| tree | af4de153bd238305f5bf01722b3dfc2561ba0d00 /cli/migration/2.0.0.js | |
| parent | wip (diff) | |
| download | misskey-5e9fb8bd848d97da2e00f4e7f7fbe5e77e82b9b8.tar.gz misskey-5e9fb8bd848d97da2e00f4e7f7fbe5e77e82b9b8.tar.bz2 misskey-5e9fb8bd848d97da2e00f4e7f7fbe5e77e82b9b8.zip | |
wip
Diffstat (limited to 'cli/migration/2.0.0.js')
| -rw-r--r-- | cli/migration/2.0.0.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/cli/migration/2.0.0.js b/cli/migration/2.0.0.js new file mode 100644 index 0000000000..f7298972e5 --- /dev/null +++ b/cli/migration/2.0.0.js @@ -0,0 +1,57 @@ +// for Node.js interpret + +const chalk = require('chalk'); +const sequential = require('promise-sequential'); + +const { default: User } = require('../../built/models/user'); +const { default: DriveFile } = require('../../built/models/drive-file'); + +async function main() { + const promiseGens = []; + + const count = await DriveFile.count({}); + + let prev; + + for (let i = 0; i < count; i++) { + promiseGens.push(() => { + const promise = new Promise(async (res, rej) => { + const file = await DriveFile.findOne(prev ? { + _id: { $gt: prev._id } + } : {}, { + sort: { + _id: 1 + } + }); + + prev = file; + + const user = await User.findOne({ _id: file.metadata.userId }); + + DriveFile.update({ + _id: file._id + }, { + $set: { + 'metadata._user': { + host: user.host + } + } + }).then(() => { + res([i, file]); + }).catch(rej); + }); + + promise.then(([i, file]) => { + console.log(chalk`{gray ${i}} {green done: {bold ${file._id}} ${file.filename}}`); + }); + + return promise; + }); + } + + return await sequential(promiseGens); +} + +main().then(() => { + console.log('ALL DONE'); +}).catch(console.error); |