Path: blob/main/components/gitpod-db/src/test/reset-db.ts
2500 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { DBUser } from "../typeorm/entity/db-user";7import { TypeORM } from "../typeorm/typeorm";8import { isBuiltinUser } from "../user-db";910export async function resetDB(typeorm: TypeORM) {11const conn = await typeorm.getConnection();12const users = await conn.getRepository(DBUser).find();13// delete all users except the builtin users14await conn.getRepository(DBUser).remove(users.filter((u) => !isBuiltinUser(u.id)));1516const deletions = conn.entityMetadatas17.filter((meta) => meta.tableName !== "d_b_user")18.map((meta) => {19return conn.getRepository(meta.name).clear();20});2122await Promise.all([23// delete all other entities24...deletions,2526// we don't have a typeorm entity for this table27conn.query("DELETE FROM d_b_oidc_client_config;"),28]);29}303132