summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-31 21:54:29 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-31 21:54:29 +0900
commit621c36c42be3b2d9cbea525e4929f2155c28c5ab (patch)
treecbb2c5249cd8dc512bff48a73bc15581f143e7cf /tools
parentUpdate migration script (diff)
downloadmisskey-621c36c42be3b2d9cbea525e4929f2155c28c5ab.tar.gz
misskey-621c36c42be3b2d9cbea525e4929f2155c28c5ab.tar.bz2
misskey-621c36c42be3b2d9cbea525e4929f2155c28c5ab.zip
Update migration script
Diffstat (limited to 'tools')
-rw-r--r--tools/migration/nighthike/7.js44
-rw-r--r--tools/migration/nighthike/8.js40
2 files changed, 74 insertions, 10 deletions
diff --git a/tools/migration/nighthike/7.js b/tools/migration/nighthike/7.js
index c5055da8ba..c8efb8952b 100644
--- a/tools/migration/nighthike/7.js
+++ b/tools/migration/nighthike/7.js
@@ -1,16 +1,40 @@
-// for Node.js interpretation
+// for Node.js interpret
-const Message = require('../../../built/models/messaging-message').default;
-const Post = require('../../../built/models/post').default;
+const { default: Post } = require('../../../built/api/models/post');
+const { default: zip } = require('@prezzemolo/zip')
const html = require('../../../built/common/text/html').default;
const parse = require('../../../built/common/text/parse').default;
-Promise.all([Message, Post].map(async model => {
- const documents = await model.find();
-
- return Promise.all(documents.map(({ _id, text }) => model.update(_id, {
+const migrate = async (post) => {
+ const result = await Post.update(post._id, {
$set: {
- textHtml: html(parse(text))
+ textHtml: post.text ? html(parse(post.text)) : null
}
- })));
-})).catch(console.error).then(process.exit);
+ });
+ return result.ok === 1;
+}
+
+async function main() {
+ const count = await Post.count({});
+
+ 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({}, {
+ 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)
diff --git a/tools/migration/nighthike/8.js b/tools/migration/nighthike/8.js
new file mode 100644
index 0000000000..5e0cf95078
--- /dev/null
+++ b/tools/migration/nighthike/8.js
@@ -0,0 +1,40 @@
+// for Node.js interpret
+
+const { default: Message } = require('../../../built/api/models/message');
+const { default: zip } = require('@prezzemolo/zip')
+const html = require('../../../built/common/text/html').default;
+const parse = require('../../../built/common/text/parse').default;
+
+const migrate = async (message) => {
+ const result = await Message.update(message._id, {
+ $set: {
+ textHtml: message.text ? html(parse(message.text)) : null
+ }
+ });
+ return result.ok === 1;
+}
+
+async function main() {
+ const count = await Message.count({});
+
+ 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 Message.find({}, {
+ 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)