diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-03-29 15:23:15 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-03-29 15:23:15 +0900 |
| commit | 31006fbc2570a3bf1f013190750b01f56a67c7b1 (patch) | |
| tree | 80296c243aa597a850213341b40491dd61b1ff0c /tools | |
| parent | Use @type (diff) | |
| download | misskey-31006fbc2570a3bf1f013190750b01f56a67c7b1.tar.gz misskey-31006fbc2570a3bf1f013190750b01f56a67c7b1.tar.bz2 misskey-31006fbc2570a3bf1f013190750b01f56a67c7b1.zip | |
#1253
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/migration/nighthike/5.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/migration/nighthike/5.js b/tools/migration/nighthike/5.js new file mode 100644 index 0000000000..fb72b69076 --- /dev/null +++ b/tools/migration/nighthike/5.js @@ -0,0 +1,47 @@ +// for Node.js interpret + +const { default: Post } = require('../../../built/api/models/post'); +const { default: zip } = require('@prezzemolo/zip') + +const migrate = async (post) => { + const result = await Post.update(post._id, { + $set: { + 'geo.type': 'Point', + 'geo.coordinates': [post.geo.longitude, post.geo.latitude] + }, + $unset: { + 'geo.longitude': '', + 'geo.latitude': '', + } + }); + return result.ok === 1; +} + +async function main() { + const count = await Post.count({ + 'geo': { $ne: null } + }); + + const dop = Number.parseInt(process.argv[2]) || 5 + const idop = ((count - (count % dop)) / dop) + 1 + + return zip( + 1, + async (time) => { + console.log(`${time} / ${idop}`) + const doc = await Post.find({ + 'geo': { $ne: null } + }, { + limit: dop, skip: time * dop + }) + return Promise.all(doc.map(migrate)) + }, + idop + ).then(a => { + const rv = [] + a.forEach(e => rv.push(...e)) + return rv + }) +} + +main().then(console.dir).catch(console.error) |