mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix(multiplayer): reconcile authoritative initial connections
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE matches
|
||||
DROP CONSTRAINT IF EXISTS matches_initial_connect_ready_at,
|
||||
DROP COLUMN IF EXISTS initial_connect_ready_at;
|
||||
@@ -9,6 +9,7 @@ ASSIGNMENTS_SQL = (Path(__file__).parent / "0002_assignments.sql").read_text()
|
||||
QUOTAS_SQL = (Path(__file__).parent / "0007_allocation_quotas.sql").read_text()
|
||||
ARENAS_SQL = (Path(__file__).parent / "0008_match_arena_paths.sql").read_text()
|
||||
ALLOCATION_ARENAS_SQL = (Path(__file__).parent / "0009_allocation_arena_paths.sql").read_text()
|
||||
INITIAL_CONNECT_READY_SQL = (Path(__file__).parent / "0010_initial_connect_ready_at.sql").read_text()
|
||||
|
||||
|
||||
class MigrationTest(unittest.TestCase):
|
||||
@@ -73,6 +74,10 @@ class MigrationTest(unittest.TestCase):
|
||||
self.assertIn("ALTER TABLE allocations", ALLOCATION_ARENAS_SQL)
|
||||
self.assertIn("ADD COLUMN arena_path TEXT", ALLOCATION_ARENAS_SQL)
|
||||
|
||||
def test_initial_connect_window_starts_at_assignment_readiness(self):
|
||||
self.assertIn("ADD COLUMN initial_connect_ready_at TIMESTAMPTZ", INITIAL_CONNECT_READY_SQL)
|
||||
self.assertIn("state IN ('ASSIGNMENT_READY', 'ASSIGNED', 'CONNECTING')", INITIAL_CONNECT_READY_SQL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user