Skip to content

Commit 95e4f5d

Browse files
authored
[db] Make Team DB transactional (#18012)
1 parent f44d1ba commit 95e4f5d

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

components/gitpod-db/src/team-db.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import {
1212
OrganizationSettings,
1313
} from "@gitpod/gitpod-protocol";
1414
import { DBTeamMembership } from "./typeorm/entity/db-team-membership";
15+
import { TransactionalDB } from "./typeorm/transactional-db-impl";
1516

1617
export const TeamDB = Symbol("TeamDB");
17-
export interface TeamDB {
18+
export interface TeamDB extends TransactionalDB<TeamDB> {
1819
findTeams(
1920
offset: number,
2021
limit: number,

components/gitpod-db/src/typeorm/team-db-impl.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import {
1212
OrganizationSettings,
1313
User,
1414
} from "@gitpod/gitpod-protocol";
15-
import { inject, injectable } from "inversify";
16-
import { TypeORM } from "./typeorm";
17-
import { Repository } from "typeorm";
15+
import { inject, injectable, optional } from "inversify";
16+
import { EntityManager, Repository } from "typeorm";
1817
import { v4 as uuidv4 } from "uuid";
1918
import { randomBytes } from "crypto";
2019
import { TeamDB } from "../team-db";
@@ -26,13 +25,16 @@ import { ResponseError } from "vscode-jsonrpc";
2625
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
2726
import slugify from "slugify";
2827
import { DBOrgSettings } from "./entity/db-team-settings";
28+
import { TransactionalDBImpl, UndefinedEntityManager } from "./transactional-db-impl";
2929

3030
@injectable()
31-
export class TeamDBImpl implements TeamDB {
32-
@inject(TypeORM) typeORM: TypeORM;
31+
export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB {
32+
constructor(@inject(UndefinedEntityManager) @optional() transactionalEM: EntityManager | undefined) {
33+
super(transactionalEM);
34+
}
3335

34-
protected async getEntityManager() {
35-
return (await this.typeORM.getConnection()).manager;
36+
protected createTransactionalDB(transactionalEM: EntityManager): TeamDB {
37+
return new TeamDBImpl(transactionalEM);
3638
}
3739

3840
protected async getTeamRepo(): Promise<Repository<DBTeam>> {

0 commit comments

Comments
 (0)