-- 0003_runs_is_playground_index.sql — billing-friendly partial index over runs.
-- Spec: docs/tasks/Studio V5 - Playground e Invoke.md (V5#01).
-- ADR:  docs/arquitectura/decisiones/2026-05-03-stackbone-studio-datapath-y-scope-mvp.md §D5/D9.
--
-- The `is_playground` column itself already lives in 0001_runs.sql (F2 baked it
-- in defensively so playground writes had a place to land before V5 shipped).
-- This migration adds the partial index that the billing pipeline and the
-- workspace-level aggregations (V1+ Workspace Health, LLM Usage) need to scan
-- only the runs that count toward billing — i.e. `is_playground = false`.
-- Keeping it partial keeps the index small even when a workspace stress-tests
-- the agent from the Playground.

CREATE INDEX IF NOT EXISTS runs_billable_workspace_started_idx
    ON stackbone_platform.runs (workspace_id, started_at DESC NULLS LAST)
    WHERE is_playground = false;
