diff --git a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts index 780147a36ffd27..22f3c5c6bfc795 100644 --- a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts +++ b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts @@ -68,4 +68,11 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace { transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED, }) error?: string; + + // statusVersion defines the last observed stateVersion from a WorkspaceStatus. See ws-manager-api/core.proto. + // statusVersion must only be set by controller/observer. + @Column({ + default: 0, + }) + statusVersion: number; } diff --git a/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts b/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts new file mode 100644 index 00000000000000..dbfe445d2d8cb1 --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1649107789640-PrebuildStatusVersionColumn.ts @@ -0,0 +1,23 @@ +/** + * 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_prebuilt_workspace"; +const COLUMN_NAME = "statusVersion"; + +export class PrebuildStatusVersionColumn1649107789640 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}\` BIGINT(20) NOT NULL DEFAULT '0'`, + ); + } + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/components/gitpod-db/src/workspace-db.spec.db.ts b/components/gitpod-db/src/workspace-db.spec.db.ts index 68d571aa00479a..5cb2dec8d02e05 100644 --- a/components/gitpod-db/src/workspace-db.spec.db.ts +++ b/components/gitpod-db/src/workspace-db.spec.db.ts @@ -247,6 +247,7 @@ class WorkspaceDBSpec { cloneURL: "", commit: "", state: "available", + statusVersion: 0, }); if (usageDaysAgo !== undefined) { const now = new Date(); @@ -509,6 +510,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "queued", + statusVersion: 0, }), // now and aborted this.storePrebuiltWorkspace({ @@ -518,6 +520,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "aborted", + statusVersion: 0, }), // completed over a minute ago this.storePrebuiltWorkspace({ @@ -527,6 +530,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "available", + statusVersion: 0, }), ]); diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 7d81090cd934b1..161a3ad0f1077b 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -634,6 +634,7 @@ export interface PrebuiltWorkspace { buildWorkspaceId: string; creationTime: string; state: PrebuiltWorkspaceState; + statusVersion: number; error?: string; snapshot?: string; } diff --git a/components/server/ee/src/workspace/workspace-factory.ts b/components/server/ee/src/workspace/workspace-factory.ts index 602a3cc500397f..f37c1d921d2bad 100644 --- a/components/server/ee/src/workspace/workspace-factory.ts +++ b/components/server/ee/src/workspace/workspace-factory.ts @@ -172,6 +172,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { creationTime: new Date().toISOString(), projectId: ws.projectId, branch, + statusVersion: 0, }); log.debug(