mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 16:27:40 +00:00
Add cycle logic to next reminder migration
This commit is contained in:
@@ -47,9 +47,22 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
if (secretsWithLatestVersions.length > 0) {
|
if (secretsWithLatestVersions.length > 0) {
|
||||||
secretsWithLatestVersions.forEach((secret) => {
|
secretsWithLatestVersions.forEach((secret) => {
|
||||||
if (!secret.reminderRepeatDays) return;
|
if (!secret.reminderRepeatDays) return;
|
||||||
const nextReminderDate = new Date(secret.createdAt);
|
|
||||||
|
const now = new Date();
|
||||||
|
const createdAt = new Date(secret.createdAt);
|
||||||
|
let nextReminderDate = new Date(createdAt);
|
||||||
nextReminderDate.setDate(nextReminderDate.getDate() + secret.reminderRepeatDays);
|
nextReminderDate.setDate(nextReminderDate.getDate() + secret.reminderRepeatDays);
|
||||||
|
|
||||||
|
// If the next reminder date is in the past, calculate the proper next occurrence
|
||||||
|
if (nextReminderDate < now) {
|
||||||
|
const daysSinceCreation = Math.floor((now.getTime() - createdAt.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
|
const daysIntoCurrentCycle = daysSinceCreation % secret.reminderRepeatDays;
|
||||||
|
const daysUntilNextReminder = secret.reminderRepeatDays - daysIntoCurrentCycle;
|
||||||
|
|
||||||
|
nextReminderDate = new Date(now);
|
||||||
|
nextReminderDate.setDate(now.getDate() + daysUntilNextReminder);
|
||||||
|
}
|
||||||
|
|
||||||
reminderInserts.push({
|
reminderInserts.push({
|
||||||
secretId: secret.secretId,
|
secretId: secret.secretId,
|
||||||
message: secret.reminderNote,
|
message: secret.reminderNote,
|
||||||
|
|||||||
Reference in New Issue
Block a user