9 Commits
Author SHA1 Message Date
Joshen Lim f87de2f0d0 Joshenlim/fe 4593 cmd k related resources while in table editor (#53079)
## Context

Building on towards resource-aware Cmd K, the changes done up so far
have all been to allow users to search for database resources from
anywhere in the project, with the intention to get you to the resource
quickly without having to go through the navigation hierarchy of the
dashboard.

This PR explores a way to quickly glance related resources for a table
in the Table Editor through Cmd K for that same intention, but listing
out the policies, triggers or functions that run on the table that
you're currently viewing in the Table Editor. E.g here we've got the
`blog_authors` table opened:
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/78c9b85f-cd30-4564-a264-c1a2a596d5c2"
/>

Policies and triggers are fairly straight forward since we can determine
what's related by their target table. Functions are a bit more fuzzy as
we're trying to find what's related by checking the function definition,
if it does anything to the table. For e.g based on the screenshot above,
`blog_handle_new_user` has this definition which was why it was flagged
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/fb8f3be4-05df-4d87-8440-8b75d95546ae"
/>

We're also deliberately decoupling loading of policies + triggers and
functions since searching functions takes slightly longer, so opting to
load results of policies + triggers first, then lazy load functions
subsequently once results are ready

 ## Performance

As usual, ran a benchmarking session with Claude just to make sure that
the added SQL doesn't cause any performance issues, these are aggregates
of 4–5 runs.

**Catalog size (stress catalog)**

| Query | 2,000 tables | 10,000 tables |
|---|---|---|
| Policies and triggers, hub table (many FKs) | 0.1 ms | 0.5–1.3 ms |
| Policies and triggers, ordinary table | ~0 ms | ~0 ms |
| Functions, every body matches | 1.4 ms | 4–8 ms |
| Functions, no match (full scan) | 1.8 ms | 7.3–7.7 ms |
| Functions, table not visible | 0 ms | 0 ms |

**Large function bodies** (random text, 2,000 tables plus 2,000 small
functions, plus the large ones added)

| Function source | Largest function | Functions: no match (full scan) |
Functions: every body matches |
|---|---|---|---|
| 56 MB (600 functions) | 94 KB | ~50 ms | 2 ms |
| 103 MB (+10 multi-MB) | 4.7 MB | ~92 ms | 2 ms |

## To test

Use a project with a table that has at least one policy, one trigger,
and a function that mentions the table in its body.

- [ ] Open that table in the Table Editor and press Cmd+K. A **Related
resources** section appears at the top with its policies, triggers, and
functions.
- [ ] Click a policy, a trigger, and a function. Each opens its editor
on the right resource.
- [ ] A trigger's function does not also appear under the functions
rows.
- [ ] Type part of one of those names. The section narrows to matching
rows and the project-wide entity results appear below. A resource can
appear in both.
- [ ] Type something that matches nothing in the table. The section
disappears rather than showing empty.
- [ ] Clear the input. The full section comes back without a loading
flicker, since the data is cached.
- [ ] Open the table editor on a table with no policies, triggers, or
referencing functions. Cmd+K shows no empty **Related resources**
section.
- [ ] Switch to a different table and press Cmd+K. The section shows
that table's resources, not the previous table's.
- [ ] Open Cmd+K from a non-Table Editor page, such as the SQL Editor.
The section is not shown.
- [ ] In the network tab, check that opening the menu sends one query
for policies and triggers and one for functions. Typing sends no
additional ones for this section.
2026-11-10 10:46:41 +08:00
Joshen Lim 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
2026-11-06 17:04:39 +08:00
Joshen Lim 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
2026-11-05 13:02:44 +08:00
Joshen Lim 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
2026-11-04 14:26:37 +08:00
Joshen Lim 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
2026-10-23 23:24:56 +08:00
Ali Waseem 3ed436de74 feat: new shortcuts hook with registrations (#44954)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

- Brand new hook APIs for registering shortcuts using tanstack hotkeys
- Support for command menu injection when shortcut is added

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Centralized keyboard shortcuts system with per‑shortcut registration
and per‑user enable/disable preferences stored locally
  * Added a "Copy results as Markdown" shortcut (Mod+Shift+M)
* Shortcuts can be surfaced in the Command Menu with a visual shortcut
badge for discoverability

* **Documentation**
* Legacy keyboard shortcut hooks marked as deprecated and documentation
updated to point to the new shortcut API
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-17 08:20:36 -06:00
Joshen Lim 31a804f6d4 Add integrations to command k (#35550) 2025-05-09 10:55:03 +08:00
23973eb5c3 feat: cmdk sections preview (#34633)
* cmdk sections preview

* useRegisterCommands refactor

* Update apps/studio/components/interfaces/App/CommandMenu/CommandMenu.utils.ts

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* Update apps/studio/components/layouts/DatabaseLayout/Database.Commands.tsx

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* Update apps/studio/components/layouts/DatabaseLayout/Database.Commands.tsx

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

---------

Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
2025-04-15 12:49:33 +00:00
Charis 84732ff44c feat: add new command menu to studio (#28432)
Add new command menu to studio. Ports over commands from old menu (with some minor reorganization), then adds:
- Branch switcher
- Project switcher
2024-08-08 16:42:07 -04:00