mirror of
https://github.com/supabase/agent-skills.git
synced 2026-03-27 10:09:26 +08:00
4.6 KiB
4.6 KiB
Scenario: postgrest-schema-cache
Summary
The agent must create a migration that adds new columns to an existing table
and create a view that uses those columns, including the correct NOTIFY pgrst, 'reload schema' call to force PostgREST to pick up the schema changes.
Without this, the API returns 400 errors for the new columns even after
migration.
Real-World Justification
Why this is a common and important workflow:
- Direct troubleshooting entry — "PostgREST not recognizing new columns, tables, views or functions" and "Reload/refresh postgrest schema" (400 bad_request error) are explicitly listed in the Supabase troubleshooting guide. This is among the most confusing errors for new Supabase developers — the migration ran successfully but the API still returns errors.
- Schema cache invalidation — PostgREST caches the database schema at
startup and reloads it only when notified. Migrations that add new objects
must explicitly call
NOTIFY pgrst, 'reload schema'at the end of the migration file for the changes to be reflected immediately in local development. - Views and RLS — Creating a view over a user-owned table requires
understanding that RLS applies to the underlying tables, and the view itself
should use
security_invoker = trueto preserve RLS context.
Skill References Exercised
| Reference File | What It Teaches | What the Agent Should Apply |
|---|---|---|
references/db-rls-views.md |
Views need security_invoker to respect RLS | WITH (security_invoker = true) on view |
references/db-migrations-idempotent.md |
ADD COLUMN IF NOT EXISTS; IF NOT EXISTS patterns | Idempotent column additions |
references/db-rls-mandatory.md |
RLS on base tables | RLS enabled on base table |
references/db-rls-performance.md |
(select auth.uid()) subselect | Subselect form in policies |
references/db-schema-timestamps.md |
timestamptz for new columns | timestamptz on added columns |
Workspace Setup
- A workspace with
supabase/config.tomland a starter migration that creates a basicproductstable (id, name, price) with RLS enabled but no policies.
Agent Task (PROMPT.md draft)
Our
productstable needs two new columns:description(text) andpublished_at(timestamp). Also create a view calledpublic_productsthat shows only products wherepublished_atis not null. Add a policy so any authenticated user can view published products. Put changes in a new migration file insupabase/migrations/.
Evaluation Criteria
| # | Test Name | What It Checks | Quality Dimension |
|---|---|---|---|
| 1 | new migration file exists | A second .sql file in supabase/migrations/ |
structure |
| 2 | ADD COLUMN IF NOT EXISTS for description | ADD COLUMN IF NOT EXISTS description |
idempotency |
| 3 | ADD COLUMN IF NOT EXISTS for published_at | ADD COLUMN IF NOT EXISTS published_at |
idempotency |
| 4 | published_at uses timestamptz | published_at timestamptz not plain timestamp |
correctness |
| 5 | view created | CREATE OR REPLACE VIEW public_products or similar |
correctness |
| 6 | view uses security_invoker | security_invoker = true on the view |
security |
| 7 | SELECT policy on products for authenticated | A FOR SELECT policy on products with TO authenticated | security |
| 8 | NOTIFY pgrst reload present | NOTIFY pgrst in the migration |
correctness |
Reasoning
- Baseline differentiator: Agents without the skill add columns correctly
but miss
IF NOT EXISTS, use plaintimestamp, forgetsecurity_invokeron the view, and almost never include theNOTIFY pgrstcall. - Skill value: The NOTIFY pattern and security_invoker requirement are non-obvious details that the reference files teach explicitly.
- Testability:
NOTIFY pgrstis a unique string that either appears or doesn't;security_invokeris similarly specific. - Realism: Iterative schema evolution (adding columns to existing tables) is the most common database task after initial setup, and the PostgREST cache invalidation issue is a universal source of confusion.
Difficulty
Rating: MEDIUM
- Without skill: ~40% of assertions expected to pass (columns added and view created, but no IF NOT EXISTS, wrong timestamp type, no NOTIFY, no security_invoker)
- With skill: ~88% of assertions expected to pass
- pass_threshold: 7