mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## 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
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { getPolicyEditorRoute, matchesPolicySearch } from './DatabaseEntitySearch.utils'
|
|
|
|
describe('matchesPolicySearch', () => {
|
|
const policy = { name: 'Authors can edit', schema: 'public', table: 'blog_posts' }
|
|
|
|
it.each([
|
|
['the policy name', 'AUTHORS'],
|
|
['the table name', 'blog_p'],
|
|
['a schema-qualified table', 'pub.blog_posts'],
|
|
])('matches on %s', (_, query) => {
|
|
expect(matchesPolicySearch(policy, query)).toBe(true)
|
|
})
|
|
|
|
it('does not match unrelated searches', () => {
|
|
expect(matchesPolicySearch(policy, 'colors')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('getPolicyEditorRoute', () => {
|
|
it('sets the schema so the policy is listed on the policies page', () => {
|
|
expect(getPolicyEditorRoute('abc', { id: 7, schema: 'public' })).toBe(
|
|
'/project/abc/database/policies?schema=public&edit=7'
|
|
)
|
|
})
|
|
|
|
it('encodes schema names', () => {
|
|
expect(getPolicyEditorRoute('abc', { id: 7, schema: 'my schema&x' })).toBe(
|
|
'/project/abc/database/policies?schema=my%20schema%26x&edit=7'
|
|
)
|
|
})
|
|
})
|