-- 0004_rename_runs_partial_index.sql — clarify semantics of the is_playground partial index.
-- ADR: docs/adr/2026-05-14-playground-runs-bill-like-real-invocations.md.
--
-- Migration 0003 created the partial index `runs_billable_workspace_started_idx`
-- on `stackbone_platform.runs (workspace_id, started_at DESC NULLS LAST)
-- WHERE is_playground = false`. Its name and accompanying comments framed the
-- predicate as the "billable" set — that framing is wrong.
--
-- Playground runs DO bill: invoking from Studio consumes real LLM tokens, real
-- DB queries and real compute, and the creator's organization is charged for
-- it like any other invocation (otherwise a malicious client could mark all
-- production traffic with `X-Stackbone-Playground: 1` and dodge billing). The
-- predicate `WHERE is_playground = false` actually identifies the rows that
-- count toward Trust Layer / public marketplace aggregations (p50 latency,
-- success rate, median cost) — a slow demo run from Studio must not lower
-- the public stats of an `agent_template`.
--
-- This migration renames the index so the next reader gets the semantics
-- right. The index definition (table, columns, predicate) is unchanged.

ALTER INDEX IF EXISTS stackbone_platform.runs_billable_workspace_started_idx
  RENAME TO runs_public_metrics_workspace_started_idx;
