fix(sagent): accept task-scoped event lines in the target constraint
ZhenYi committed
Modified lib/models/schema_extras.sql lib/models/schema_extras.sql +10 −6 View lib/models/schema_extras.sql
@@ -301,7 +301,7 @@
301301 ON ci_runner (state, last_seen_at DESC);
302302
303303-- ---------------------------------------------------------------------------
304-- Sagent domain (lib/sagent): XOR guard for polymorphic event lines, plus
304-- Sagent domain (lib/sagent): target guard for polymorphic event lines, plus
305305-- lookup indexes.
306306--
307307-- Caveat: SeaORM sync drops any unique index on a managed table whose column
@@ -310,12 +310,16 @@
310310-- So only NON-unique indexes (or partial variants of a declared unique key)
311311-- may be added here.
312312-- ---------------------------------------------------------------------------
313-- Every activity line belongs to a task, and records its collection too so the
314-- collection feed needs no join. "At least one target" (not XOR) is what that
315-- shape allows; a line with neither is still an orphan and is rejected.
316-- The constraint is dropped first so an older definition is replaced instead of
317-- being skipped by the existence check.
313318DO $$ BEGIN
314 IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'agent_event_target_xor') THEN
315 ALTER TABLE agent_event_line
316 ADD CONSTRAINT agent_event_target_xor
317 CHECK (((agent_id IS NOT NULL)::int + (collection_id IS NOT NULL)::int) = 1);
318 END IF;
319 ALTER TABLE agent_event_line DROP CONSTRAINT IF EXISTS agent_event_target_xor;
320 ALTER TABLE agent_event_line
321 ADD CONSTRAINT agent_event_target_xor
322 CHECK (agent_id IS NOT NULL OR collection_id IS NOT NULL);
319323END $$;
320324
321325CREATE INDEX IF NOT EXISTS idx_agent_collection_state