mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-24 15:16:07 +09:00
wip migration
This commit is contained in:
parent
1d16c44b1b
commit
9dcff01640
@ -12,6 +12,7 @@
|
||||
"scripts": {
|
||||
"start": "node ./index.js",
|
||||
"init": "node ./built/init.js",
|
||||
"migrate": "node ./built/migrate.js",
|
||||
"debug": "DEBUG=misskey:* node ./index.js",
|
||||
"build": "webpack && gulp build",
|
||||
"webpack": "webpack",
|
||||
@ -66,6 +67,8 @@
|
||||
"@types/lolex": "3.1.1",
|
||||
"@types/minio": "7.0.1",
|
||||
"@types/mocha": "5.2.6",
|
||||
"@types/mongodb": "3.1.22",
|
||||
"@types/monk": "6.0.0",
|
||||
"@types/node": "11.10.4",
|
||||
"@types/nodemailer": "4.6.6",
|
||||
"@types/nprogress": "0.0.29",
|
||||
@ -168,6 +171,8 @@
|
||||
"mocha": "6.0.2",
|
||||
"moji": "0.5.1",
|
||||
"moment": "2.24.0",
|
||||
"mongodb": "3.2.3",
|
||||
"monk": "6.0.6",
|
||||
"ms": "2.1.1",
|
||||
"nested-property": "0.0.7",
|
||||
"node-fetch": "2.3.0",
|
||||
|
43
src/migrate.ts
Normal file
43
src/migrate.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import mongo from 'monk';
|
||||
import config from './config';
|
||||
import { initDb } from './db/postgre';
|
||||
import { User } from './models/entities/user';
|
||||
import { getRepository } from 'typeorm';
|
||||
import generateUserToken from './server/api/common/generate-native-user-token';
|
||||
|
||||
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
|
||||
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
|
||||
|
||||
const uri = `mongodb://${u && p ? `${u}:${p}@` : ''}${(config as any).mongodb.host}:${(config as any).mongodb.port}/${(config as any).mongodb.db}`;
|
||||
|
||||
const db = mongo(uri);
|
||||
|
||||
const _User = db.get<any>('users');
|
||||
|
||||
async function main() {
|
||||
await initDb();
|
||||
const Users = getRepository(User);
|
||||
|
||||
const allUsersCount = await _User.count();
|
||||
|
||||
for (let i = 0; i < allUsersCount; i++) {
|
||||
const user = await _User.findOne({}, {
|
||||
skip: i
|
||||
});
|
||||
await Users.save({
|
||||
id: user._id.toHexString(),
|
||||
createdAt: user.createdAt || new Date(),
|
||||
username: user.username,
|
||||
usernameLower: user.username.toLowerCase(),
|
||||
host: user.host,
|
||||
token: generateUserToken(),
|
||||
password: user.password,
|
||||
isAdmin: user.isAdmin,
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false
|
||||
});
|
||||
console.log(`USER (${i + 1}/${allUsersCount}) ${user.id} DONE`);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue
Block a user