Add upsert behavior to service creation

- 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 <noreply@anthropic.com>
This commit is contained in:
2025-12-06 11:46:21 +01:00
parent ac0e064e34
commit 5622867411

View File

@@ -217,6 +217,15 @@ export function createApp(storage: Storage, config: Config) {
return c.json({ error: 'Invalid signature for username' }, 403); 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 // Validate SDP
if (typeof sdp !== 'string' || sdp.length === 0) { if (typeof sdp !== 'string' || sdp.length === 0) {
return c.json({ error: 'Invalid SDP' }, 400); return c.json({ error: 'Invalid SDP' }, 400);