ALTER TABLE matches ADD COLUMN initial_connect_ready_at TIMESTAMPTZ; -- Existing in-flight matches receive a fresh, fair connection window when -- this migration is deployed. Future rows are stamped by the transition to -- ASSIGNMENT_READY, not by match creation or provider allocation. UPDATE matches SET initial_connect_ready_at = now() WHERE state IN ('ASSIGNMENT_READY', 'ASSIGNED', 'CONNECTING'); ALTER TABLE matches ADD CONSTRAINT matches_initial_connect_ready_at CHECK (state NOT IN ('ASSIGNMENT_READY', 'ASSIGNED', 'CONNECTING') OR initial_connect_ready_at IS NOT NULL) NOT VALID;