Update migrate.ts
This commit is contained in:
parent
91c1ceefbd
commit
dea3e2132e
1 changed files with 27 additions and 16 deletions
|
@ -35,6 +35,8 @@ const uri = `mongodb://${u && p ? `${u}:${p}@` : ''}${(config as any).mongodb.ho
|
||||||
const db = monk(uri);
|
const db = monk(uri);
|
||||||
let mdb: mongo.Db;
|
let mdb: mongo.Db;
|
||||||
|
|
||||||
|
const test = false;
|
||||||
|
|
||||||
const nativeDbConn = async (): Promise<mongo.Db> => {
|
const nativeDbConn = async (): Promise<mongo.Db> => {
|
||||||
if (mdb) return mdb;
|
if (mdb) return mdb;
|
||||||
|
|
||||||
|
@ -91,14 +93,14 @@ async function main() {
|
||||||
usernameLower: user.username.toLowerCase(),
|
usernameLower: user.username.toLowerCase(),
|
||||||
host: toPuny(user.host),
|
host: toPuny(user.host),
|
||||||
token: generateUserToken(),
|
token: generateUserToken(),
|
||||||
isAdmin: user.isAdmin,
|
isAdmin: user.isAdmin || false,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
followersCount: user.followersCount,
|
followersCount: user.followersCount || 0,
|
||||||
followingCount: user.followingCount,
|
followingCount: user.followingCount || 0,
|
||||||
notesCount: user.notesCount,
|
notesCount: user.notesCount || 0,
|
||||||
isBot: user.isBot,
|
isBot: user.isBot || false,
|
||||||
isCat: user.isCat,
|
isCat: user.isCat || false,
|
||||||
isVerified: user.isVerified,
|
isVerified: user.isVerified || false,
|
||||||
inbox: user.inbox,
|
inbox: user.inbox,
|
||||||
sharedInbox: user.sharedInbox,
|
sharedInbox: user.sharedInbox,
|
||||||
uri: user.uri,
|
uri: user.uri,
|
||||||
|
@ -321,7 +323,8 @@ async function main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const allUsersCount = await _User.count();
|
let allUsersCount = await _User.count();
|
||||||
|
if (test && allUsersCount > 1000) allUsersCount = 1000;
|
||||||
for (let i = 0; i < allUsersCount; i++) {
|
for (let i = 0; i < allUsersCount; i++) {
|
||||||
const user = await _User.findOne({}, {
|
const user = await _User.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -335,7 +338,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allFollowingsCount = await _Following.count();
|
let allFollowingsCount = await _Following.count();
|
||||||
|
if (test && allFollowingsCount > 1000) allFollowingsCount = 1000;
|
||||||
for (let i = 0; i < allFollowingsCount; i++) {
|
for (let i = 0; i < allFollowingsCount; i++) {
|
||||||
const following = await _Following.findOne({}, {
|
const following = await _Following.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -349,7 +353,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allDriveFoldersCount = await _DriveFolder.count();
|
let allDriveFoldersCount = await _DriveFolder.count();
|
||||||
|
if (test && allDriveFoldersCount > 1000) allDriveFoldersCount = 1000;
|
||||||
for (let i = 0; i < allDriveFoldersCount; i++) {
|
for (let i = 0; i < allDriveFoldersCount; i++) {
|
||||||
const folder = await _DriveFolder.findOne({}, {
|
const folder = await _DriveFolder.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -363,7 +368,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allDriveFilesCount = await _DriveFile.count();
|
let allDriveFilesCount = await _DriveFile.count();
|
||||||
|
if (test && allDriveFilesCount > 1000) allDriveFilesCount = 1000;
|
||||||
for (let i = 0; i < allDriveFilesCount; i++) {
|
for (let i = 0; i < allDriveFilesCount; i++) {
|
||||||
const file = await _DriveFile.findOne({}, {
|
const file = await _DriveFile.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -377,9 +383,10 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allNotesCount = await _Note.count({
|
let allNotesCount = await _Note.count({
|
||||||
'_user.host': null
|
'_user.host': null
|
||||||
});
|
});
|
||||||
|
if (test && allNotesCount > 1000) allNotesCount = 1000;
|
||||||
for (let i = 0; i < allNotesCount; i++) {
|
for (let i = 0; i < allNotesCount; i++) {
|
||||||
const note = await _Note.findOne({
|
const note = await _Note.findOne({
|
||||||
'_user.host': null
|
'_user.host': null
|
||||||
|
@ -395,7 +402,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPollVotesCount = await _PollVote.count();
|
let allPollVotesCount = await _PollVote.count();
|
||||||
|
if (test && allPollVotesCount > 1000) allPollVotesCount = 1000;
|
||||||
for (let i = 0; i < allPollVotesCount; i++) {
|
for (let i = 0; i < allPollVotesCount; i++) {
|
||||||
const vote = await _PollVote.findOne({}, {
|
const vote = await _PollVote.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -409,7 +417,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allNoteFavoritesCount = await _Favorite.count();
|
let allNoteFavoritesCount = await _Favorite.count();
|
||||||
|
if (test && allNoteFavoritesCount > 1000) allNoteFavoritesCount = 1000;
|
||||||
for (let i = 0; i < allNoteFavoritesCount; i++) {
|
for (let i = 0; i < allNoteFavoritesCount; i++) {
|
||||||
const favorite = await _Favorite.findOne({}, {
|
const favorite = await _Favorite.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -423,7 +432,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allNoteReactionsCount = await _NoteReaction.count();
|
let allNoteReactionsCount = await _NoteReaction.count();
|
||||||
|
if (test && allNoteReactionsCount > 1000) allNoteReactionsCount = 1000;
|
||||||
for (let i = 0; i < allNoteReactionsCount; i++) {
|
for (let i = 0; i < allNoteReactionsCount; i++) {
|
||||||
const reaction = await _NoteReaction.findOne({}, {
|
const reaction = await _NoteReaction.findOne({}, {
|
||||||
skip: i
|
skip: i
|
||||||
|
@ -437,7 +447,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allActualUsersCount = await Users.count();
|
let allActualUsersCount = await Users.count();
|
||||||
|
if (test && allActualUsersCount > 1000) allActualUsersCount = 1000;
|
||||||
for (let i = 0; i < allActualUsersCount; i++) {
|
for (let i = 0; i < allActualUsersCount; i++) {
|
||||||
const [user] = await Users.find({
|
const [user] = await Users.find({
|
||||||
take: 1,
|
take: 1,
|
||||||
|
|
Loading…
Reference in a new issue