mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 18:13:42 +00:00
fix(multiplayer): constrain ranked arena paths in postgres
This commit is contained in:
@@ -4,5 +4,31 @@
|
||||
ALTER TABLE proposals
|
||||
ADD COLUMN match_arena_path TEXT;
|
||||
|
||||
ALTER TABLE proposals
|
||||
ADD CONSTRAINT proposals_ranked_arena_path
|
||||
CHECK (
|
||||
playlist <> 'ranked' OR (
|
||||
match_arena_path IS NOT NULL AND
|
||||
match_arena_path IN (
|
||||
'res://scenes/arena_01.tscn',
|
||||
'res://scenes/arena_02.tscn',
|
||||
'res://scenes/arena_03.tscn'
|
||||
)
|
||||
)
|
||||
) NOT VALID;
|
||||
|
||||
ALTER TABLE matches
|
||||
ADD COLUMN arena_path TEXT;
|
||||
|
||||
ALTER TABLE matches
|
||||
ADD CONSTRAINT matches_ranked_arena_path
|
||||
CHECK (
|
||||
playlist <> 'ranked' OR (
|
||||
arena_path IS NOT NULL AND
|
||||
arena_path IN (
|
||||
'res://scenes/arena_01.tscn',
|
||||
'res://scenes/arena_02.tscn',
|
||||
'res://scenes/arena_03.tscn'
|
||||
)
|
||||
)
|
||||
) NOT VALID;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
ALTER TABLE matches
|
||||
DROP CONSTRAINT IF EXISTS matches_ranked_arena_path,
|
||||
DROP COLUMN IF EXISTS arena_path;
|
||||
ALTER TABLE proposals
|
||||
DROP CONSTRAINT IF EXISTS proposals_ranked_arena_path,
|
||||
DROP COLUMN IF EXISTS match_arena_path;
|
||||
|
||||
@@ -7,6 +7,7 @@ import unittest
|
||||
SQL = (Path(__file__).parent / "0001_initial.sql").read_text()
|
||||
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()
|
||||
|
||||
|
||||
class MigrationTest(unittest.TestCase):
|
||||
@@ -59,6 +60,14 @@ class MigrationTest(unittest.TestCase):
|
||||
self.assertIn(fragment, QUOTAS_SQL)
|
||||
self.assertIn("region IN ('EU', 'NA')", QUOTAS_SQL)
|
||||
|
||||
def test_ranked_arena_paths_are_database_enforced_for_new_rows(self):
|
||||
for fragment in (
|
||||
"proposals_ranked_arena_path", "matches_ranked_arena_path", "NOT VALID",
|
||||
"match_arena_path IS NOT NULL", "arena_path IS NOT NULL",
|
||||
"res://scenes/arena_01.tscn", "res://scenes/arena_02.tscn", "res://scenes/arena_03.tscn",
|
||||
):
|
||||
self.assertIn(fragment, ARENAS_SQL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user