From 4e0460b947cadd46b26eaaf06f40e469c9be1360 Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Tue, 18 Apr 2023 11:38:50 +0200 Subject: [PATCH] [db] Remove theia plugin db model - WEB-168 (#17255) * [db] Remove theia plugin db model * retest --- components/gitpod-db/src/container-module.ts | 5 -- components/gitpod-db/src/index.ts | 1 - components/gitpod-db/src/tables.ts | 5 -- components/gitpod-db/src/theia-plugin-db.ts | 25 ------ .../src/typeorm/entity/db-theia-plugin.ts | 47 ----------- .../src/typeorm/theia-plugin-db-impl.ts | 80 ------------------- components/gitpod-protocol/src/protocol.ts | 21 ----- 7 files changed, 184 deletions(-) delete mode 100644 components/gitpod-db/src/theia-plugin-db.ts delete mode 100644 components/gitpod-db/src/typeorm/entity/db-theia-plugin.ts delete mode 100644 components/gitpod-db/src/typeorm/theia-plugin-db-impl.ts diff --git a/components/gitpod-db/src/container-module.ts b/components/gitpod-db/src/container-module.ts index f9814791dfcf8b..5168a7bf3e3bd5 100644 --- a/components/gitpod-db/src/container-module.ts +++ b/components/gitpod-db/src/container-module.ts @@ -22,8 +22,6 @@ import { DBWithTracing, bindDbWithTracing, TracedWorkspaceDB, TracedUserDB, Trac import { OneTimeSecretDB } from "./one-time-secret-db"; import { TypeORMAppInstallationDBImpl } from "./typeorm/app-installation-db-impl"; import { AppInstallationDB } from "./app-installation-db"; -import { TheiaPluginDBImpl } from "./typeorm/theia-plugin-db-impl"; -import { TheiaPluginDB } from "./theia-plugin-db"; import { TypeORMOneTimeSecretDBImpl } from "./typeorm/one-time-secret-db-impl"; import { PendingGithubEventDB, TransactionalPendingGithubEventDBFactory } from "./pending-github-event-db"; import { @@ -103,9 +101,6 @@ export const dbContainerModule = new ContainerModule((bind, unbind, isBound, reb bind(TypeORMAppInstallationDBImpl).toSelf().inSingletonScope(); bind(AppInstallationDB).toService(TypeORMAppInstallationDBImpl); - bind(TheiaPluginDBImpl).toSelf().inSingletonScope(); - bind(TheiaPluginDB).toService(TheiaPluginDBImpl); - bind(TypeORMOneTimeSecretDBImpl).toSelf().inSingletonScope(); bind(OneTimeSecretDB).toService(TypeORMOneTimeSecretDBImpl); bindDbWithTracing(TracedOneTimeSecretDB, bind, OneTimeSecretDB).inSingletonScope(); diff --git a/components/gitpod-db/src/index.ts b/components/gitpod-db/src/index.ts index a34c44ba83f73e..910323fb4db669 100644 --- a/components/gitpod-db/src/index.ts +++ b/components/gitpod-db/src/index.ts @@ -22,7 +22,6 @@ export * from "./traced-db"; export * from "./app-installation-db"; export * from "./user-message-views-db"; export * from "./user-storage-resources-db"; -export * from "./theia-plugin-db"; export * from "./one-time-secret-db"; export * from "./auth-provider-entry-db"; export * from "./license-db"; diff --git a/components/gitpod-db/src/tables.ts b/components/gitpod-db/src/tables.ts index 385505c0a7b74e..e07d1dbc2a1d86 100644 --- a/components/gitpod-db/src/tables.ts +++ b/components/gitpod-db/src/tables.ts @@ -186,11 +186,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider primaryKeys: ["domain"], timeColumn: "_lastModified", }, - { - name: "d_b_theia_plugin", - primaryKeys: ["id"], - timeColumn: "_lastModified", - }, { name: "d_b_user_env_var", primaryKeys: ["id", "userId"], diff --git a/components/gitpod-db/src/theia-plugin-db.ts b/components/gitpod-db/src/theia-plugin-db.ts deleted file mode 100644 index 459d068c497c11..00000000000000 --- a/components/gitpod-db/src/theia-plugin-db.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2020 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { TheiaPlugin } from "@gitpod/gitpod-protocol"; - -export const TheiaPluginDB = Symbol("TheiaPluginDB"); - -export interface TheiaPluginDB { - newPlugin( - userId: string, - pluginName: string, - bucketName: string, - pathFn: (id: string) => string, - ): Promise; - storePlugin(plugin: TheiaPlugin): Promise; - delete(plugin: TheiaPlugin): Promise; - - findById(id: string): Promise; - findByPluginId(pluginId: string): Promise; - - exists(pluginId: string, predicate: { state?: TheiaPlugin.State; hash?: string }): Promise; -} diff --git a/components/gitpod-db/src/typeorm/entity/db-theia-plugin.ts b/components/gitpod-db/src/typeorm/entity/db-theia-plugin.ts deleted file mode 100644 index 0371f64b37bdbf..00000000000000 --- a/components/gitpod-db/src/typeorm/entity/db-theia-plugin.ts +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2020 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { PrimaryColumn, Column, Entity } from "typeorm"; -import { TypeORM } from "../typeorm"; -import { TheiaPlugin } from "@gitpod/gitpod-protocol"; -import { Transformer } from "../transformer"; - -@Entity() -// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync -export class DBTheiaPlugin implements TheiaPlugin { - @PrimaryColumn(TypeORM.UUID_COLUMN_TYPE) - id: string; - - @Column() - pluginName: string; - - @Column({ - default: "", - transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED, - }) - pluginId?: string; - - @Column({ - default: "", - transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED, - }) - userId?: string; - - @Column() - bucketName: string; - - @Column() - path: string; - - @Column({ - default: "", - transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED, - }) - hash?: string; - - @Column() - state: TheiaPlugin.State; -} diff --git a/components/gitpod-db/src/typeorm/theia-plugin-db-impl.ts b/components/gitpod-db/src/typeorm/theia-plugin-db-impl.ts deleted file mode 100644 index c35fb492b947ff..00000000000000 --- a/components/gitpod-db/src/typeorm/theia-plugin-db-impl.ts +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2020 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { Repository, EntityManager } from "typeorm"; -import { injectable, inject } from "inversify"; -import { TypeORM } from "./typeorm"; -import { TheiaPluginDB } from "../theia-plugin-db"; -import { DBTheiaPlugin } from "./entity/db-theia-plugin"; -import { TheiaPlugin } from "@gitpod/gitpod-protocol"; -import { v4 as uuidv4 } from "uuid"; - -@injectable() -export class TheiaPluginDBImpl implements TheiaPluginDB { - @inject(TypeORM) typeORM: TypeORM; - - protected async getEntityManager(): Promise { - return (await this.typeORM.getConnection()).manager; - } - - protected async getTheiaPluginRepo(): Promise> { - return (await this.getEntityManager()).getRepository(DBTheiaPlugin); - } - - async newPlugin( - userId: string, - pluginName: string, - bucketName: string, - pathFn: (id: string) => string, - ): Promise { - const id = uuidv4(); - const newPlugin: TheiaPlugin = { - id, - pluginName, - userId, - bucketName, - path: pathFn(id), - state: TheiaPlugin.State.Uploading, - }; - return await this.storePlugin(newPlugin); - } - - async storePlugin(plugin: TheiaPlugin): Promise { - const repo = await this.getTheiaPluginRepo(); - return repo.save(plugin); - } - - async delete(plugin: TheiaPlugin): Promise { - const repo = await this.getTheiaPluginRepo(); - await repo.delete(plugin); - } - - async findById(id: string): Promise { - const repo = await this.getTheiaPluginRepo(); - return repo.findOne(id); - } - - async findByPluginId(pluginId: string): Promise { - const repo = await this.getTheiaPluginRepo(); - const query = repo.createQueryBuilder("theia_plugin").where(`theia_plugin.pluginId = :pluginId`, { pluginId }); - return query.getMany(); - } - - async exists(pluginId: string, predicate: { state?: TheiaPlugin.State; hash?: string }): Promise { - const repo = await this.getTheiaPluginRepo(); - const query = repo - .createQueryBuilder("theia_plugin") - .select("1") - .where(`theia_plugin.pluginId = :pluginId`, { pluginId }); - if (predicate.state) { - query.andWhere(`theia_plugin.state = :state`, { state: predicate.state }); - } - if (predicate.hash) { - query.andWhere(`theia_plugin.hash = :hash`, { hash: predicate.hash }); - } - return (await query.getCount()) > 0; - } -} diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 6c4eb221050b90..adb00cfa441068 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -1550,27 +1550,6 @@ export interface Configuration { readonly garbageCollectionStartDate: number; } -export interface TheiaPlugin { - id: string; - pluginName: string; - pluginId?: string; - /** - * Id of the user which uploaded this plugin. - */ - userId?: string; - bucketName: string; - path: string; - hash?: string; - state: TheiaPlugin.State; -} -export namespace TheiaPlugin { - export enum State { - Uploading = "uploading", - Uploaded = "uploaded", - CheckinFailed = "checkin-failed", - } -} - export interface TermsAcceptanceEntry { readonly userId: string; readonly termsRevision: string;