Skip to content

Commit 66cbbe5

Browse files
committed
[db] DBUserSshPublicKey: drop deleted column (unused)
1 parent a3d51de commit 66cbbe5

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

components/gitpod-db/src/tables.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
8686
deletionColumn: "deleted",
8787
timeColumn: "_lastModified",
8888
},
89-
{
90-
name: "d_b_user_ssh_public_key",
91-
primaryKeys: ["id"],
92-
deletionColumn: "deleted",
93-
timeColumn: "_lastModified",
94-
},
9589
{
9690
name: "d_b_stripe_customer",
9791
primaryKeys: ["stripeCustomerId"],

components/gitpod-db/src/typeorm/entity/db-user-ssh-public-key.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,4 @@ export class DBUserSshPublicKey implements UserSSHPublicKey {
4949
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED,
5050
})
5151
lastUsedTime?: string;
52-
53-
// This column triggers the periodic deleter deletion mechanism. It's not intended for public consumption.
54-
@Column()
55-
deleted: boolean;
5652
}
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 { columnExists } from "./helper/helper";
9+
10+
const TABLE_NAME = "d_b_user_ssh_public_key";
11+
const COLUMN_NAME = "deleted";
12+
13+
export class UserSshPublicKeyDropDeleted1695822248160 implements MigrationInterface {
14+
public async up(queryRunner: QueryRunner): Promise<void> {
15+
if (await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME)) {
16+
await queryRunner.query(`ALTER TABLE \`${TABLE_NAME}\` DROP COLUMN \`${COLUMN_NAME}\`, ALGORITHM=INSTANT`);
17+
}
18+
}
19+
20+
public async down(queryRunner: QueryRunner): Promise<void> {
21+
if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) {
22+
await queryRunner.query(
23+
`ALTER TABLE \`${TABLE_NAME}\` ADD COLUMN \`${COLUMN_NAME}\` tinyint(4) NOT NULL DEFAULT '0', ALGORITHM=INSTANT`,
24+
);
25+
}
26+
}
27+
}

components/gitpod-db/src/typeorm/user-db-impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,18 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
425425

426426
public async hasSSHPublicKey(userId: string): Promise<boolean> {
427427
const repo = await this.getSSHPublicKeyRepo();
428-
return !!(await repo.findOne({ where: { userId, deleted: false } }));
428+
return !!(await repo.findOne({ where: { userId } }));
429429
}
430430

431431
public async getSSHPublicKeys(userId: string): Promise<UserSSHPublicKey[]> {
432432
const repo = await this.getSSHPublicKeyRepo();
433-
return repo.find({ where: { userId, deleted: false }, order: { creationTime: "ASC" } });
433+
return repo.find({ where: { userId }, order: { creationTime: "ASC" } });
434434
}
435435

436436
public async addSSHPublicKey(userId: string, value: SSHPublicKeyValue): Promise<UserSSHPublicKey> {
437437
const repo = await this.getSSHPublicKeyRepo();
438438
const fingerprint = SSHPublicKeyValue.getFingerprint(value);
439-
const allKeys = await repo.find({ where: { userId, deleted: false } });
439+
const allKeys = await repo.find({ where: { userId } });
440440
const prevOne = allKeys.find((e) => e.fingerprint === fingerprint);
441441
if (!!prevOne) {
442442
throw new Error(`Key already in use`);

0 commit comments

Comments
 (0)