Name each database target's archive for its webhook and target (closes #376)
check / check (push) Successful in 3m14s

Each database target now has its own archive file,
archive-WEBHOOKNAME-TARGETNAME-TARGETID.db, instead of one
archive-WEBHOOKID.db per webhook. delivery.ArchiveFileName builds the
name: each name is lowercased, keeps ASCII letters and digits, turns
every other run of characters into one dash, and is cut to 40
characters.

Renaming a webhook or a target renames its archive files under the
archive writer's lock, before the new name is saved, and back again if
the save fails. Deleting a target evicts only that target's writer.
Archive files are never deleted, and nothing looks for files under the
old name.

Model: opus-5-5
This commit is contained in:
2026-10-02 05:10:15 +00:00
parent 7d360babed
commit d88948a1c3
21 changed files with 1277 additions and 663 deletions
+37 -1
View File
@@ -152,11 +152,30 @@ func (h *Handlers) applyTargetEdit(
target.MaxRetries = retries
}
oldName := target.Name
target.Name = name
target.Config = configJSON
err = h.db.DB().Save(target).Error
// The archive file is renamed before the new name is saved (see
// delivery.Engine.RenameArchive). If either step fails, it goes
// back to the name that is still stored.
err = h.renameTargetArchive(target, webhook.Name, name)
if err == nil {
err = h.db.DB().Save(target).Error
}
if err != nil {
restoreErr := h.renameTargetArchive(
target, webhook.Name, oldName,
)
if restoreErr != nil {
h.log.Error(
"failed to rename archive back",
"target_id", target.ID,
"error", restoreErr,
)
}
h.serverError(w, "failed to update target", err)
return
@@ -167,6 +186,23 @@ func (h *Handlers) applyTargetEdit(
)
}
// renameTargetArchive renames a database target's archive file for
// the given webhook and target names. Other target types have no
// archive.
func (h *Handlers) renameTargetArchive(
target *database.Target,
webhookName, targetName string,
) error {
if h.archives == nil ||
target.Type != database.TargetTypeDatabase {
return nil
}
return h.archives.RenameArchive(
target.ID, webhookName, targetName,
)
}
// renderTargetEdit renders the target edit page with an optional
// error message.
func (h *Handlers) renderTargetEdit(