Update migrate.ts
This commit is contained in:
		
							parent
							
								
									795be20ee1
								
							
						
					
					
						commit
						fa6eae2937
					
				
					 1 changed files with 36 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,7 @@ 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';
 | 
			
		||||
import { DriveFile } from './models/entities/drive-file';
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
| 
						 | 
				
			
			@ -13,13 +14,14 @@ const uri = `mongodb://${u && p ? `${u}:${p}@` : ''}${(config as any).mongodb.ho
 | 
			
		|||
const db = mongo(uri);
 | 
			
		||||
 | 
			
		||||
const _User = db.get<any>('users');
 | 
			
		||||
const _DriveFile = db.get<any>('driveFiles.files');
 | 
			
		||||
 | 
			
		||||
async function main() {
 | 
			
		||||
	await initDb();
 | 
			
		||||
	const Users = getRepository(User);
 | 
			
		||||
	const DriveFiles = getRepository(DriveFile);
 | 
			
		||||
 | 
			
		||||
	const allUsersCount = await _User.count();
 | 
			
		||||
 | 
			
		||||
	for (let i = 0; i < allUsersCount; i++) {
 | 
			
		||||
		const user = await _User.findOne({}, {
 | 
			
		||||
			skip: i
 | 
			
		||||
| 
						 | 
				
			
			@ -34,9 +36,40 @@ async function main() {
 | 
			
		|||
			password: user.password,
 | 
			
		||||
			isAdmin: user.isAdmin,
 | 
			
		||||
			autoAcceptFollowed: true,
 | 
			
		||||
			autoWatch: false
 | 
			
		||||
			autoWatch: false,
 | 
			
		||||
			name: user.name,
 | 
			
		||||
			location: user.profile.location,
 | 
			
		||||
			birthday: user.profile.birthday,
 | 
			
		||||
			followersCount: user.followersCount,
 | 
			
		||||
			followingCount: user.followingCount,
 | 
			
		||||
			notesCount: user.notesCount,
 | 
			
		||||
			description: user.description,
 | 
			
		||||
			isBot: user.isBot,
 | 
			
		||||
			isCat: user.isCat,
 | 
			
		||||
			isVerified: user.isVerified,
 | 
			
		||||
			inbox: user.inbox,
 | 
			
		||||
			sharedInbox: user.sharedInbox,
 | 
			
		||||
			uri: user.uri,
 | 
			
		||||
		});
 | 
			
		||||
		console.log(`USER (${i + 1}/${allUsersCount}) ${user.id} DONE`);
 | 
			
		||||
		console.log(`USER (${i + 1}/${allUsersCount}) ${user._id} DONE`);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const allDriveFilesCount = await _DriveFile.count();
 | 
			
		||||
	for (let i = 0; i < allDriveFilesCount; i++) {
 | 
			
		||||
		const file = await _DriveFile.findOne({}, {
 | 
			
		||||
			skip: i
 | 
			
		||||
		});
 | 
			
		||||
		await DriveFiles.save({
 | 
			
		||||
			id: file._id.toHexString(),
 | 
			
		||||
			userId: file.userId.toHexString(),
 | 
			
		||||
			createdAt: file.uploadDate || new Date(),
 | 
			
		||||
			md5: file.md5,
 | 
			
		||||
			name: file.filename,
 | 
			
		||||
			type: file.contentType,
 | 
			
		||||
			properties: file.metadata.properties,
 | 
			
		||||
			size: file.length,
 | 
			
		||||
		});
 | 
			
		||||
		console.log(`USER (${i + 1}/${allDriveFilesCount}) ${file._id} DONE`);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue