mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
docs/reference-template
9
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
53ffdf75c9 |
Joshenlim/fe 4945 cmd k support searching for all table (#53262)
## Context Probably the final piece for this series of changes towards resource aware Cmd K. We currently only present results for tables when searching in Cmd K, this PR adds in other entity types like views, materialized views, foreign tables, and partitioned tables (only the parent) Note that the results excludes entities created from database extensions to reduce the chance of noise <img width="500" alt="image" src="https://github.com/user-attachments/assets/27bf5026-937a-4883-b365-75694d551a39" /> ## Related changes - Tweaked the entity icon for partitioned tables a little to be blue (previously gray) and - Added an entity icon for child partition tables in the table editor that's slightly lighter than the partition table icon, currently child partition tables just render with the same icon as tables which can be confusing <img width="286" height="128" alt="image" src="https://github.com/user-attachments/assets/638af7c3-512d-4264-bfae-0a8827b3ef94" /> - Note that i'm planning to look into this separately RE how to better render child partition tables so this might go away subsequently ## Performance As always, ran a claude benchmarking session - this runs on debounced keystrokes against a live catalog, so it's benchmarked at scale: **45,653 `pg_class` rows** - 12k tables - 3,143 views - 3,002 matviews - 3,001 foreign tables) Taking a median of 15 runs, all variants measured against the same catalog in one process. | scenario | query | master | this PR | worst | |---|---|---|---|---| | exact table name | `t_500` | 19.5ms | 24.3ms | 29.1ms | | view name | `v_10` | 19.3ms | 23.7ms | 25.8ms | | foreign table name | `ft_10` | 18.9ms | 24.1ms | 26.9ms | | no match | `zzz_nothing` | 19.4ms | 24.0ms | 27.5ms | | broad prefix (~3k matches) | `t_1` | 30.8ms | 38.7ms | 45.1ms | | broad matview prefix | `mv_1` | 26.6ms | 37.5ms | 41.7ms | |
||
|
|
c0e92057a6 |
feat(studio): split SQL errors into user and Studio SQL (#53059)
Part of FE-4772. ## Why Errors from the pg-meta query endpoint didn't say who wrote the SQL, so a Sentry issue like SUPABASE-APP-KXE couldn't tell a user's query from one Studio composed. That event came from the assistant's `execute_sql` tool and was captured by the Vercel AI integration on the server, so it skipped `reportStudioError` and had no fault tags. The Postgres message also went to Sentry as-is, and it can contain user SQL and data. ## What - **`sqlOrigin` is required on `executeSql`.** `'user'` covers SQL the user or an AI agent wrote, in whole or in part: SQL editor, editor panel, Explorer, AI `execute_sql` and `run_notebook`, report blocks, Query Insights EXPLAIN, the policy, function, and cron editors, and running a stored cron job. Everything else is `'studio'`. The policy, function, and cron mutation hooks and `useDbQuery` take `sqlOrigin` too. - **`classifySqlResponseError`** turns a 400 from the query endpoint into `UserSqlError` (`user`, `user_sql`) or `StudioSqlError` (`studio`, `studio_sql`). Pattern rules (connection timeouts) and other statuses keep their classes. - **`UserSqlError` never reaches Sentry.** Its routing is `SAMPLE_NEVER`, `alwaysCapture` doesn't override it, and `beforeSend` drops it. - **`StudioSqlError` is redacted.** Error classes can set `sentryMessage`; for `StudioSqlError` it is the SQLSTATE and the query's `queryName`, a static name that `executeSql` requires for Studio SQL. The query key is never reported, since its segments can hold IDs, schemas, and search terms. `applyStudioErrorPolicy` applies it from `beforeSend` on the client and the server, so it holds however the error was captured. The server config gets a `beforeSend` for this. Events get `query_name` and `sql_state` tags and are grouped by both, since every SQL error shares the `executeSql` stack. - **A custom `handleError` gets the classified error**, matching its declared type. The SQL editor, editor panel, and policy editor rethrow it, so their errors are now `UserSqlError` instead of being reported as `UnexpectedError`. The error keeps Postgres's `position` for the editor's line highlight. The error message, `formattedError`, and `position` stay on the error for the UI. The query-performance Sentry context no longer carries the raw error message, which bypassed redaction. ## Known gaps - Index advisor queries run users' query text from `pg_stat_statements` but are marked `'studio'`. Redaction keeps the text out of Sentry, but their failures count as Studio faults. - 5xx responses for user SQL are still `PlatformError` and keep their message. - The self-hosted MCP `executeSql` calls `executeQuery` directly and isn't covered. ## Testing - Unit tests for `classifySqlResponseError`, `applyStudioErrorPolicy`, and the client `beforeSend`. - Full Studio vitest suite passes except `useReportDateRange.test.ts` (169 vs 168 hourly buckets across the DST change), which this PR doesn't touch. |
||
|
|
06d43f6881 |
Joshenlim/fe 4721 cmd k support searching for triggers (#52755)
## Context Building off from [here](https://github.com/supabase/supabase/pull/52751) to make Cmd+K resource-aware so finding and inspecting anything in a project doesn't depend on knowing where it lives in the dashboard. Specifically looking into database entities for now - end state would be that you could search for a table name for example, and Cmd K will pull up everything related to that table for you to skim (e.g Policies, Functions, Triggers, etc). Changes in this PR sets up searching for **database triggers**, and will probably be the last database entity that we'll add into context aware cmd K for now given that we'll have tables, policies, functions and triggers which are the primary building blocks for a project. <img width="500" alt="image" src="https://github.com/user-attachments/assets/242ec517-88cd-4f3d-96ce-741edaa8560d" /> Triggers will also match if it's function matches the search input, and its description will tweak slightly as well <img width="500" alt="image" src="https://github.com/user-attachments/assets/65f515df-b875-4b92-95b7-00389d8a070b" /> ## Performance Had Claude do some benchmarking against `getSearchEntitiesSql` (`EXPLAIN ANALYZE`, median of 5 runs, local Postgres, warm cache) on one synthetic catalog: - 12,000 tables (36,651 `pg_class`), 6,001 policies, 27,261 `pg_proc` (12,000 user + 12,000 extension-owned functions), 56,304 `pg_trigger` - 3,500 user triggers, 500 of which run one shared function; the rest are internal FK triggers - 297,921 `pg_depend`. Compared against master (tables + policies) and the functions PR (before triggers). | Search | What it exercises | master | functions PR | this PR | Δ this PR | |---|---|---|---|---|---| | `t_1` | broad table match | 12ms | 26ms | 30ms | +4ms | | `p_1` | broad policy-name match | 15ms | 27ms | 35ms | +8ms | | `fn_1` | broad function match | 10ms | 26ms | 33ms | +7ms | | `trg_1` | broad trigger-name match | 9ms | 23ms | 32ms | +9ms | | `trg_` | every user trigger matches by name | 10ms | 25ms | 40ms | +15ms | | `audit_row_fn` | function match; its 500 triggers match only through the function | 9ms | 24ms | 31ms | +7ms | | `ri_constraint` | only internal FK triggers match | 9ms | 24ms | 30ms | +6ms | | `stress.fn_1` | schema-qualified | 12ms | 33ms | 40ms | +7ms | | `zzz` | no match | 9ms | 22ms | 27ms | +5ms | - Triggers add +4 to +15ms over the functions PR. The worst case is a search matching every user trigger, at 40ms in total. - Matching triggers through their function shares the single `pg_trigger` pass the name search already does, with no extra scan. A separate pass measured about 30ms more on every search. ## To test - [ ] Search a table name: Tables first, then policies, and functions, and triggers - [ ] Search a trigger name: it appears under triggers and opens the editor panel in database/triggers - [ ] Search a function name: trigger results should appear if the trigger uses that function - [ ] Trigger outside public: schema filter switches and the trigger opens |
||
|
|
5152899fac |
Joshenlim/fe 4720 cmd k support searching for functions (#52751)
## Context Building off from [here](https://github.com/supabase/supabase/pull/52678) to make Cmd+K resource-aware so finding and inspecting anything in a project doesn't depend on knowing where it lives in the dashboard. Specifically looking into database entities for now - end state would be that you could search for a table name for example, and Cmd K will pull up everything related to that table for you to skim (e.g Policies, Functions, Triggers, etc). Changes in this PR sets up searching for **database functions**. <img width="607" height="531" alt="image" src="https://github.com/user-attachments/assets/b4a2cd15-9874-4e80-80d4-d343d8c70fc3" /> ## Performance Ran a Claude session to benchmark `getSearchEntitiesSql` against the version on master (tables and policies only), on the same synthetic catalog: - 12,000 tables (36,651 `pg_class`), 6,001 policies, 27,258 `pg_proc` (12,000 user + 12,000 extension-owned functions), 290,915 `pg_depend`. - Median of 5 runs, `EXPLAIN ANALYZE`, local Postgres (warm cache). | Search | Matches | master | this PR | |---|---|---|---| | `t_1` | ~1/9 of tables | 12ms | 23ms | | `p_1` | broad policy-name match | 13ms | 25ms | | `fn_1` | user + extension functions | 8ms | 23ms | | `fn_` | every function | 8ms | 29ms | | `stress.fn_1` | schema-qualified | 10ms | 30ms | | `zzz` | nothing | 9ms | 22ms | - Adding functions costs +11 to +21ms at this scale - Most of it is fixed (+13ms even for a query that matches nothing): one pass over `pg_proc`, plus building the set of extension-owned functions. It doesn't grow with the number of matches. ## To test - [ ] Search a table name: Tables first, then policies, and functions - [ ] Search a function name: it appears under Functions and opens the editor panel in database/functions - [ ] Function outside public: schema filter switches and the function opens |
||
|
|
2b55f7db9a |
Joshenlim/fe 4719 cmd k support searching for policies (#52678)
## Context Continue to build off from [here](https://github.com/supabase/supabase/pull/52205) to make Cmd+K resource-aware so finding and inspecting anything in a project doesn't depend on knowing where it lives in the dashboard. Specifically looking into database entities for now - end state would be that you could search for a table name for example, and Cmd K will pull up everything related to that table for you to skim (e.g Policies, Functions, Triggers, etc). Changes in this PR sets up searching for RLS policies. <img width="609" height="525" alt="image" src="https://github.com/user-attachments/assets/212a430a-314d-48c4-a27c-2f9bb06e8457" /> Policies are matched on, in priority, its name and the target table. ## Performance checking Just ran a check with Claude just to make sure that the added SQL doesn't cause any performance degradation on the database. Plan guard passes at 12,000 tables, under its 500ms budget. Also benchmarked locally with a 3-character query matching every policy, results look good so should be alright: | Catalog | Worst-case search | No-match baseline | |---|---|---| | 36k policies | ~52–64ms | ~16ms | | 120k policies | ~118–134ms | ~63ms | ## To test - [x] Search a table name: Tables first, then its policies, under Policies - [x] Search a policy name: it appears under Policies and opens the editor panel in database/policies - [x] Policy outside `public`: schema filter switches and the policy opens |
||
|
|
df742bdb3b |
refactor(studio): rename ResponseError to StudioError (#52707)
## What
Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.
## Why
Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.
## Notes for reviewers
- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
|
||
|
|
5d8499b6f1 |
chore(eslint): allowlist grant and connectionString in query exhaustive-deps (#52334)
## Problem `@tanstack/query/exhaustive-deps` flags every variable used in a `queryFn` that isn't in the `queryKey`. Some variables are intentionally left out because they don't change the returned data, and keeping them out of the key avoids splitting the cache: * **`connectionString`** in queries that run SQL against the user's database. These currently need `eslint-disable` comments or count against the ratchet. * **`grant`**, the FGA grants that Studio data hooks now take (see #52331). Every migrated query would otherwise need a disable comment. The installed plugin (5.91.2) has no way to configure this. ## Solution * Upgrade `@tanstack/eslint-plugin-query` from `^5.0.0` (resolving 5.91.2) to `^5.104.5`. The rule's `allowlist` option arrived in 5.95.0. 5.105.0 is newer than our pnpm minimum release age allows. * Allowlist `grant` and `connectionString` for `exhaustive-deps` in `eslint-config-supabase/next.js`. * Remove the 11 disable comments in Studio that only suppressed `connectionString`. * Six disable comments stay, because they suppress other dependencies: * `ReportBlock.tsx` * `UserJourneys.queries.ts` * `github-config-query.ts` * `bucket-objects-infinite-query.ts` * `table-rows-query.ts` * `useSingleLog.tsx` * Lower Studio's `@tanstack/query/exhaustive-deps` baseline from 87 to 28. The upgraded rule is stricter than 5.91.2: without the allowlist it adds about 18 warnings. With the allowlist, the total drops well below the old baseline, because many existing warnings were unsuppressed `connectionString` omissions. The lockfile changes are the plugin and its `@typescript-eslint` dependencies. The graphiql entries are re-keyed by pnpm's peer resolution; their versions are unchanged. ## Testing * `pnpm --filter studio run lint:ratchet` passes. * ESLint is clean on each file where a disable comment was removed. * Other apps' ratchets only track `shadcn/*` rules, so they're unaffected. |
||
|
|
ac1fa9f1b6 |
fix(studio): add missing grant to entity search query (#52302)
## Problem Typecheck and the `DatabaseEntitySearchCommands.test.tsx` unit tests fail on master. `executeSql` in `entity-search-query.ts` does not pass the now-required `grant`. ## Solution Pass `grant: unguarded.migrating`, matching the other `data/database` queries. |
||
|
|
7d63d764fc |
Joshenlim/fe 4712 cmd k support searching for database tables (#52205)
## Context Looking into some kaizen improvements for Cmd+K, with the overarching idea to make Cmd+K resource-aware so finding and inspecting anything in a project doesn't depend on knowing where it lives in the dashboard. Specifically looking into database entities for now - end state would be that you could search for a table name for example, and Cmd K will pull up everything *related* to that table for you to skim (e.g Policies, Functions, Triggers, etc). Changes in this PR sets the foundation here by starting with just the tables. <img width="500" alt="image" src="https://github.com/user-attachments/assets/65054781-2385-416c-aed9-f142380e4454" /> This might be similar to how we currently support searching for database entities via these "Queries" section, but these only search within the context of the entity category, not across (e.g only tables, only policies) <img width="500" alt="image" src="https://github.com/user-attachments/assets/66ca16c6-9551-4134-b1e1-0b0c4b004085" /> The idea isn't to replace this, but provide another way to find your database entities so that - You can see related entities to what you're searching at a glance - You don't need to go to a 2nd level nav in Cmd K Also fwiw the bulk of the LOC changes in here are mainly tests actually, actual LOC changes are +385, -22 |