mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 03:26:27 +00:00
Merge pull request #4237 from Infisical/fix/remindersMigrationFix
Fix secret reminders migration job
This commit is contained in:
@@ -11,7 +11,7 @@ import { TReminderServiceFactory } from "./reminder-types";
|
|||||||
type TDailyReminderQueueServiceFactoryDep = {
|
type TDailyReminderQueueServiceFactoryDep = {
|
||||||
reminderService: TReminderServiceFactory;
|
reminderService: TReminderServiceFactory;
|
||||||
queueService: TQueueServiceFactory;
|
queueService: TQueueServiceFactory;
|
||||||
secretDAL: Pick<TSecretV2BridgeDALFactory, "transaction" | "findSecretsWithReminderRecipients">;
|
secretDAL: Pick<TSecretV2BridgeDALFactory, "transaction" | "findSecretsWithReminderRecipientsOld">;
|
||||||
secretReminderRecipientsDAL: Pick<TSecretReminderRecipientsDALFactory, "delete">;
|
secretReminderRecipientsDAL: Pick<TSecretReminderRecipientsDALFactory, "delete">;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ export const dailyReminderQueueServiceFactory = ({
|
|||||||
|
|
||||||
// Find existing secrets with pagination
|
// Find existing secrets with pagination
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const secrets = await secretDAL.findSecretsWithReminderRecipients(batchIds, REMINDER_PRUNE_BATCH_SIZE);
|
const secrets = await secretDAL.findSecretsWithReminderRecipientsOld(batchIds, REMINDER_PRUNE_BATCH_SIZE);
|
||||||
const secretsWithReminder = secrets.filter((secret) => secret.reminderRepeatDays);
|
const secretsWithReminder = secrets.filter((secret) => secret.reminderRepeatDays);
|
||||||
|
|
||||||
const foundSecretIds = new Set(secretsWithReminder.map((secret) => secret.id));
|
const foundSecretIds = new Set(secretsWithReminder.map((secret) => secret.id));
|
||||||
|
|||||||
@@ -308,12 +308,11 @@ export const reminderServiceFactory = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const newReminders = await reminderDAL.insertMany(
|
const newReminders = await reminderDAL.insertMany(
|
||||||
processedReminders.map(({ secretId, message, repeatDays, nextReminderDate, projectId }) => ({
|
processedReminders.map(({ secretId, message, repeatDays, nextReminderDate }) => ({
|
||||||
secretId,
|
secretId,
|
||||||
message,
|
message,
|
||||||
repeatDays,
|
repeatDays,
|
||||||
nextReminderDate,
|
nextReminderDate
|
||||||
projectId
|
|
||||||
})),
|
})),
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -875,6 +875,48 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const findSecretsWithReminderRecipientsOld = async (ids: string[], limit: number, tx?: Knex) => {
|
||||||
|
try {
|
||||||
|
// Create a subquery to get limited secret IDs
|
||||||
|
const limitedSecretIds = (tx || db)(TableName.SecretV2)
|
||||||
|
.whereIn(`${TableName.SecretV2}.id`, ids)
|
||||||
|
.limit(limit)
|
||||||
|
.select("id");
|
||||||
|
|
||||||
|
// Join with all recipients for the limited secrets
|
||||||
|
const docs = await (tx || db)(TableName.SecretV2)
|
||||||
|
.whereIn(`${TableName.SecretV2}.id`, limitedSecretIds)
|
||||||
|
.leftJoin(TableName.Reminder, `${TableName.SecretV2}.id`, `${TableName.Reminder}.secretId`)
|
||||||
|
.leftJoin(
|
||||||
|
TableName.SecretReminderRecipients,
|
||||||
|
`${TableName.SecretV2}.id`,
|
||||||
|
`${TableName.SecretReminderRecipients}.secretId`
|
||||||
|
)
|
||||||
|
.select(selectAllTableCols(TableName.SecretV2))
|
||||||
|
.select(db.ref("userId").withSchema(TableName.SecretReminderRecipients).as("reminderRecipientUserId"));
|
||||||
|
|
||||||
|
const data = sqlNestRelationships({
|
||||||
|
data: docs,
|
||||||
|
key: "id",
|
||||||
|
parentMapper: (el) => ({
|
||||||
|
_id: el.id,
|
||||||
|
...SecretsV2Schema.parse(el)
|
||||||
|
}),
|
||||||
|
childrenMapper: [
|
||||||
|
{
|
||||||
|
key: "reminderRecipientUserId",
|
||||||
|
label: "recipients" as const,
|
||||||
|
mapper: ({ reminderRecipientUserId }) => reminderRecipientUserId
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "findSecretsWithReminderRecipientsOld" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...secretOrm,
|
...secretOrm,
|
||||||
update,
|
update,
|
||||||
@@ -893,6 +935,7 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
|
|||||||
findOne,
|
findOne,
|
||||||
find,
|
find,
|
||||||
invalidateSecretCacheByProjectId,
|
invalidateSecretCacheByProjectId,
|
||||||
findSecretsWithReminderRecipients
|
findSecretsWithReminderRecipients,
|
||||||
|
findSecretsWithReminderRecipientsOld
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user