From d81c20f163f0884d04cd11e46221bfefc0ac9f22 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 14 Apr 2018 14:39:07 +0900 Subject: hostLowerは廃止してhostにlowerしたものを入れるように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/note.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'src/models/note.ts') diff --git a/src/models/note.ts b/src/models/note.ts index 3c1c2e18e1..6d315db4cf 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -66,7 +66,6 @@ export type INote = { }; _user: { host: string; - hostLower: string; account: { inbox?: string; }; -- cgit v1.2.3-freya From 0ef280377bbbd357bef688ab5c7fd609fd78af72 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 15 Apr 2018 06:34:55 +0900 Subject: wip --- src/models/note.ts | 11 ++++++++--- src/models/notification.ts | 27 +++++++++++++++++++++++++++ src/models/user.ts | 11 +++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) (limited to 'src/models/note.ts') diff --git a/src/models/note.ts b/src/models/note.ts index 6d315db4cf..1dcc70c175 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -5,13 +5,13 @@ import db from '../db/mongodb'; import { IUser, pack as packUser } from './user'; import { pack as packApp } from './app'; import { pack as packChannel } from './channel'; -import Vote, { deletePollVote } from './poll-vote'; +import PollVote, { deletePollVote } from './poll-vote'; import Reaction, { deleteNoteReaction } from './note-reaction'; import { pack as packFile } from './drive-file'; import NoteWatching, { deleteNoteWatching } from './note-watching'; import NoteReaction from './note-reaction'; import Favorite, { deleteFavorite } from './favorite'; -import PollVote from './poll-vote'; +import Notification, { deleteNotification } from './notification'; const Note = db.get('notes'); @@ -123,6 +123,11 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { await Favorite.find({ noteId: n._id }) ).map(x => deleteFavorite(x))); + // この投稿に対するNotificationをすべて削除 + await Promise.all(( + await Notification.find({ noteId: n._id }) + ).map(x => deleteNotification(x))); + // このNoteを削除 await Note.remove({ _id: n._id @@ -258,7 +263,7 @@ export const pack = async ( // Poll if (meId && _note.poll) { _note.poll = (async (poll) => { - const vote = await Vote + const vote = await PollVote .findOne({ userId: meId, noteId: id diff --git a/src/models/notification.ts b/src/models/notification.ts index d5ca7135b7..76871166a9 100644 --- a/src/models/notification.ts +++ b/src/models/notification.ts @@ -49,6 +49,33 @@ export interface INotification { isRead: Boolean; } +/** + * Notificationを物理削除します + */ +export async function deleteNotification(notification: string | mongo.ObjectID | INotification) { + let n: INotification; + + // Populate + if (mongo.ObjectID.prototype.isPrototypeOf(notification)) { + n = await Notification.findOne({ + _id: notification + }); + } else if (typeof notification === 'string') { + n = await Notification.findOne({ + _id: new mongo.ObjectID(notification) + }); + } else { + n = notification as INotification; + } + + if (n == null) return; + + // このNotificationを削除 + await Notification.remove({ + _id: n._id + }); +} + /** * Pack a notification for API response */ diff --git a/src/models/user.ts b/src/models/user.ts index 686bcc5ec5..56ca0c625f 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -19,6 +19,7 @@ import PollVote, { deletePollVote } from './poll-vote'; import FollowingLog, { deleteFollowingLog } from './following-log'; import FollowedLog, { deleteFollowedLog } from './followed-log'; import SwSubscription, { deleteSwSubscription } from './sw-subscription'; +import Notification, { deleteNotification } from './notification'; const User = db.get('users'); @@ -246,6 +247,16 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await SwSubscription.find({ userId: u._id }) ).map(x => deleteSwSubscription(x))); + // このユーザーのNotificationをすべて削除 + await Promise.all(( + await Notification.find({ notifieeId: u._id }) + ).map(x => deleteNotification(x))); + + // このユーザーが原因となったNotificationをすべて削除 + await Promise.all(( + await Notification.find({ notifierId: u._id }) + ).map(x => deleteNotification(x))); + // このユーザーを削除 } -- cgit v1.2.3-freya From 69c452a9809d0af933b3137651b9a18327d3e8a7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 15 Apr 2018 11:57:33 +0900 Subject: :pizza: --- cli/del-usr.js | 13 ++ cli/init.js | 162 ++++++++++++++++++++++++ migration/README.md | 11 ++ migration/init-migration-file.sh | 37 ++++++ src/models/drive-file.ts | 9 +- src/models/note.ts | 4 + src/models/user.ts | 4 + tools/init-migration-file.sh | 37 ------ tools/init.js | 162 ------------------------ tools/migration/README.md | 11 -- tools/migration/nighthike/1.js | 39 ------ tools/migration/nighthike/10.js | 3 - tools/migration/nighthike/11.js | 36 ------ tools/migration/nighthike/12.js | 58 --------- tools/migration/nighthike/2.js | 39 ------ tools/migration/nighthike/3.js | 73 ----------- tools/migration/nighthike/4.js | 262 --------------------------------------- tools/migration/nighthike/5.js | 49 -------- tools/migration/nighthike/6.js | 13 -- tools/migration/nighthike/7.js | 41 ------ tools/migration/nighthike/8.js | 40 ------ tools/migration/nighthike/9.js | 93 -------------- 22 files changed, 238 insertions(+), 958 deletions(-) create mode 100644 cli/del-usr.js create mode 100644 cli/init.js create mode 100644 migration/README.md create mode 100644 migration/init-migration-file.sh delete mode 100755 tools/init-migration-file.sh delete mode 100644 tools/init.js delete mode 100644 tools/migration/README.md delete mode 100644 tools/migration/nighthike/1.js delete mode 100644 tools/migration/nighthike/10.js delete mode 100644 tools/migration/nighthike/11.js delete mode 100644 tools/migration/nighthike/12.js delete mode 100644 tools/migration/nighthike/2.js delete mode 100644 tools/migration/nighthike/3.js delete mode 100644 tools/migration/nighthike/4.js delete mode 100644 tools/migration/nighthike/5.js delete mode 100644 tools/migration/nighthike/6.js delete mode 100644 tools/migration/nighthike/7.js delete mode 100644 tools/migration/nighthike/8.js delete mode 100644 tools/migration/nighthike/9.js (limited to 'src/models/note.ts') diff --git a/cli/del-usr.js b/cli/del-usr.js new file mode 100644 index 0000000000..08e97845ec --- /dev/null +++ b/cli/del-usr.js @@ -0,0 +1,13 @@ +const deleteUser = require('../built/models/user').deleteUser; + +const args = process.argv.slice(2); + +const userId = args[0]; + +console.log(`deleting ${userId}...`); + +deleteUser(userId).then(() => { + console.log('done'); +}, e => { + console.error(e); +}); diff --git a/cli/init.js b/cli/init.js new file mode 100644 index 0000000000..7a3e7d1b51 --- /dev/null +++ b/cli/init.js @@ -0,0 +1,162 @@ +const fs = require('fs'); +const path = require('path'); +const yaml = require('js-yaml'); +const inquirer = require('inquirer'); +const chalk = require('chalk'); + +const configDirPath = `${__dirname}/../.config`; +const configPath = `${configDirPath}/default.yml`; + +const form = [{ + type: 'input', + name: 'maintainerName', + message: 'Your name:' +}, { + type: 'input', + name: 'maintainerUrl', + message: 'Your home page URL or your mailto URL:' +}, { + type: 'input', + name: 'url', + message: 'URL you want to run Misskey:' +}, { + type: 'input', + name: 'port', + message: 'Listen port (e.g. 443):' +}, { + type: 'confirm', + name: 'https', + message: 'Use TLS?', + default: false +}, { + type: 'input', + name: 'https_key', + message: 'Path of tls key:', + when: ctx => ctx.https +}, { + type: 'input', + name: 'https_cert', + message: 'Path of tls cert:', + when: ctx => ctx.https +}, { + type: 'input', + name: 'https_ca', + message: 'Path of tls ca:', + when: ctx => ctx.https +}, { + type: 'input', + name: 'mongo_host', + message: 'MongoDB\'s host:', + default: 'localhost' +}, { + type: 'input', + name: 'mongo_port', + message: 'MongoDB\'s port:', + default: '27017' +}, { + type: 'input', + name: 'mongo_db', + message: 'MongoDB\'s db:', + default: 'misskey' +}, { + type: 'input', + name: 'mongo_user', + message: 'MongoDB\'s user:' +}, { + type: 'password', + name: 'mongo_pass', + message: 'MongoDB\'s password:' +}, { + type: 'input', + name: 'redis_host', + message: 'Redis\'s host:', + default: 'localhost' +}, { + type: 'input', + name: 'redis_port', + message: 'Redis\'s port:', + default: '6379' +}, { + type: 'password', + name: 'redis_pass', + message: 'Redis\'s password:' +}, { + type: 'confirm', + name: 'elasticsearch', + message: 'Use Elasticsearch?', + default: false +}, { + type: 'input', + name: 'es_host', + message: 'Elasticsearch\'s host:', + default: 'localhost', + when: ctx => ctx.elasticsearch +}, { + type: 'input', + name: 'es_port', + message: 'Elasticsearch\'s port:', + default: '9200', + when: ctx => ctx.elasticsearch +}, { + type: 'password', + name: 'es_pass', + message: 'Elasticsearch\'s password:', + when: ctx => ctx.elasticsearch +}, { + type: 'input', + name: 'recaptcha_site', + message: 'reCAPTCHA\'s site key:' +}, { + type: 'input', + name: 'recaptcha_secret', + message: 'reCAPTCHA\'s secret key:' +}]; + +inquirer.prompt(form).then(as => { + // Mapping answers + const conf = { + maintainer: { + name: as['maintainerName'], + url: as['maintainerUrl'] + }, + url: as['url'], + port: parseInt(as['port'], 10), + https: { + enable: as['https'], + key: as['https_key'] || null, + cert: as['https_cert'] || null, + ca: as['https_ca'] || null + }, + mongodb: { + host: as['mongo_host'], + port: parseInt(as['mongo_port'], 10), + db: as['mongo_db'], + user: as['mongo_user'], + pass: as['mongo_pass'] + }, + redis: { + host: as['redis_host'], + port: parseInt(as['redis_port'], 10), + pass: as['redis_pass'] + }, + elasticsearch: { + enable: as['elasticsearch'], + host: as['es_host'] || null, + port: parseInt(as['es_port'], 10) || null, + pass: as['es_pass'] || null + }, + recaptcha: { + siteKey: as['recaptcha_site'], + secretKey: as['recaptcha_secret'] + } + }; + + console.log(`Thanks. Writing the configuration to ${chalk.bold(path.resolve(configPath))}`); + + try { + fs.writeFileSync(configPath, yaml.dump(conf)); + console.log(chalk.green('Well done.')); + } catch (e) { + console.error(e); + } +}); diff --git a/migration/README.md b/migration/README.md new file mode 100644 index 0000000000..d52e84b35a --- /dev/null +++ b/migration/README.md @@ -0,0 +1,11 @@ +Misskeyの破壊的変更に対応するいくつかのスニペットがあります。 +MongoDBシェルで実行する必要のあるものとnodeで直接実行する必要のあるものがあります。 +ファイル名が `shell.` から始まるものは前者、 `node.` から始まるものは後者です。 + +MongoDBシェルで実行する場合、`use`でデータベースを選択しておく必要があります。 + +nodeで実行するいくつかのスニペットは、並列処理させる数を引数で設定できるものがあります。 +処理中にエラーで落ちる場合は、メモリが足りていない可能性があるので、少ない数に設定してみてください。 +※デフォルトは`5`です。 + +ファイルを作成する際は `../init-migration-file.sh -t _type_ -n _name_` を実行すると _type_._unixtime_._name_.js が生成されます diff --git a/migration/init-migration-file.sh b/migration/init-migration-file.sh new file mode 100644 index 0000000000..c6a2b862e6 --- /dev/null +++ b/migration/init-migration-file.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +usage() { + echo "$0 [-t type] [-n name]" + echo " type: [node | shell]" + echo " name: if no present, set untitled" + exit 0 +} + +while getopts :t:n:h OPT +do + case $OPT in + t) type=$OPTARG + ;; + n) name=$OPTARG + ;; + h) usage + ;; + \?) usage + ;; + :) usage + ;; + esac +done + +if [ "$type" = "" ] +then + echo "no type present!!!" + usage +fi + +if [ "$name" = "" ] +then + name="untitled" +fi + +touch "$(realpath $(dirname $BASH_SOURCE))/migration/$type.$(date +%s).$name.js" diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index 80fe8e0300..fc9c150724 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -84,14 +84,19 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv // このDriveFileがアバターやバナーに使われていたらそれらのプロパティをnullにする const u = await User.findOne({ _id: d.metadata.userId }); if (u) { - if (u.avatarId.equals(d._id)) { + if (u.avatarId && u.avatarId.equals(d._id)) { await User.update({ _id: u._id }, { $set: { avatarId: null } }); } - if (u.bannerId.equals(d._id)) { + if (u.bannerId && u.bannerId.equals(d._id)) { await User.update({ _id: u._id }, { $set: { bannerId: null } }); } } + // このDriveFileのチャンクをすべて削除 + await monkDb.get('driveFiles.chunks').remove({ + files_id: d._id + }); + // このDriveFileを削除 await DriveFile.remove({ _id: d._id diff --git a/src/models/note.ts b/src/models/note.ts index 1dcc70c175..3059593540 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -91,6 +91,8 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { n = note as INote; } + console.log(n == null ? `Note: delete skipped ${note}` : `Note: deleting ${n._id}`); + if (n == null) return; // このNoteへの返信をすべて削除 @@ -132,6 +134,8 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { await Note.remove({ _id: n._id }); + + console.log(`Note: deleted ${n._id}`); } /** diff --git a/src/models/user.ts b/src/models/user.ts index f18206120f..449a563002 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -155,6 +155,8 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { u = user as IUser; } + console.log(u == null ? `User: delete skipped ${user}` : `User: deleting ${u._id}`); + if (u == null) return; // このユーザーのAccessTokenをすべて削除 @@ -261,6 +263,8 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await User.remove({ _id: u._id }); + + console.log(`User: deleted ${u._id}`); } /** diff --git a/tools/init-migration-file.sh b/tools/init-migration-file.sh deleted file mode 100755 index c6a2b862e6..0000000000 --- a/tools/init-migration-file.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -usage() { - echo "$0 [-t type] [-n name]" - echo " type: [node | shell]" - echo " name: if no present, set untitled" - exit 0 -} - -while getopts :t:n:h OPT -do - case $OPT in - t) type=$OPTARG - ;; - n) name=$OPTARG - ;; - h) usage - ;; - \?) usage - ;; - :) usage - ;; - esac -done - -if [ "$type" = "" ] -then - echo "no type present!!!" - usage -fi - -if [ "$name" = "" ] -then - name="untitled" -fi - -touch "$(realpath $(dirname $BASH_SOURCE))/migration/$type.$(date +%s).$name.js" diff --git a/tools/init.js b/tools/init.js deleted file mode 100644 index 7a3e7d1b51..0000000000 --- a/tools/init.js +++ /dev/null @@ -1,162 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const yaml = require('js-yaml'); -const inquirer = require('inquirer'); -const chalk = require('chalk'); - -const configDirPath = `${__dirname}/../.config`; -const configPath = `${configDirPath}/default.yml`; - -const form = [{ - type: 'input', - name: 'maintainerName', - message: 'Your name:' -}, { - type: 'input', - name: 'maintainerUrl', - message: 'Your home page URL or your mailto URL:' -}, { - type: 'input', - name: 'url', - message: 'URL you want to run Misskey:' -}, { - type: 'input', - name: 'port', - message: 'Listen port (e.g. 443):' -}, { - type: 'confirm', - name: 'https', - message: 'Use TLS?', - default: false -}, { - type: 'input', - name: 'https_key', - message: 'Path of tls key:', - when: ctx => ctx.https -}, { - type: 'input', - name: 'https_cert', - message: 'Path of tls cert:', - when: ctx => ctx.https -}, { - type: 'input', - name: 'https_ca', - message: 'Path of tls ca:', - when: ctx => ctx.https -}, { - type: 'input', - name: 'mongo_host', - message: 'MongoDB\'s host:', - default: 'localhost' -}, { - type: 'input', - name: 'mongo_port', - message: 'MongoDB\'s port:', - default: '27017' -}, { - type: 'input', - name: 'mongo_db', - message: 'MongoDB\'s db:', - default: 'misskey' -}, { - type: 'input', - name: 'mongo_user', - message: 'MongoDB\'s user:' -}, { - type: 'password', - name: 'mongo_pass', - message: 'MongoDB\'s password:' -}, { - type: 'input', - name: 'redis_host', - message: 'Redis\'s host:', - default: 'localhost' -}, { - type: 'input', - name: 'redis_port', - message: 'Redis\'s port:', - default: '6379' -}, { - type: 'password', - name: 'redis_pass', - message: 'Redis\'s password:' -}, { - type: 'confirm', - name: 'elasticsearch', - message: 'Use Elasticsearch?', - default: false -}, { - type: 'input', - name: 'es_host', - message: 'Elasticsearch\'s host:', - default: 'localhost', - when: ctx => ctx.elasticsearch -}, { - type: 'input', - name: 'es_port', - message: 'Elasticsearch\'s port:', - default: '9200', - when: ctx => ctx.elasticsearch -}, { - type: 'password', - name: 'es_pass', - message: 'Elasticsearch\'s password:', - when: ctx => ctx.elasticsearch -}, { - type: 'input', - name: 'recaptcha_site', - message: 'reCAPTCHA\'s site key:' -}, { - type: 'input', - name: 'recaptcha_secret', - message: 'reCAPTCHA\'s secret key:' -}]; - -inquirer.prompt(form).then(as => { - // Mapping answers - const conf = { - maintainer: { - name: as['maintainerName'], - url: as['maintainerUrl'] - }, - url: as['url'], - port: parseInt(as['port'], 10), - https: { - enable: as['https'], - key: as['https_key'] || null, - cert: as['https_cert'] || null, - ca: as['https_ca'] || null - }, - mongodb: { - host: as['mongo_host'], - port: parseInt(as['mongo_port'], 10), - db: as['mongo_db'], - user: as['mongo_user'], - pass: as['mongo_pass'] - }, - redis: { - host: as['redis_host'], - port: parseInt(as['redis_port'], 10), - pass: as['redis_pass'] - }, - elasticsearch: { - enable: as['elasticsearch'], - host: as['es_host'] || null, - port: parseInt(as['es_port'], 10) || null, - pass: as['es_pass'] || null - }, - recaptcha: { - siteKey: as['recaptcha_site'], - secretKey: as['recaptcha_secret'] - } - }; - - console.log(`Thanks. Writing the configuration to ${chalk.bold(path.resolve(configPath))}`); - - try { - fs.writeFileSync(configPath, yaml.dump(conf)); - console.log(chalk.green('Well done.')); - } catch (e) { - console.error(e); - } -}); diff --git a/tools/migration/README.md b/tools/migration/README.md deleted file mode 100644 index d52e84b35a..0000000000 --- a/tools/migration/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Misskeyの破壊的変更に対応するいくつかのスニペットがあります。 -MongoDBシェルで実行する必要のあるものとnodeで直接実行する必要のあるものがあります。 -ファイル名が `shell.` から始まるものは前者、 `node.` から始まるものは後者です。 - -MongoDBシェルで実行する場合、`use`でデータベースを選択しておく必要があります。 - -nodeで実行するいくつかのスニペットは、並列処理させる数を引数で設定できるものがあります。 -処理中にエラーで落ちる場合は、メモリが足りていない可能性があるので、少ない数に設定してみてください。 -※デフォルトは`5`です。 - -ファイルを作成する際は `../init-migration-file.sh -t _type_ -n _name_` を実行すると _type_._unixtime_._name_.js が生成されます diff --git a/tools/migration/nighthike/1.js b/tools/migration/nighthike/1.js deleted file mode 100644 index 6ae30ad4f9..0000000000 --- a/tools/migration/nighthike/1.js +++ /dev/null @@ -1,39 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../../built/models/user'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (user) => { - const result = await User.update(user._id, { - $set: { - 'username': user.username.replace(/\-/g, '_'), - 'username_lower': user.username_lower.replace(/\-/g, '_') - } - }); - 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/nighthike/10.js b/tools/migration/nighthike/10.js deleted file mode 100644 index 3c57b8d484..0000000000 --- a/tools/migration/nighthike/10.js +++ /dev/null @@ -1,3 +0,0 @@ -db.following.remove({ - deletedAt: { $exists: true } -}); diff --git a/tools/migration/nighthike/11.js b/tools/migration/nighthike/11.js deleted file mode 100644 index 2a4e8630d4..0000000000 --- a/tools/migration/nighthike/11.js +++ /dev/null @@ -1,36 +0,0 @@ -db.pollVotes.update({}, { - $rename: { - postId: 'noteId', - } -}, false, true); - -db.postReactions.renameCollection('noteReactions'); -db.noteReactions.update({}, { - $rename: { - postId: 'noteId', - } -}, false, true); - -db.postWatching.renameCollection('noteWatching'); -db.noteWatching.update({}, { - $rename: { - postId: 'noteId', - } -}, false, true); - -db.posts.renameCollection('notes'); -db.notes.update({}, { - $rename: { - _repost: '_renote', - repostId: 'renoteId', - repostCount: 'renoteCount' - } -}, false, true); - -db.users.update({}, { - $rename: { - postsCount: 'notesCount', - pinnedPostId: 'pinnedNoteId', - latestPost: 'latestNote' - } -}, false, true); diff --git a/tools/migration/nighthike/12.js b/tools/migration/nighthike/12.js deleted file mode 100644 index f4b61e2ee8..0000000000 --- a/tools/migration/nighthike/12.js +++ /dev/null @@ -1,58 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../../built/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: { - account: '' - }, - $set: { - host: null, - hostLower: null, - email: user.account.email, - links: user.account.links, - password: user.account.password, - token: user.account.token, - twitter: user.account.twitter, - line: user.account.line, - profile: user.account.profile, - lastUsedAt: user.account.lastUsedAt, - isBot: user.account.isBot, - isPro: user.account.isPro, - twoFactorSecret: user.account.twoFactorSecret, - twoFactorEnabled: user.account.twoFactorEnabled, - clientSettings: user.account.clientSettings, - settings: user.account.settings, - keypair: user.account.keypair - } - }); - 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/nighthike/2.js b/tools/migration/nighthike/2.js deleted file mode 100644 index bb516db5b7..0000000000 --- a/tools/migration/nighthike/2.js +++ /dev/null @@ -1,39 +0,0 @@ -// for Node.js interpret - -const { default: App } = require('../../../built/models/app'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (app) => { - const result = await App.update(app._id, { - $set: { - 'name_id': app.name_id.replace(/\-/g, '_'), - 'name_id_lower': app.name_id_lower.replace(/\-/g, '_') - } - }); - return result.ok === 1; -} - -async function main() { - const count = await App.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 App.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/3.js b/tools/migration/nighthike/3.js deleted file mode 100644 index bde4f773d2..0000000000 --- a/tools/migration/nighthike/3.js +++ /dev/null @@ -1,73 +0,0 @@ -// for Node.js interpret - -const { default: User } = require('../../../built/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/nighthike/4.js b/tools/migration/nighthike/4.js deleted file mode 100644 index 5e12e64055..0000000000 --- a/tools/migration/nighthike/4.js +++ /dev/null @@ -1,262 +0,0 @@ -// このスクリプトを走らせる前か後に notifications コレクションはdropしてください - -db.access_tokens.renameCollection('accessTokens'); -db.accessTokens.update({}, { - $rename: { - created_at: 'createdAt', - app_id: 'appId', - user_id: 'userId', - } -}, false, true); - -db.apps.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - name_id: 'nameId', - name_id_lower: 'nameIdLower', - callback_url: 'callbackUrl', - } -}, false, true); - -db.auth_sessions.renameCollection('authSessions'); -db.authSessions.update({}, { - $rename: { - created_at: 'createdAt', - app_id: 'appId', - user_id: 'userId', - } -}, false, true); - -db.channel_watching.renameCollection('channelWatching'); -db.channelWatching.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - channel_id: 'channelId', - user_id: 'userId', - } -}, false, true); - -db.channels.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - watching_count: 'watchingCount' - } -}, false, true); - -db.drive_files.files.renameCollection('driveFiles.files'); -db.drive_files.chunks.renameCollection('driveFiles.chunks'); -db.driveFiles.files.update({}, { - $rename: { - 'metadata.user_id': 'metadata.userId' - } -}, false, true); -db.driveFiles.files.update({ - 'metadata.folder_id': { $ne: null } -}, { - $rename: { - 'metadata.folder_id': 'metadata.folderId', - } -}, false, true); -db.driveFiles.files.update({ - 'metadata.properties.average_color': { $ne: null } -}, { - $rename: { - 'metadata.properties.average_color': 'metadata.properties.avgColor' - } -}, false, true); - -db.drive_folders.renameCollection('driveFolders'); -db.driveFolders.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - parent_id: 'parentId', - } -}, false, true); - -db.favorites.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId', - } -}, false, true); - -db.following.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - followee_id: 'followeeId', - follower_id: 'followerId', - } -}, false, true); - -db.messaging_histories.renameCollection('messagingHistories'); -db.messagingHistories.update({}, { - $rename: { - updated_at: 'updatedAt', - user_id: 'userId', - partner: 'partnerId', - message: 'messageId', - } -}, false, true); - -db.messaging_messages.renameCollection('messagingMessages'); -db.messagingMessages.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - recipient_id: 'recipientId', - file_id: 'fileId', - is_read: 'isRead' - } -}, false, true); - -db.mute.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - mutee_id: 'muteeId', - muter_id: 'muterId', - } -}, false, true); - -db.othello_games.renameCollection('othelloGames'); -db.othelloGames.update({}, { - $rename: { - created_at: 'createdAt', - started_at: 'startedAt', - is_started: 'isStarted', - is_ended: 'isEnded', - user1_id: 'user1Id', - user2_id: 'user2Id', - user1_accepted: 'user1Accepted', - user2_accepted: 'user2Accepted', - winner_id: 'winnerId', - 'settings.is_llotheo': 'settings.isLlotheo', - 'settings.can_put_everywhere': 'settings.canPutEverywhere', - 'settings.looped_board': 'settings.loopedBoard', - } -}, false, true); - -db.othello_matchings.renameCollection('othelloMatchings'); -db.othelloMatchings.update({}, { - $rename: { - created_at: 'createdAt', - parent_id: 'parentId', - child_id: 'childId' - } -}, false, true); - -db.poll_votes.renameCollection('pollVotes'); -db.pollVotes.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId' - } -}, false, true); - -db.post_reactions.renameCollection('postReactions'); -db.postReactions.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId' - } -}, false, true); - -db.post_watching.renameCollection('postWatching'); -db.postWatching.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - post_id: 'postId' - } -}, false, true); - -db.posts.update({}, { - $rename: { - created_at: 'createdAt', - channel_id: 'channelId', - user_id: 'userId', - app_id: 'appId', - media_ids: 'mediaIds', - reply_id: 'replyId', - repost_id: 'repostId', - via_mobile: 'viaMobile', - reaction_counts: 'reactionCounts', - replies_count: 'repliesCount', - repost_count: 'repostCount' - } -}, false, true); - -db.posts.update({ - _reply: { $ne: null } -}, { - $rename: { - '_reply.user_id': '_reply.userId', - } -}, false, true); - -db.posts.update({ - _repost: { $ne: null } -}, { - $rename: { - '_repost.user_id': '_repost.userId', - } -}, false, true); - -db.signin.update({}, { - $rename: { - created_at: 'createdAt', - user_id: 'userId', - } -}, false, true); - -db.sw_subscriptions.renameCollection('swSubscriptions'); -db.swSubscriptions.update({}, { - $rename: { - user_id: 'userId', - } -}, false, true); - -db.users.update({}, { - $unset: { - likes_count: '', - liked_count: '', - latest_post: '', - 'account.twitter.access_token': '', - 'account.twitter.access_token_secret': '', - 'account.twitter.user_id': '', - 'account.twitter.screen_name': '', - 'account.line.user_id': '', - 'account.client_settings.mobile_home': '' - } -}, false, true); - -db.users.update({}, { - $rename: { - created_at: 'createdAt', - deleted_at: 'deletedAt', - followers_count: 'followersCount', - following_count: 'followingCount', - posts_count: 'postsCount', - drive_capacity: 'driveCapacity', - username_lower: 'usernameLower', - avatar_id: 'avatarId', - banner_id: 'bannerId', - pinned_post_id: 'pinnedPostId', - is_suspended: 'isSuspended', - host_lower: 'hostLower', - 'account.last_used_at': 'account.lastUsedAt', - 'account.is_bot': 'account.isBot', - 'account.is_pro': 'account.isPro', - 'account.two_factor_secret': 'account.twoFactorSecret', - 'account.two_factor_enabled': 'account.twoFactorEnabled', - 'account.client_settings': 'account.clientSettings' - } -}, false, true); diff --git a/tools/migration/nighthike/5.js b/tools/migration/nighthike/5.js deleted file mode 100644 index 3989ea6301..0000000000 --- a/tools/migration/nighthike/5.js +++ /dev/null @@ -1,49 +0,0 @@ -// for Node.js interpret - -const mongodb = require("../../../built/db/mongodb"); -const Post = mongodb.default.get('posts'); - -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) diff --git a/tools/migration/nighthike/6.js b/tools/migration/nighthike/6.js deleted file mode 100644 index 27fff2ec19..0000000000 --- a/tools/migration/nighthike/6.js +++ /dev/null @@ -1,13 +0,0 @@ -db.posts.update({ - $or: [{ - mediaIds: null - }, { - mediaIds: { - $exists: false - } - }] -}, { - $set: { - mediaIds: [] - } -}, false, true); diff --git a/tools/migration/nighthike/7.js b/tools/migration/nighthike/7.js deleted file mode 100644 index ed5f1e6b96..0000000000 --- a/tools/migration/nighthike/7.js +++ /dev/null @@ -1,41 +0,0 @@ -// for Node.js interpret - -const mongodb = require("../../../built/db/mongodb"); -const Post = mongodb.default.get('posts'); -const { default: zip } = require('@prezzemolo/zip') -const html = require('../../../built/text/html').default; -const parse = require('../../../built/text/parse').default; - -const migrate = async (post) => { - const result = await Post.update(post._id, { - $set: { - textHtml: post.text ? html(parse(post.text)) : null - } - }); - 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 deleted file mode 100644 index e4f4482dba..0000000000 --- a/tools/migration/nighthike/8.js +++ /dev/null @@ -1,40 +0,0 @@ -// for Node.js interpret - -const { default: Message } = require('../../../built/models/messaging-message'); -const { default: zip } = require('@prezzemolo/zip') -const html = require('../../../built/text/html').default; -const parse = require('../../../built/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) diff --git a/tools/migration/nighthike/9.js b/tools/migration/nighthike/9.js deleted file mode 100644 index f4e1ab341e..0000000000 --- a/tools/migration/nighthike/9.js +++ /dev/null @@ -1,93 +0,0 @@ -// for Node.js interpret - -const { default: Following } = require('../../../built/models/following'); -const { default: FollowingLog } = require('../../../built/models/following-log'); -const { default: FollowedLog } = require('../../../built/models/followed-log'); -const { default: zip } = require('@prezzemolo/zip') - -const migrate = async (following) => { - const followingCount = await Following.count({ - followerId: following.followerId, - createdAt: { $lt: following.createdAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowingLog.insert({ - createdAt: following.createdAt, - userId: following.followerId, - count: followingCount + 1 - }); - - const followersCount = await Following.count({ - followeeId: following.followeeId, - createdAt: { $lt: following.createdAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowedLog.insert({ - createdAt: following.createdAt, - userId: following.followeeId, - count: followersCount + 1 - }); - - if (following.deletedAt) { - const followingCount2 = await Following.count({ - followerId: following.followerId, - createdAt: { $lt: following.deletedAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowingLog.insert({ - createdAt: following.deletedAt, - userId: following.followerId, - count: followingCount2 - 1 - }); - - const followersCount2 = await Following.count({ - followeeId: following.followeeId, - createdAt: { $lt: following.deletedAt }, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: following.createdAt } } - ] - }); - await FollowedLog.insert({ - createdAt: following.deletedAt, - userId: following.followeeId, - count: followersCount2 - 1 - }); - } - - return true; -} - -async function main() { - const count = await Following.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 Following.find({}, { - limit: dop, skip: time * dop, sort: { _id: 1 } - }) - 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) -- cgit v1.2.3-freya