fix(mirrors): keep last copy state (#125)

This commit is contained in:
Nico 2025-12-10 21:18:10 +01:00 committed by GitHub
parent 2ddf3c6597
commit ef8fd7228f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -502,15 +502,32 @@ const updateMirrors = async (scheduleId: number, data: UpdateScheduleMirrorsBody
}
}
const existingMirrors = await db.query.backupScheduleMirrorsTable.findMany({
where: eq(backupScheduleMirrorsTable.scheduleId, scheduleId),
});
const existingMirrorsMap = new Map(
existingMirrors.map((m) => [
m.repositoryId,
{ lastCopyAt: m.lastCopyAt, lastCopyStatus: m.lastCopyStatus, lastCopyError: m.lastCopyError },
]),
);
await db.delete(backupScheduleMirrorsTable).where(eq(backupScheduleMirrorsTable.scheduleId, scheduleId));
if (data.mirrors.length > 0) {
await db.insert(backupScheduleMirrorsTable).values(
data.mirrors.map((mirror) => ({
scheduleId,
repositoryId: mirror.repositoryId,
enabled: mirror.enabled,
})),
data.mirrors.map((mirror) => {
const existing = existingMirrorsMap.get(mirror.repositoryId);
return {
scheduleId,
repositoryId: mirror.repositoryId,
enabled: mirror.enabled,
lastCopyAt: existing?.lastCopyAt ?? null,
lastCopyStatus: existing?.lastCopyStatus ?? null,
lastCopyError: existing?.lastCopyError ?? null,
};
}),
);
}