mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 02:15:05 +03:00
## Context Migrates the remaining API requests to the pg-meta endpoint to use the query endpoint directly with the SQL from the pg-meta package. This touches the following: - policies - publications - triggers - views - materialized views - types ## To test Just need to verify that we're still fetching the data correctly on these pages - Database policies - Database publications - Database triggers - Database tables (views + materialized views) - Database types <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved and stabilized loading of database metadata (views, triggers, RLS policies, publications, materialized views, and enum types), including more reliable schema-scoped filtering. * Updated policy loading behavior and related UI queries to consistently use schema arrays, improving cache correctness and consistency. * **Tests** * Updated end-to-end test synchronization to wait for the correct metadata responses using more specific request identifiers. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { tool } from 'ai'
|
|
import { z } from 'zod'
|
|
|
|
import { getDatabasePolicies } from '@/data/database-policies/database-policies-query'
|
|
|
|
export const getSchemaTools = ({
|
|
projectRef,
|
|
connectionString,
|
|
}: {
|
|
projectRef: string
|
|
connectionString: string
|
|
}) => ({
|
|
list_policies: tool({
|
|
description: 'Get existing RLS policies for a given schema',
|
|
inputSchema: z.object({
|
|
schemas: z.array(z.string()).describe('The schema names to get the policies for'),
|
|
}),
|
|
execute: async ({ schemas }) => {
|
|
const data = await getDatabasePolicies(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
schemas,
|
|
},
|
|
undefined
|
|
)
|
|
|
|
const formattedPolicies = data
|
|
.map(
|
|
(policy) => `
|
|
Policy Name: "${policy.name}"
|
|
Action: ${policy.action}
|
|
Roles: ${policy.roles.join(', ')}
|
|
Command: ${policy.command}
|
|
Definition: ${policy.definition}
|
|
${policy.check ? `Check: ${policy.check}` : ''}
|
|
`
|
|
)
|
|
.join('\n')
|
|
|
|
return formattedPolicies
|
|
},
|
|
}),
|
|
})
|