From 4def67993b08b030408440ff6478af196290c816 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Thu, 1 Sep 2022 10:41:32 +0000 Subject: [PATCH] [db] fix d_b_workspace_instance_usage.startedAt and add ind_dbsync --- ...2027342962-WorkspaceInstanceUsageUpdate.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 components/gitpod-db/src/typeorm/migration/1662027342962-WorkspaceInstanceUsageUpdate.ts diff --git a/components/gitpod-db/src/typeorm/migration/1662027342962-WorkspaceInstanceUsageUpdate.ts b/components/gitpod-db/src/typeorm/migration/1662027342962-WorkspaceInstanceUsageUpdate.ts new file mode 100644 index 00000000000000..a8a5118c0d42c0 --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1662027342962-WorkspaceInstanceUsageUpdate.ts @@ -0,0 +1,26 @@ +/** + * 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_usage"; +const COLUMN_NAME = "startedAt"; + +export class WorkspaceInstanceUsageUpdate1662027342962 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + if (await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME)) { + await queryRunner.query( + `ALTER TABLE ${TABLE_NAME} MODIFY COLUMN ${COLUMN_NAME} timestamp(6) NULL, ALGORITHM=INPLACE, LOCK=NONE`, + ); + } + await queryRunner.query("CREATE INDEX `ind_dbsync` ON `d_b_workspace_instance_usage` (_lastModified)"); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query("ALTER TABLE `d_b_workspace_instance_usage` DROP INDEX `ind_dbsync`"); + } +}