Files
CosmicClash/server/migrations/test_migration.py
T
2026-08-31 20:12:19 +01:00

40 lines
1.5 KiB
Python

"""Static migration checks; PostgreSQL integration runs in the backend CI."""
from pathlib import Path
import unittest
SQL = (Path(__file__).parent / "0001_initial.sql").read_text()
class MigrationTest(unittest.TestCase):
def test_durable_domains_and_fences_exist(self):
required_tables = {
"identities", "sessions", "queue_tickets", "proposals",
"proposal_participants", "matches", "match_participants",
"ratings", "result_receipts", "outbox", "audit_events",
}
for table in required_tables:
self.assertIn(f"CREATE TABLE {table}", SQL)
self.assertIn("queue_tickets_one_active_per_player", SQL)
self.assertIn("match_participants_one_active_match", SQL)
self.assertIn("UNIQUE (aggregate_type, aggregate_id, revision)", SQL)
def test_redis_is_not_a_durable_dependency(self):
self.assertNotIn("CREATE TABLE redis", SQL.lower())
self.assertNotIn("redis_id", SQL.lower())
self.assertIn("CREATE TABLE outbox", SQL)
self.assertIn("published_at", SQL)
def test_no_unbounded_or_client_owned_identity_fields(self):
self.assertIn("steam_id TEXT NOT NULL UNIQUE", SQL)
self.assertIn("token_digest BYTEA NOT NULL UNIQUE", SQL)
self.assertIn("payload JSONB NOT NULL", SQL)
self.assertNotIn("steam_ticket TEXT", SQL)
self.assertIn("participation_active BOOLEAN NOT NULL DEFAULT TRUE", SQL)
self.assertIn("WHERE participation_active", SQL)
if __name__ == "__main__":
unittest.main()