Files
Maxime Van Hees 4d024a39f4 first MVP
2025-11-14 21:07:10 +01:00

14 lines
501 B
SQL

-- Enforce undirected connection uniqueness and prevent self-edges
-- Prevent self-edge (A == B)
ALTER TABLE "Connection"
ADD CONSTRAINT "Connection_no_self_edge"
CHECK ("personAId" <> "personBId");
-- Unique undirected pair using functional index on LEAST/GREATEST
-- Ensures only one edge exists for a given unordered pair {A,B}
CREATE UNIQUE INDEX IF NOT EXISTS "Connection_undirected_pair_unique"
ON "Connection" (
(LEAST("personAId","personBId")),
(GREATEST("personAId","personBId"))
);