Skip to content

[db] add migration to alter pat table allow null expirationTime #19328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DBPersonalAccessToken {
scopes: string[];

@Column("datetime")
expirationTime: Date;
expirationTime: Date | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR we've really never used null as value. Wouldn't setting a date in distant future be less likely to cause problems?

Copy link
Contributor Author

@mustard-mh mustard-mh Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svenefftinge So just add option to allow 5 years? And not show Never expires! but actual expiration date on dashboard?

SCR-20240117-dmpv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or hard code something like 2099-01-01 00:00:00 as never expires


@Column("datetime")
createdAt: Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2024 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";

const table = "d_b_personal_access_token";

export class PersonalAccessTokenAllowNullExpireDateonPAT1705393804800 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE ${table} MODIFY expirationTime timestamp(6) NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE ${table} CHANGE expirationTime timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class PersonalAccessTokenDBImpl implements PersonalAccessTokenDB {
const pat = await repo
.createQueryBuilder("pat")
.where(`pat.hash = :hash`, { hash })
.andWhere(`pat.expirationTime > :expirationTime`, { expirationTime })
.andWhere(`pat.expirationTime > :expirationTime OR pat.expirationTime IS NULL`, { expirationTime })
.andWhere(`pat.deleted = false`)
.getOne();

Expand Down