From e0f7bfe976924005a4591ed9d3eb9e919111336a Mon Sep 17 00:00:00 2001 From: "Laurie T. Malau" Date: Tue, 8 Feb 2022 13:51:35 +0000 Subject: [PATCH] Create an index for contextURL column --- .../src/typeorm/entity/db-workspace.ts | 1 + .../1644327547997-IndexWorkspaceContextUrl.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 components/gitpod-db/src/typeorm/migration/1644327547997-IndexWorkspaceContextUrl.ts diff --git a/components/gitpod-db/src/typeorm/entity/db-workspace.ts b/components/gitpod-db/src/typeorm/entity/db-workspace.ts index faa032085683c1..fe1ea8d6fb03ef 100644 --- a/components/gitpod-db/src/typeorm/entity/db-workspace.ts +++ b/components/gitpod-db/src/typeorm/entity/db-workspace.ts @@ -27,6 +27,7 @@ export class DBWorkspace implements Workspace { ownerId: string; @Column("text") + @Index('ind_contextURL') contextURL: string; @Column({ diff --git a/components/gitpod-db/src/typeorm/migration/1644327547997-IndexWorkspaceContextUrl.ts b/components/gitpod-db/src/typeorm/migration/1644327547997-IndexWorkspaceContextUrl.ts new file mode 100644 index 00000000000000..a5136705e3fadb --- /dev/null +++ b/components/gitpod-db/src/typeorm/migration/1644327547997-IndexWorkspaceContextUrl.ts @@ -0,0 +1,25 @@ +/** + * 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 { indexExists } from "./helper/helper"; + +export class IndexWorkspaceContextUrl1644327547997 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + const TABLE_NAME = "d_b_workspace"; + const INDEX_NAME = "ind_contextURL"; + + if(!(await indexExists(queryRunner, TABLE_NAME, INDEX_NAME))) { + await queryRunner.query("ALTER TABLE d_b_workspace MODIFY COLUMN `contextURL` varchar(255) NOT NULL"); + await queryRunner.query(`CREATE INDEX ${INDEX_NAME} ON ${TABLE_NAME} (contextURL)`); + } + } + + public async down(queryRunner: QueryRunner): Promise { + } + +}