ALTER TABLE match_participants ADD COLUMN disconnected_at TIMESTAMPTZ; -- The pre-lease connection receipt populated connected_at but did not advance -- the already-present generation column. Preserve those live admissions as -- generation one before enforcing the lease invariant. UPDATE match_participants SET connection_generation = 1 WHERE connected_at IS NOT NULL AND connection_generation = 0; ALTER TABLE match_participants ADD CONSTRAINT match_participants_connection_lease CHECK ( (connection_generation = 0 AND connected_at IS NULL AND disconnected_at IS NULL) OR (connection_generation > 0 AND connected_at IS NOT NULL) ) NOT VALID;