mirror of
https://github.com/supabase/supabase.git
synced 2026-07-01 04:47:16 -04:00
097f220c5c
## Context Dashboard currently doesn't have any support for managing stored procedures. In the event that the security advisor surfaces a warning about a stored procedure, users hence run into a dead-end as there's currently no way to self-remediate via the dashboard ## Changes involved We're hence adding support for managing stored procedures within Database Functions <img width="1082" height="546" alt="image" src="https://github.com/user-attachments/assets/2598a5fe-e58f-4e8a-ad2f-9cb6d0eb2f53" /> Creating a function now shows a dropdown to select the type <img width="500" alt="image" src="https://github.com/user-attachments/assets/acc9249d-7b25-4416-aae8-89c630e1c62b" /> In which if stored procedure is selected, the following fields will be hidden since they're irrelevant for stored procedures - Return type - Behaviour (Under advanced settings) Some other minor UI changes as well: - Field inputs are re-ordered a little, opting to group "Schema" and "Name" into one section, followed by "Type" and "Return type" - Opting to show "Return type" when editing a function but disabled - Add schema filter for fetching database functions to reduce unnecessary load on the database ## To test - [ ] Can create, update, delete, read stored procedures via database functions page <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary - **New Features** - Added PostgreSQL **procedure** support alongside functions, including a **Type** selector in the create/edit flow. - Updated Functions UI with a new **Type** column and procedure-aware return/argument details. - **Improvements** - Refreshed create/edit headers and language help text for clearer context. - Improved argument parsing/display, including better handling of procedure argument modes. - **Bug Fixes** - Corrected routine-type handling during function/procedure delete and update SQL operations. - **Tests** - Updated unit snapshots and end-to-end UI flows/labels for the new “New function” control. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
74 lines
3.6 KiB
TypeScript
74 lines
3.6 KiB
TypeScript
import { sqlKeys } from '@/data/sql/keys'
|
|
|
|
export const databaseKeys = {
|
|
schemas: (projectRef: string | undefined) => ['projects', projectRef, 'schemas'] as const,
|
|
keywords: (projectRef: string | undefined) => ['projects', projectRef, 'keywords'] as const,
|
|
migrations: (projectRef: string | undefined) => ['projects', projectRef, 'migrations'] as const,
|
|
tableColumns: (
|
|
projectRef: string | undefined,
|
|
schema: string | undefined,
|
|
table: string | undefined
|
|
) => ['projects', projectRef, 'table-columns', schema, table] as const,
|
|
databaseFunctions: (projectRef: string | undefined, schema?: string) =>
|
|
['projects', projectRef, 'database-functions', schema].filter(Boolean),
|
|
entityDefinition: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'entity-definition', id] as const,
|
|
entityDefinitions: (projectRef: string | undefined, schemas: string[]) =>
|
|
['projects', projectRef, 'entity-definitions', schemas] as const,
|
|
tableDefinition: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'table-definition', id] as const,
|
|
viewDefinition: (projectRef: string | undefined, id?: number, includeCreateStatement?: boolean) =>
|
|
['projects', projectRef, 'view-definition', id, includeCreateStatement ?? false] as const,
|
|
backups: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database', 'backups'] as const,
|
|
poolingConfiguration: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database', 'pooling-configuration'] as const,
|
|
indexesFromQuery: (projectRef: string | undefined, query: string) =>
|
|
['projects', projectRef, 'indexes', { query }] as const,
|
|
indexAdvisorFromQuery: (
|
|
projectRef: string | undefined,
|
|
query: string,
|
|
connectionString?: string
|
|
) => {
|
|
// Use only the host (no credentials) as a safe cache discriminator
|
|
let connectionFingerprint: string | undefined
|
|
if (connectionString) {
|
|
try {
|
|
connectionFingerprint = new URL(connectionString).host
|
|
} catch {
|
|
connectionFingerprint = undefined
|
|
}
|
|
}
|
|
return ['projects', projectRef, 'index-advisor', { query, connectionFingerprint }] as const
|
|
},
|
|
tableConstraints: (projectRef: string | undefined, id?: number) =>
|
|
['projects', projectRef, 'table-constraints', id] as const,
|
|
foreignKeyConstraints: (projectRef: string | undefined, schema?: string, options = {}) =>
|
|
['projects', projectRef, 'foreign-key-constraints', schema, options] as const,
|
|
databaseSize: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'database-size'] as const,
|
|
maxConnections: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'max-connections'] as const,
|
|
pgbouncerStatus: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'pgbouncer', 'status'] as const,
|
|
pgbouncerConfig: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'pgbouncer', 'config'] as const,
|
|
checkPrimaryKeysExists: (
|
|
projectRef: string | undefined,
|
|
tables: { name: string; schema: string }[]
|
|
) => ['projects', projectRef, 'check-primary-keys', tables] as const,
|
|
tableIndexAdvisor: (
|
|
projectRef: string | undefined,
|
|
schema: string | undefined,
|
|
table: string | undefined
|
|
) => ['projects', projectRef, 'table-index-advisor', schema, table] as const,
|
|
supamonitorEnabled: (projectRef: string | undefined) =>
|
|
['projects', projectRef, 'supamonitor-enabled'] as const,
|
|
}
|
|
|
|
export const getLiveTupleEstimateKey = (
|
|
projectRef: string | undefined,
|
|
table: string,
|
|
schema = 'public'
|
|
) => sqlKeys.query(projectRef, ['live-tuple-estimate', schema, table])
|