Files
CosmicClash/server/migrations/0006_match_allocation_claims.sql
T
2026-09-01 10:36:13 +01:00

13 lines
602 B
SQL

-- Allocation is an external call, so a durable leased claim fences competing
-- allocator replicas before any provider request. A timed-out claim can be
-- recovered with the same deterministic allocation ID after a worker crash.
ALTER TABLE matches
ADD COLUMN allocation_id TEXT UNIQUE,
ADD COLUMN allocation_claimed_at TIMESTAMPTZ,
ADD CONSTRAINT matches_allocation_claim_pair
CHECK ((allocation_id IS NULL) = (allocation_claimed_at IS NULL));
CREATE INDEX matches_allocating_claimable
ON matches (created_at, match_id)
WHERE state = 'ALLOCATING' AND server_id IS NULL;