diff --git a/components/gitpod-db/src/typeorm/entity/db-workspace-instance.ts b/components/gitpod-db/src/typeorm/entity/db-workspace-instance.ts index f5c6c0fdb95d36..3afa156176040d 100644 --- a/components/gitpod-db/src/typeorm/entity/db-workspace-instance.ts +++ b/components/gitpod-db/src/typeorm/entity/db-workspace-instance.ts @@ -96,4 +96,10 @@ export class DBWorkspaceInstance implements WorkspaceInstance { @Column("simple-json", { nullable: true }) imageBuildInfo?: ImageBuildInfo; + + @Column({ + default: "", + transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED, + }) + workspaceClass?: string; } diff --git a/components/gitpod-db/src/typeorm/migration/1654264374619-WorkspaceClass.ts b/components/gitpod-db/src/typeorm/migration/1654264374619-WorkspaceClass.ts new file mode 100644 index 00000000000000..cfc2462cd4b707 --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1654264374619-WorkspaceClass.ts @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2022 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 { MigrationInterface, QueryRunner } from "typeorm"; +import { columnExists } from "./helper/helper"; + +const TABLE_NAME = "d_b_workspace_instance"; +const COLUMN_NAME = "workspaceClass"; + +export class WorkspaceClass1654264374619 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) { + await queryRunner.query( + `ALTER TABLE ${TABLE_NAME} ADD COLUMN ${COLUMN_NAME} varchar(255) NOT NULL DEFAULT '', ALGORITHM=INPLACE, LOCK=NONE`, + ); + } + } + + public async down(queryRunner: QueryRunner): Promise { + if (await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME)) { + await queryRunner.query(`ALTER TABLE ${TABLE_NAME} DROP COLUMN ${COLUMN_NAME}`); + } + } +} diff --git a/components/gitpod-db/src/workspace-db.spec.db.ts b/components/gitpod-db/src/workspace-db.spec.db.ts index cf49bd6fc375e3..6bc546942b1971 100644 --- a/components/gitpod-db/src/workspace-db.spec.db.ts +++ b/components/gitpod-db/src/workspace-db.spec.db.ts @@ -49,6 +49,7 @@ class WorkspaceDBSpec { id: "123", ideUrl: "example.org", region: "unknown", + workspaceClass: undefined, workspaceImage: "abc.io/test/image:123", creationTime: this.timeBefore, startedTime: undefined, @@ -70,6 +71,7 @@ class WorkspaceDBSpec { id: "1234", ideUrl: "example.org", region: "unknown", + workspaceClass: undefined, workspaceImage: "abc.io/test/image:123", creationTime: this.timeAfter, startedTime: undefined, @@ -106,6 +108,7 @@ class WorkspaceDBSpec { id: "4", ideUrl: "example.org", region: "unknown", + workspaceClass: undefined, workspaceImage: "abc.io/test/image:123", creationTime: this.timeBefore, startedTime: undefined, @@ -142,6 +145,7 @@ class WorkspaceDBSpec { id: "3_1", ideUrl: "example.org", region: "unknown", + workspaceClass: undefined, workspaceImage: "abc.io/test/image:123", creationTime: this.timeBefore, startedTime: undefined, diff --git a/components/gitpod-protocol/src/workspace-instance.ts b/components/gitpod-protocol/src/workspace-instance.ts index 7992f656986f9a..ea5e28f6ef1c4b 100644 --- a/components/gitpod-protocol/src/workspace-instance.ts +++ b/components/gitpod-protocol/src/workspace-instance.ts @@ -56,6 +56,12 @@ export interface WorkspaceInstance { * Contains information about the image build, if there was any */ imageBuildInfo?: ImageBuildInfo; + + /** + * workspace class, also known as workspace size, determines the type of + * resources that are provided to the workspace. + */ + workspaceClass?: string; } // WorkspaceInstanceStatus describes the current state of a workspace instance diff --git a/components/server/src/workspace/workspace-starter.ts b/components/server/src/workspace/workspace-starter.ts index 27f028604f4166..91f7872ff201e5 100644 --- a/components/server/src/workspace/workspace-starter.ts +++ b/components/server/src/workspace/workspace-starter.ts @@ -501,6 +501,7 @@ export class WorkspaceStarter { instance.status.phase = "pending"; instance.region = installation; + instance.workspaceClass = startRequest.getSpec()!.getClass(); await this.workspaceDb.trace(ctx).storeInstance(instance); try { await this.messageBus.notifyOnInstanceUpdate(workspace.ownerId, instance);