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

@@ -68,7 +68,7 @@ CREATE TABLE services (
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE,
UNIQUE(service_fqn)
UNIQUE(service_name, version, username)
);
CREATE INDEX idx_services_fqn ON services(service_fqn);