Fix fresh schema to match D1 storage expectations

Changed offers table to use service_id (nullable) instead of service_fqn.
This matches the actual D1 storage implementation in d1.ts which expects:
- service_id TEXT (optional link to service)
- NOT service_fqn (that's only in the services table)

Resolves 'NOT NULL constraint failed: offers.service_fqn' error.
This commit is contained in:
2025-12-10 18:32:43 +01:00
parent 00c5bbc501
commit 9088abe305

View File

@@ -11,10 +11,11 @@ DROP TABLE IF EXISTS usernames;
CREATE TABLE offers (
id TEXT PRIMARY KEY,
peer_id TEXT NOT NULL,
service_fqn TEXT NOT NULL,
service_id TEXT,
sdp TEXT NOT NULL,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
last_seen INTEGER NOT NULL,
secret TEXT,
answerer_peer_id TEXT,
answer_sdp TEXT,
@@ -22,10 +23,10 @@ CREATE TABLE offers (
);
CREATE INDEX idx_offers_peer ON offers(peer_id);
CREATE INDEX idx_offers_service_fqn ON offers(service_fqn);
CREATE INDEX idx_offers_service ON offers(service_id);
CREATE INDEX idx_offers_expires ON offers(expires_at);
CREATE INDEX idx_offers_last_seen ON offers(last_seen);
CREATE INDEX idx_offers_answerer ON offers(answerer_peer_id);
CREATE INDEX idx_offers_available ON offers(answerer_peer_id) WHERE answerer_peer_id IS NULL;
-- ICE candidates table
CREATE TABLE ice_candidates (