feat(multiplayer): persist connection generation leases

This commit is contained in:
Josh Creek
2026-09-03 13:38:13 +01:00
parent 2e9da3032c
commit 3e0022ce9c
10 changed files with 286 additions and 80 deletions
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,3 @@
ALTER TABLE match_participants
DROP CONSTRAINT IF EXISTS match_participants_connection_lease,
DROP COLUMN IF EXISTS disconnected_at;