refactor(database): run knex migrations on startup

Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2025-05-17 23:27:47 +02:00
parent d67e44f540
commit 21a1f35281
No known key found for this signature in database
GPG key ID: DB99ADDDC5C0AF82
85 changed files with 830 additions and 418 deletions

View file

@ -5,17 +5,21 @@
*/
import {
AuthProviderType,
LoginUserInfoDto,
REGEX_USERNAME,
UserInfoDto,
} from '@hedgedoc/commons';
import { LoginUserInfoDto } from '@hedgedoc/commons';
import {
FieldNameUser,
TableUser,
TypeUpdateUser,
User,
} from '@hedgedoc/database';
import { BadRequestException, Injectable } from '@nestjs/common';
import { Knex } from 'knex';
import { InjectConnection } from 'nest-knexjs';
import { v4 as uuidv4 } from 'uuid';
import { FieldNameUser, TableUser, User } from '../database/types';
import { TypeUpdateUser } from '../database/types/user';
import { GenericDBError, NotInDBError } from '../errors/errors';
import { ConsoleLoggerService } from '../logger/console-logger.service';
import { generateRandomName } from '../realtime/realtime-note/random-word-lists/name-randomizer';
@ -209,11 +213,12 @@ export class UsersService {
transaction?: Knex,
): Promise<boolean> {
const dbActor = transaction ? transaction : this.knex;
const username = await dbActor(TableUser)
const usernameResponse = await dbActor(TableUser)
.select(FieldNameUser.username)
.where(FieldNameUser.id, userId)
.first();
return username !== null && username !== undefined;
const username = usernameResponse?.[FieldNameUser.username] ?? null;
return username !== null;
}
/**