Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/src/test/reset-db.ts
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { DBUser } from "../typeorm/entity/db-user";
8
import { TypeORM } from "../typeorm/typeorm";
9
import { isBuiltinUser } from "../user-db";
10
11
export async function resetDB(typeorm: TypeORM) {
12
const conn = await typeorm.getConnection();
13
const users = await conn.getRepository(DBUser).find();
14
// delete all users except the builtin users
15
await conn.getRepository(DBUser).remove(users.filter((u) => !isBuiltinUser(u.id)));
16
17
const deletions = conn.entityMetadatas
18
.filter((meta) => meta.tableName !== "d_b_user")
19
.map((meta) => {
20
return conn.getRepository(meta.name).clear();
21
});
22
23
await Promise.all([
24
// delete all other entities
25
...deletions,
26
27
// we don't have a typeorm entity for this table
28
conn.query("DELETE FROM d_b_oidc_client_config;"),
29
]);
30
}
31
32