Skip to content

Commit c5c5be9

Browse files
easyCZroboquat
authored andcommitted
[db] Add deleted and _lastModified columns, index _lastModified for d_b_prebuilt_workspace_updatable
1 parent 8953c4b commit c5c5be9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2022 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 { columnExists, indexExists } from "./helper/helper";
9+
10+
const TABLE_NAME = "d_b_prebuilt_workspace_updatable";
11+
const DELETED_COLUMN_NAME = "deleted";
12+
const MODIFIED_COLUMN_NAME = "_lastModified";
13+
const LAST_MODIFIED_INDEX_NAME = "ind_lastModified";
14+
15+
export class PrebuiltWorkspaceUpdatableDBSync1663752957582 implements MigrationInterface {
16+
public async up(queryRunner: QueryRunner): Promise<void> {
17+
if (!(await columnExists(queryRunner, TABLE_NAME, DELETED_COLUMN_NAME))) {
18+
await queryRunner.query(
19+
`ALTER TABLE ${TABLE_NAME} ADD COLUMN \`${DELETED_COLUMN_NAME}\` tinyint(4) NOT NULL DEFAULT '0', ALGORITHM=INPLACE, LOCK=NONE`,
20+
);
21+
}
22+
23+
if (!(await columnExists(queryRunner, TABLE_NAME, MODIFIED_COLUMN_NAME))) {
24+
await queryRunner.query(
25+
`ALTER TABLE ${TABLE_NAME} ADD COLUMN ${MODIFIED_COLUMN_NAME} timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), ALGORITHM=INPLACE, LOCK=NONE `,
26+
);
27+
}
28+
29+
if (!(await indexExists(queryRunner, TABLE_NAME, LAST_MODIFIED_INDEX_NAME))) {
30+
await queryRunner.query(
31+
`CREATE INDEX \`${LAST_MODIFIED_INDEX_NAME}\` ON \`${TABLE_NAME}\` (${MODIFIED_COLUMN_NAME})`,
32+
);
33+
}
34+
}
35+
36+
public async down(queryRunner: QueryRunner): Promise<void> {}
37+
}

0 commit comments

Comments
 (0)