What the agent does
The agent reads the schema and the client before it writes SQL. In a project shaped like Razikus/supabase-nextjs-template, supabase/config.toml sets Postgres major_version 15 on port 54322 and enables a seed.sql on db reset, and supabase/migrations holds four files: the MFA migration that creates the authenticative schema and its is_user_authenticated() function, two storage migrations, and 20250130181641_todo_list.sql, which creates public.todo_list with id, created_at, title text not null, urgent, description text, done, done_at and owner uuid referencing auth.users, enables row level security, grants the table to anon, authenticated and service_role, and adds one policy, Owner can do everything, for authenticated using is_user_authenticated() AND owner = auth.uid(). On the Next.js side, nextjs/src/lib/supabase/unified.ts wraps the client in SassClient, whose getMyTodoList selects * with range and order and an optional done filter, nextjs/src/lib/types.ts is the generated Database type with Functions empty, and nextjs/src/app/app/table/page.tsx loads tasks with a done filter and offers no search. The Expo app in supabase-expo-template reads the same table.
The agent adds one migration, supabase/migrations/<timestamp>_todo_list_search.sql. It adds a generated column search tsvector generated always as (setweight(to_tsvector('english', coalesce(title, '')), 'A') || setweight(to_tsvector('english', coalesce(description, '')), 'B')) stored, a GIN index on it, and a function public.search_todos(query text) returns setof public.todo_list language sql stable with security invoker and set search_path = public, which filters with websearch_to_tsquery('english', query) and orders by ts_rank. Because the function runs as the caller, the existing Owner can do everything policy applies inside it, so a user searches only their own rows and the MFA requirement in is_user_authenticated() still holds. Nothing in the existing migrations is edited.
Then it regenerates the types with supabase gen types typescript --local into nextjs/src/lib/types.ts, so Functions now declares search_todos with its argument and return row, adds searchMyTodoList(query) to SassClient calling this.client.rpc('search_todos', { query }), and adds a search input to the table page that calls it after a short debounce and falls back to getMyTodoList when the box is empty, keeping the done filter and the existing cards. The generated search column is excluded from the insert in CreateTaskDialog, which already builds the row explicitly.
The proof runs on a local stack. The agent runs supabase start, supabase db reset to apply all migrations and the seed, inserts two rows as a test user through psql on port 54322 and calls select * from search_todos('groceries') as that user with the authenticated role and the user's claims set, showing the match and the empty result for another user. In nextjs it runs npm run lint and npm run build, and loads the table page in the sandbox browser against the local stack to type a query. It documents the function in README.md under the task management section.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add full-text search for tasks to this Supabase project and open a pull request. Read supabase/config.toml, every file under supabase/migrations, nextjs/package.json, nextjs/src/lib/types.ts, nextjs/src/lib/supabase/unified.ts, nextjs/src/lib/supabase/client.ts and nextjs/src/app/app/table/page.tsx first; do not edit an existing migration. Add one migration that gives public.todo_list a stored generated tsvector column weighting title over description, a GIN index on it, and a function public.search_todos(query text) returning setof public.todo_list, language sql, stable, security invoker, with search_path set to public, that filters with websearch_to_tsquery and orders by ts_rank. Regenerate nextjs/src/lib/types.ts with supabase gen types typescript --local. Add searchMyTodoList to SassClient using rpc, and a debounced search input on the table page that uses it and falls back to getMyTodoList when empty. Run supabase start and supabase db reset, insert rows for two users with psql and show search_todos returning only the caller's matches, run npm run lint and npm run build in nextjs, load the table page in the browser against the local stack and search, and paste the SQL output, build output and a screenshot in the pull request description. Document the function in README.md. Do not change any policy or the Expo app.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request with one new file under supabase/migrations, the regenerated nextjs/src/lib/types.ts with search_todos under Functions, the new method in unified.ts, the search input in table/page.tsx, and a README paragraph. The description shows the db reset output applying the five migrations, the psql session where search_todos returns the test user's matching row and nothing for the other user, the Next.js build output, and a screenshot of the table page with results.
The repository has no workflow, so the local stack run in the sandbox is the check: the migration applied cleanly on Postgres 15 with the seed, and the function answered under row level security. The agent pushes one commit for the migration and types and one for the client and page.
A reviewer checks that the function is security invoker and not security definer, that search_path is pinned, that the generated column is stored so the GIN index can use it, and that the existing policy was not widened. Then they run supabase db push on their project and watch the column backfill on existing rows.
Run it on every new searchable table
A team that adds tables to the same Supabase project over time starts one run per table with POST /o/{org}/sessions, this prompt adjusted to name the table and its text columns, and the repository in resources. Each run reads the table's own policy and the client methods that touch it, so a table shared with the Expo app gets a function both clients can call, and each run ends in its own pull request.
The key's webhook_url receives run.completed for each run it starts, with a session_url for the result, so a script can post the migration file names and pull request links to the team channel.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
Search that touches row level security is the kind of change that looks right in a diff and leaks in production. In a Rush sandbox the agent brings up the real Supabase stack, applies the migrations in order, runs the function as two different users through psql and loads the page in a browser; every command, query result and screenshot stays in the run's transcript, so the pull request shows the policy holding rather than asserting it.
The migration is the only schema change, it is additive, and it was applied on the same Postgres major version config.toml declares before a reviewer opens the pull request. The same request works on every table the team wants searchable, each run in its own sandbox at the same time.
Frequently asked questions
Does the search respect row level security?
Yes. search_todos is security invoker, so it runs with the caller's role and claims, and the Owner can do everything policy on todo_list, including its is_user_authenticated() MFA check, filters the rows inside the function. The agent proves it by calling the function as two users in psql.
Why a generated column instead of a trigger?
A stored generated column is kept current by Postgres on every insert and update with no trigger to maintain, and the GIN index on it is what makes the query fast. Postgres 15, which config.toml pins, supports it; the one cost is a backfill when the migration runs on an existing table.
Will the Expo app break?
No. The column and function are additive, the Expo app's reads of todo_list select existing columns, and its inserts name their fields, so the generated column is never written. It can call search_todos through the same rpc when the team wants search there too.
Does the generated types file change by hand?
No. The agent runs supabase gen types typescript --local against the stack it started, so nextjs/src/lib/types.ts is regenerated exactly as the project's own instructions produce it, and the new Functions entry types the rpc call.