From 64f69979100e1bb856bd8cd44f5df20d54c124f8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 28 Mar 2018 18:43:49 +0900 Subject: [PATCH] =?UTF-8?q?=E8=89=AF=E3=81=84=E6=84=9F=E3=81=98=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1.js} | 3 +- .../2.js} | 3 +- tools/migration/nighthike/3.js | 73 +++++++++++++++++++ .../{shell.camel-case.js => nighthike/4.js} | 0 .../node.1522066477.user-account-keypair.js | 39 ---------- .../shell.1522038492.user-account.js | 41 ----------- tools/migration/shell.1522116709.user-host.js | 1 - .../shell.1522116710.user-host_lower.js | 1 - 8 files changed, 75 insertions(+), 86 deletions(-) rename tools/migration/{node.2018-03-28.username.js => nighthike/1.js} (86%) rename tools/migration/{node.2018-03-28.appname.js => nighthike/2.js} (86%) create mode 100644 tools/migration/nighthike/3.js rename tools/migration/{shell.camel-case.js => nighthike/4.js} (100%) delete mode 100644 tools/migration/node.1522066477.user-account-keypair.js delete mode 100644 tools/migration/shell.1522038492.user-account.js delete mode 100644 tools/migration/shell.1522116709.user-host.js delete mode 100644 tools/migration/shell.1522116710.user-host_lower.js diff --git a/tools/migration/node.2018-03-28.username.js b/tools/migration/nighthike/1.js similarity index 86% rename from tools/migration/node.2018-03-28.username.js rename to tools/migration/nighthike/1.js index 2222152101..d7e011c5bd 100644 --- a/tools/migration/node.2018-03-28.username.js +++ b/tools/migration/nighthike/1.js @@ -1,7 +1,6 @@ // for Node.js interpret -const { default: User } = require('../../built/api/models/user'); -const { generate } = require('../../built/crypto_key'); +const { default: User } = require('../../../built/api/models/user'); const { default: zip } = require('@prezzemolo/zip') const migrate = async (user) => { diff --git a/tools/migration/node.2018-03-28.appname.js b/tools/migration/nighthike/2.js similarity index 86% rename from tools/migration/node.2018-03-28.appname.js rename to tools/migration/nighthike/2.js index 9f16e47202..8fb5bbb08d 100644 --- a/tools/migration/node.2018-03-28.appname.js +++ b/tools/migration/nighthike/2.js @@ -1,7 +1,6 @@ // for Node.js interpret -const { default: App } = require('../../built/api/models/app'); -const { generate } = require('../../built/crypto_key'); +const { default: App } = require('../../../built/api/models/app'); const { default: zip } = require('@prezzemolo/zip') const migrate = async (app) => { diff --git a/tools/migration/nighthike/3.js b/tools/migration/nighthike/3.js new file mode 100644 index 0000000000..cc0603d9e4 --- /dev/null +++ b/tools/migration/nighthike/3.js @@ -0,0 +1,73 @@ +// for Node.js interpret + +const { default: User } = require('../../../built/api/models/user'); +const { generate } = require('../../../built/crypto_key'); +const { default: zip } = require('@prezzemolo/zip') + +const migrate = async (user) => { + const result = await User.update(user._id, { + $unset: { + email: '', + links: '', + password: '', + token: '', + twitter: '', + line: '', + profile: '', + last_used_at: '', + is_bot: '', + is_pro: '', + two_factor_secret: '', + two_factor_enabled: '', + client_settings: '', + settings: '' + }, + $set: { + host: null, + host_lower: null, + account: { + email: user.email, + links: user.links, + password: user.password, + token: user.token, + twitter: user.twitter, + line: user.line, + profile: user.profile, + last_used_at: user.last_used_at, + is_bot: user.is_bot, + is_pro: user.is_pro, + two_factor_secret: user.two_factor_secret, + two_factor_enabled: user.two_factor_enabled, + client_settings: user.client_settings, + settings: user.settings, + keypair: generate() + } + } + }); + return result.ok === 1; +} + +async function main() { + const count = await User.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 User.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/shell.camel-case.js b/tools/migration/nighthike/4.js similarity index 100% rename from tools/migration/shell.camel-case.js rename to tools/migration/nighthike/4.js diff --git a/tools/migration/node.1522066477.user-account-keypair.js b/tools/migration/node.1522066477.user-account-keypair.js deleted file mode 100644 index c413e3db1e..0000000000 --- a/tools/migration/node.1522066477.user-account-keypair.js +++ /dev/null @@ -1,39 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../built/api/models/user'); -const { generate } = require('../../built/crypto_key'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (user) => { - const result = await User.update(user._id, { - $set: { - 'account.keypair': generate() - } - }); - return result.ok === 1; -} - -async function main() { - const count = await User.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 User.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/shell.1522038492.user-account.js b/tools/migration/shell.1522038492.user-account.js deleted file mode 100644 index 056c29e8e1..0000000000 --- a/tools/migration/shell.1522038492.user-account.js +++ /dev/null @@ -1,41 +0,0 @@ -db.users.dropIndex({ token: 1 }); - -db.users.find({}).forEach(function(user) { - print(user._id); - db.users.update({ _id: user._id }, { - $unset: { - email: '', - links: '', - password: '', - token: '', - twitter: '', - line: '', - profile: '', - last_used_at: '', - is_bot: '', - is_pro: '', - two_factor_secret: '', - two_factor_enabled: '', - client_settings: '', - settings: '' - }, - $set: { - account: { - email: user.email, - links: user.links, - password: user.password, - token: user.token, - twitter: user.twitter, - line: user.line, - profile: user.profile, - last_used_at: user.last_used_at, - is_bot: user.is_bot, - is_pro: user.is_pro, - two_factor_secret: user.two_factor_secret, - two_factor_enabled: user.two_factor_enabled, - client_settings: user.client_settings, - settings: user.settings - } - } - }, false, false); -}); diff --git a/tools/migration/shell.1522116709.user-host.js b/tools/migration/shell.1522116709.user-host.js deleted file mode 100644 index b354709a61..0000000000 --- a/tools/migration/shell.1522116709.user-host.js +++ /dev/null @@ -1 +0,0 @@ -db.users.update({ }, { $set: { host: null } }, { multi: true }); diff --git a/tools/migration/shell.1522116710.user-host_lower.js b/tools/migration/shell.1522116710.user-host_lower.js deleted file mode 100644 index 31ec6c468a..0000000000 --- a/tools/migration/shell.1522116710.user-host_lower.js +++ /dev/null @@ -1 +0,0 @@ -db.users.update({ }, { $set: { host_lower: null } }, { multi: true });