refactor: migrate to typeorm 3.0 (#8443)

* wip

* wip

* wip

* Update following.ts

* wip

* wip

* wip

* Update resolve-user.ts

* maxQueryExecutionTime

* wip

* wip
This commit is contained in:
syuilo 2022-03-26 15:34:00 +09:00 committed by GitHub
parent 41c87074e6
commit 1c67c26bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
325 changed files with 1314 additions and 1494 deletions

View file

@ -4,10 +4,11 @@ import generateNativeUserToken from '../server/api/common/generate-native-user-t
import { genRsaKeyPair } from '@/misc/gen-key-pair.js';
import { User } from '@/models/entities/user.js';
import { UserProfile } from '@/models/entities/user-profile.js';
import { getConnection, ObjectLiteral } from 'typeorm';
import { IsNull } from 'typeorm';
import { genId } from '@/misc/gen-id.js';
import { UserKeypair } from '@/models/entities/user-keypair.js';
import { UsedUsername } from '@/models/entities/used-username.js';
import { db } from '@/db/postgre.js';
export async function createSystemUser(username: string) {
const password = uuid();
@ -21,13 +22,13 @@ export async function createSystemUser(username: string) {
const keyPair = await genRsaKeyPair(4096);
let account!: User | ObjectLiteral;
let account!: User;
// Start transaction
await getConnection().transaction(async transactionalEntityManager => {
const exist = await transactionalEntityManager.findOne(User, {
await db.transaction(async transactionalEntityManager => {
const exist = await transactionalEntityManager.findOneBy(User, {
usernameLower: username.toLowerCase(),
host: null,
host: IsNull(),
});
if (exist) throw new Error('the user is already exists');
@ -43,7 +44,7 @@ export async function createSystemUser(username: string) {
isLocked: true,
isExplorable: false,
isBot: true,
}).then(x => transactionalEntityManager.findOneOrFail(User, x.identifiers[0]));
}).then(x => transactionalEntityManager.findOneByOrFail(User, x.identifiers[0]));
await transactionalEntityManager.insert(UserKeypair, {
publicKey: keyPair.publicKey,