---
name: "supabase-realtime-postgres-sync"
description: "Stream live database changes and user presence states directly to web clients with Supabase."
metadata:
  author: "Supabase"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "subscribe postgres_changes supabase"
  - "supabase presence tracking"
  - "supabase realtime broadcast"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Supabase Realtime PostgreSQL CDC Broadcasts & Presence

Implements Supabase Realtime: subscribing to PostgreSQL table changes (postgres_changes), client-to-client broadcasts (broadcast), tracking online user presence (presence), and managing channel cleanup.

## When to Invoke
Invoke this skill whenever you need to:
- subscribe postgres_changes supabase
- supabase presence tracking
- supabase realtime broadcast

## Execution SOP & Rules
1. Create channel: const channel = supabase.channel('room_1').
2. Listen to DB changes: channel.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'messages' }, handleNewMessage).
3. Track presence: channel.on('presence', { event: 'sync' }, () => { const state = channel.presenceState(); }).subscribe();
4. Always unsubscribe on component unmount: supabase.removeChannel(channel).

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
