Fix UNIQUE constraint: Use (service_name, version, username) instead of service_fqn

- Change UNIQUE constraint to composite key on separate columns
- Move upsert logic into D1Storage.createService() for atomic operation
- Delete existing service and its offers before inserting new one
- Remove redundant delete logic from app.ts endpoint
- Fixes 'UNIQUE constraint failed: services.service_fqn' error when republishing
This commit is contained in:
2025-12-10 19:42:03 +01:00
parent cfa58f1dfa
commit e3ede0033e
3 changed files with 22 additions and 7 deletions

View File

@@ -337,11 +337,7 @@ 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 existingService = await storage.getServiceByFqn(serviceFqn);
if (existingService) {
await storage.deleteService(existingService.id, username);
}
// Note: createService handles upsert behavior (deletes existing service if it exists)
// Validate all offers
for (const offer of offers) {