Skip to content

Commit

Permalink
[db] DBUserSshPublicKey: drop deleted column (unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
geropl committed Oct 4, 2023
1 parent 0547c25 commit 02b91a7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
6 changes: 0 additions & 6 deletions components/gitpod-db/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
deletionColumn: "deleted",
timeColumn: "_lastModified",
},
{
name: "d_b_user_ssh_public_key",
primaryKeys: ["id"],
deletionColumn: "deleted",
timeColumn: "_lastModified",
},
{
name: "d_b_stripe_customer",
primaryKeys: ["stripeCustomerId"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,4 @@ export class DBUserSshPublicKey implements UserSSHPublicKey {
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED,
})
lastUsedTime?: string;

// This column triggers the periodic deleter deletion mechanism. It's not intended for public consumption.
@Column()
deleted: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2023 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_user_ssh_public_key";
const COLUMN_NAME = "deleted";

export class UserSshPublicKeyDropDeleted1695822248160 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME)) {
await queryRunner.query(`ALTER TABLE \`${TABLE_NAME}\` DROP COLUMN \`${COLUMN_NAME}\`, ALGORITHM=INSTANT`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) {
await queryRunner.query(
`ALTER TABLE \`${TABLE_NAME}\` ADD COLUMN \`${COLUMN_NAME}\` tinyint(4) NOT NULL DEFAULT '0', ALGORITHM=INSTANT`,
);
}
}
}
6 changes: 3 additions & 3 deletions components/gitpod-db/src/typeorm/user-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,18 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us

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

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

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

0 comments on commit 02b91a7

Please sign in to comment.