mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
18 lines
686 B
SQL
18 lines
686 B
SQL
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;
|