-- Per-character voice assignment for multi-voice audiobook rendering.
-- A NULL voice_id means "use the story's default narrator voice for
-- this character's dialogue" (effectively no voice change vs the
-- narrator). A non-NULL voice_id pins the character's dialogue to
-- that specific voice.
--
-- slug is the stable lowercase token the narrate_prep pass uses
-- inside [voice:<slug>]...[/voice] markers. Distinct from name so
-- "Anatoly Dyatlov" can carry slug "dyatlov" without re-deriving on
-- every render.
ALTER TABLE characters
    ADD COLUMN voice_id uuid REFERENCES voices(id) ON DELETE SET NULL,
    ADD COLUMN slug text;

CREATE INDEX idx_characters_voice ON characters(voice_id) WHERE voice_id IS NOT NULL;
CREATE UNIQUE INDEX idx_characters_story_slug ON characters(story_id, slug) WHERE slug IS NOT NULL;
