Improvements on notify expired service tokens

This commit is contained in:
carlosmonastyrski
2025-04-15 18:31:05 -03:00
parent ae8a78b883
commit 23a5a7a624
5 changed files with 53 additions and 32 deletions
@@ -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");
});
}
}
+1 -1
View File
@@ -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>;