From 56228674111d203cee9a51a6fa4a0a12c98c0dc8 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 6 Dec 2025 11:46:21 +0100 Subject: [PATCH] Add upsert behavior to service creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Delete existing service before creating new one - Prevents UNIQUE constraint error on (username, service_fqn) - Enables seamless service republishing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/app.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/app.ts b/src/app.ts index 35cde5a..66c066f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -217,6 +217,15 @@ export function createApp(storage: Storage, config: Config) { return c.json({ error: 'Invalid signature for username' }, 403); } + // Delete existing service if one exists (upsert behavior) + const existingUuid = await storage.queryService(username, serviceFqn); + if (existingUuid) { + const existingService = await storage.getServiceByUuid(existingUuid); + if (existingService) { + await storage.deleteService(existingService.id, username); + } + } + // Validate SDP if (typeof sdp !== 'string' || sdp.length === 0) { return c.json({ error: 'Invalid SDP' }, 400);