diff --git a/components/gitpod-db/src/tables.ts b/components/gitpod-db/src/tables.ts index 6590a06eb8ed0d..62e1e48c036092 100644 --- a/components/gitpod-db/src/tables.ts +++ b/components/gitpod-db/src/tables.ts @@ -38,16 +38,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider timeColumn: "_lastModified", deletionColumn: "deleted", }, - { - name: "d_b_oauth_auth_code_entry", - primaryKeys: ["id"], - timeColumn: "_lastModified", - }, - { - name: "d_b_installation_admin", - primaryKeys: ["id"], - timeColumn: "_lastModified", - }, { name: "d_b_volume_snapshot", primaryKeys: ["id"], @@ -72,52 +62,12 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider primaryKeys: ["id"], timeColumn: "_lastModified", }, - { - name: "d_b_user_storage_resource", - primaryKeys: ["userId", "uri"], - timeColumn: "_lastModified", - deletionColumn: "deleted", - dependencies: ["d_b_user"], - }, - { - name: "d_b_workspace_instance_user", - primaryKeys: ["instanceId", "userId"], - timeColumn: "_lastModified", - dependencies: ["d_b_user"], - }, - { - name: "d_b_workspace_report_entry", - primaryKeys: ["uid"], - timeColumn: "time", - dependencies: [], - }, - { - name: "d_b_snapshot", - primaryKeys: ["id"], - timeColumn: "creationTime", - dependencies: [], - }, - { - name: "d_b_email_domain_filter", - primaryKeys: ["domain"], - timeColumn: "_lastModified", - }, - { - name: "d_b_app_installation", - primaryKeys: ["platform", "installationID", "state"], - timeColumn: "creationTime", - }, { name: "d_b_token_entry", primaryKeys: ["uid"], deletionColumn: "deleted", timeColumn: "_lastModified", }, - { - name: "d_b_user_env_var", - primaryKeys: ["id", "userId"], - timeColumn: "_lastModified", - }, { name: "d_b_gitpod_token", primaryKeys: ["tokenHash"], @@ -137,17 +87,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider deletionColumn: "deleted", timeColumn: "_lastModified", }, - { - name: "d_b_code_sync_collection", - primaryKeys: ["userId", "collection"], - timeColumn: "_lastModified", - }, - { - name: "d_b_code_sync_resource", - primaryKeys: ["userId", "kind", "rev", "collection"], - timeColumn: "created", - dependencies: ["d_b_code_sync_collection"], - }, { name: "d_b_team", primaryKeys: ["id"], @@ -196,16 +135,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider deletionColumn: "deleted", timeColumn: "_lastModified", }, - { - name: "d_b_cost_center", - primaryKeys: ["id", "creationTime"], - timeColumn: "_lastModified", - }, - { - name: "d_b_usage", - primaryKeys: ["id"], - timeColumn: "_lastModified", - }, { name: "d_b_stripe_customer", primaryKeys: ["stripeCustomerId"], @@ -218,11 +147,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider timeColumn: "_lastModified", deletionColumn: "deleted", }, - { - name: "d_b_linked_in_profile", - primaryKeys: ["id"], - timeColumn: "_lastModified", - }, ]; public getSortedTables(): TableDescription[] { diff --git a/components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts b/components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts index 831ca0f8bbb7bb..f63e5dc932bd47 100644 --- a/components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts +++ b/components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts @@ -48,7 +48,7 @@ export class AuthProviderEntryDBImpl implements AuthProviderEntryDB { // 2. then mark as deleted const repo = await this.getAuthProviderRepo(); - await repo.update({ id }, { deleted: true }); + await repo.delete({ id }); } async findAll(exceptOAuthRevisions: string[] = []): Promise { diff --git a/components/gitpod-db/src/typeorm/project-db-impl.ts b/components/gitpod-db/src/typeorm/project-db-impl.ts index ce1b10571223a8..8aa1210e90458a 100644 --- a/components/gitpod-db/src/typeorm/project-db-impl.ts +++ b/components/gitpod-db/src/typeorm/project-db-impl.ts @@ -118,10 +118,7 @@ export class ProjectDBImpl extends TransactionalDBImpl implements Pro await projectInfoRepo.update(projectId, { deleted: true }); } const projectUsageRepo = await this.getProjectUsageRepo(); - const usage = await projectUsageRepo.findOne({ projectId, deleted: false }); - if (usage) { - await projectUsageRepo.update(projectId, { deleted: true }); - } + await projectUsageRepo.delete({ projectId }); } public async findProjectEnvironmentVariable( diff --git a/components/gitpod-db/src/typeorm/team-db-impl.ts b/components/gitpod-db/src/typeorm/team-db-impl.ts index 08f47086423b45..32a6c71e3402a9 100644 --- a/components/gitpod-db/src/typeorm/team-db-impl.ts +++ b/components/gitpod-db/src/typeorm/team-db-impl.ts @@ -328,8 +328,7 @@ export class TeamDBImpl extends TransactionalDBImpl implements TeamDB { "The given user is not currently a member of this organization or does not exist.", ); } - membership.deleted = true; - await membershipRepo.save(membership); + await membershipRepo.delete(membership); } public async findTeamMembershipInviteById(inviteId: string): Promise { diff --git a/components/gitpod-db/src/typeorm/user-db-impl.ts b/components/gitpod-db/src/typeorm/user-db-impl.ts index 1b6968358849f8..90cb08fc500de0 100644 --- a/components/gitpod-db/src/typeorm/user-db-impl.ts +++ b/components/gitpod-db/src/typeorm/user-db-impl.ts @@ -29,7 +29,7 @@ import { OAuthUser, } from "@jmondi/oauth2-server"; import { inject, injectable, optional } from "inversify"; -import { EntityManager, Equal, Not, Repository } from "typeorm"; +import { EntityManager, Equal, FindOperator, Not, Repository } from "typeorm"; import { v4 as uuidv4 } from "uuid"; import { BUILTIN_WORKSPACE_PROBE_USER_ID, @@ -256,27 +256,12 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl implements Us public async deleteGitpodToken(tokenHash: string): Promise { const repo = await this.getGitpodTokenRepo(); - await repo.query( - ` - UPDATE d_b_gitpod_token AS gt - SET gt.deleted = TRUE - WHERE tokenHash = ?; - `, - [tokenHash], - ); + await repo.delete({ tokenHash }); } public async deleteGitpodTokensNamedLike(userId: string, namePattern: string): Promise { const repo = await this.getGitpodTokenRepo(); - await repo.query( - ` - UPDATE d_b_gitpod_token AS gt - SET gt.deleted = TRUE - WHERE userId = ? - AND name LIKE ? - `, - [userId, namePattern], - ); + await repo.delete({ userId, name: new FindOperator("like", namePattern) }); } public async storeSingleToken(identity: Identity, token: Token): Promise { @@ -309,16 +294,14 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl implements Us public async deleteExpiredTokenEntries(date: string): Promise { const repo = await this.getTokenRepo(); - await repo.query( - ` - UPDATE d_b_token_entry AS te - SET te.deleted = TRUE - WHERE te.expiryDate != '' - AND te.refreshable != 1 - AND te.expiryDate <= ?; - `, - [date], - ); + await repo + .createQueryBuilder() + .delete() + .from(DBTokenEntry) + .where("expiryDate != ''") + .andWhere("refreshable != 1") + .andWhere("expiryDate <= :date", { date }) + .execute(); } public async updateTokenEntry(tokenEntry: Partial & Pick): Promise { @@ -331,8 +314,7 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl implements Us const repo = await this.getTokenRepo(); for (const existing of existingTokens) { if (!shouldDelete || shouldDelete(existing)) { - existing.deleted = true; - await repo.save(existing); + await repo.delete(existing.uid); } } } @@ -481,7 +463,7 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl implements Us public async deleteSSHPublicKey(userId: string, id: string): Promise { const repo = await this.getSSHPublicKeyRepo(); - await repo.update({ userId, id }, { deleted: true }); + await repo.delete({ userId, id }); } public async findAllUsers(