This commit is contained in:
syuilo 2018-07-24 23:35:19 +09:00
parent a048939cf1
commit 5e9fb8bd84
6 changed files with 15 additions and 53 deletions

View file

@ -1,57 +0,0 @@
// 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);

View file

@ -1,71 +0,0 @@
// 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 User.count({});
let prev;
for (let i = 0; i < count; i++) {
promiseGens.push(() => {
const promise = new Promise(async (res, rej) => {
const user = await User.findOne(prev ? {
_id: { $gt: prev._id }
} : {}, {
sort: {
_id: 1
}
});
prev = user;
const set = {};
if (user.avatarId != null) {
const file = await DriveFile.findOne({ _id: user.avatarId });
if (file && file.metadata.properties.avgColor) {
set.avatarColor = file.metadata.properties.avgColor;
}
}
if (user.bannerId != null) {
const file = await DriveFile.findOne({ _id: user.bannerId });
if (file && file.metadata.properties.avgColor) {
set.bannerColor = file.metadata.properties.avgColor;
}
}
if (Object.keys(set).length === 0) return res([i, user]);
User.update({
_id: user._id
}, {
$set: set
}).then(() => {
res([i, user]);
}).catch(rej);
});
promise.then(([i, user]) => {
console.log(chalk`{gray ${i}} {green done: {bold ${user._id}} @${user.username}}`);
});
return promise;
});
}
return await sequential(promiseGens);
}
main().then(() => {
console.log('ALL DONE');
}).catch(console.error);

View file

@ -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 が生成されます

View file

@ -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"