mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 23:52:09 +00:00
Improvements on notify expired service tokens
This commit is contained in:
@@ -3,25 +3,25 @@ import { Knex } from "knex";
|
||||
import { TableName } from "../schemas";
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
const hasCol = await knex.schema.hasColumn(TableName.ServiceToken, "notificationSent");
|
||||
const hasCol = await knex.schema.hasColumn(TableName.ServiceToken, "expiryNotificationSent");
|
||||
if (!hasCol) {
|
||||
await knex.schema.alterTable(TableName.ServiceToken, (t) => {
|
||||
t.boolean("notificationSent").defaultTo(false);
|
||||
t.boolean("expiryNotificationSent").defaultTo(false);
|
||||
});
|
||||
|
||||
// Update only tokens where expiresAt is before current time
|
||||
await knex(TableName.ServiceToken)
|
||||
.whereRaw(`${TableName.ServiceToken}."expiresAt" < NOW()`)
|
||||
.whereNotNull("expiresAt")
|
||||
.update({ notificationSent: true });
|
||||
.update({ expiryNotificationSent: true });
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
const hasCol = await knex.schema.hasColumn(TableName.ServiceToken, "notificationSent");
|
||||
const hasCol = await knex.schema.hasColumn(TableName.ServiceToken, "expiryNotificationSent");
|
||||
if (hasCol) {
|
||||
await knex.schema.alterTable(TableName.ServiceToken, (t) => {
|
||||
t.dropColumn("notificationSent");
|
||||
t.dropColumn("expiryNotificationSent");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export const ServiceTokensSchema = z.object({
|
||||
updatedAt: z.date(),
|
||||
createdBy: z.string(),
|
||||
projectId: z.string(),
|
||||
notificationSent: z.boolean().default(false).nullable().optional()
|
||||
expiryNotificationSent: z.boolean().default(false).nullable().optional()
|
||||
});
|
||||
|
||||
export type TServiceTokens = z.infer<typeof ServiceTokensSchema>;
|
||||
|
||||
Reference in New Issue
Block a user