-- Migration: 039-add-oidc-client-missing-metadata.sql
-- Description: Add missing oidc_grants indexes for Session/Interaction/AuthorizationCode models
-- Date: 2026-06-16

-- Indexes to speed up adapter lookups for oidc_grants table
CREATE INDEX IF NOT EXISTS idx_oidc_grants_model_id_expires
  ON oidc_grants(model, id, expires_at)
  WHERE expires_at IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_oidc_grants_model_payload_uid
  ON oidc_grants(model, (payload->>'uid'))
  WHERE payload IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_oidc_grants_model_payload_user_code
  ON oidc_grants(model, (payload->>'userCode'))
  WHERE payload IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_oidc_grants_model_payload_grant_id
  ON oidc_grants(model, (payload->>'grantId'))
  WHERE payload IS NOT NULL;
