Skip to content

Commit 4a35e53

Browse files
committed
[db] DBPrebuiltWorkspace: Add index ind_creationTime
1 parent 2ba3475 commit 4a35e53

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace {
5353
default: () => "CURRENT_TIMESTAMP(6)",
5454
transformer: Transformer.MAP_ISO_STRING_TO_TIMESTAMP_DROP,
5555
})
56+
@Index("ind_creationTime")
5657
creationTime: string;
5758

5859
@Column(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { indexExists } from "./helper/helper";
9+
10+
const TABLE_NAME = "d_b_prebuilt_workspace";
11+
const INDEX_NAME = "ind_creationTime";
12+
13+
export class PrebuildAddIndexCreationTime1695797972732 implements MigrationInterface {
14+
public async up(queryRunner: QueryRunner): Promise<void> {
15+
if (!(await indexExists(queryRunner, TABLE_NAME, INDEX_NAME))) {
16+
await queryRunner.query(
17+
`ALTER TABLE ${TABLE_NAME} ADD INDEX(${INDEX_NAME}), ALGORITHM=INPLACE, LOCK=NONE `,
18+
);
19+
}
20+
}
21+
22+
public async down(queryRunner: QueryRunner): Promise<void> {
23+
if (await indexExists(queryRunner, TABLE_NAME, INDEX_NAME)) {
24+
await queryRunner.query(`DROP INDEX ${INDEX_NAME} ON ${TABLE_NAME}`);
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)