|
| 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 { DBGitpodToken } from "../typeorm/entity/db-gitpod-token"; |
| 8 | +import { DBIdentity } from "../typeorm/entity/db-identity"; |
| 9 | +import { DBOAuthAuthCodeEntry } from "../typeorm/entity/db-oauth-auth-code"; |
| 10 | +import { DBOneTimeSecret } from "../typeorm/entity/db-one-time-secret"; |
| 11 | +import { DBProject } from "../typeorm/entity/db-project"; |
| 12 | +import { DBTeam } from "../typeorm/entity/db-team"; |
| 13 | +import { DBTeamMembership } from "../typeorm/entity/db-team-membership"; |
| 14 | +import { DBUser } from "../typeorm/entity/db-user"; |
| 15 | +import { DBWorkspace } from "../typeorm/entity/db-workspace"; |
| 16 | +import { DBWorkspaceInstance } from "../typeorm/entity/db-workspace-instance"; |
| 17 | +import { TypeORM } from "../typeorm/typeorm"; |
| 18 | +import { isBuiltinUser } from "../user-db"; |
| 19 | + |
| 20 | +export async function resetDB(typeorm: TypeORM) { |
| 21 | + const conn = await typeorm.getConnection(); |
| 22 | + // delete all users except the builtin users |
| 23 | + const users = await conn.getRepository(DBUser).find(); |
| 24 | + await conn.getRepository(DBUser).remove(users.filter((u) => !isBuiltinUser(u.id))); |
| 25 | + |
| 26 | + await conn.getRepository(DBTeam).clear(); |
| 27 | + await conn.getRepository(DBTeamMembership).clear(); |
| 28 | + await conn.getRepository(DBProject).clear(); |
| 29 | + await conn.getRepository(DBIdentity).clear(); |
| 30 | + await conn.getRepository(DBWorkspace).clear(); |
| 31 | + await conn.getRepository(DBWorkspaceInstance).clear(); |
| 32 | + await conn.getRepository(DBGitpodToken).clear(); |
| 33 | + await conn.getRepository(DBOAuthAuthCodeEntry).clear(); |
| 34 | + await conn.getRepository(DBOneTimeSecret).clear(); |
| 35 | + // we don't have a typeorm entity for this table |
| 36 | + await conn.query("DELETE FROM d_b_oidc_client_config;"); |
| 37 | +} |
0 commit comments