-- 004_create_personas.sql
-- Persona table for AI-generated personas with multi-stage generation pipeline.
-- Compatible with both PostgreSQL (local dev) and CockroachDB (production).

CREATE TABLE IF NOT EXISTS personas (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    name        TEXT NOT NULL,
    handle      TEXT UNIQUE NOT NULL,
    gender      TEXT NOT NULL,
    description TEXT NOT NULL,
    tags        TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
    spec_json   JSONB,
    anchor_url  TEXT,
    avatar_url  TEXT,
    banner_url  TEXT,
    image_urls  TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
    video_urls  TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
    status      TEXT NOT NULL DEFAULT 'pending',
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_personas_status ON personas (status, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_personas_handle ON personas (handle);
