mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 15:02:04 +00:00
feat(multiplayer): persist connection generation leases
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user