-- Merit nodes: a ceremony node that awards an achievement when the playthrough
-- reaches it (Scene 8 — "The Barricelli Luggage"). The awarded flag is authored on
-- the node; the runtime grants it on arrival with node provenance. Merit nodes may
-- also carry a component_key for their ceremony presentation (e.g. a 3D model).

ALTER TABLE osint.story_nodes DROP CONSTRAINT story_nodes_node_type_check;
ALTER TABLE osint.story_nodes ADD CONSTRAINT story_nodes_node_type_check
  CHECK (node_type IN ('cutscene','dialogue','level','det_gate','llm_gate','merit'));

-- Let a merit node carry a ceremony component_key (was cutscene/gate only).
ALTER TABLE osint.story_nodes DROP CONSTRAINT story_nodes_check1;
ALTER TABLE osint.story_nodes ADD CONSTRAINT story_nodes_check1
  CHECK (component_key IS NULL OR node_type IN ('cutscene','det_gate','llm_gate','merit'));

ALTER TABLE osint.story_nodes ADD COLUMN awards_flag TEXT
  CHECK (awards_flag IS NULL OR awards_flag ~ '^[a-z][a-z0-9_.-]{0,63}$');
ALTER TABLE osint.story_nodes ADD CONSTRAINT story_nodes_awards_flag_type
  CHECK (awards_flag IS NULL OR node_type = 'merit');
