The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Swap CALL to SELECT for database functions in cron jobs (#32927)
Joshen Limd139a8f0edb8
diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx b/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsxindex ec9e3897737..582388d2284 100644--- a/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx@@ -186,7 +186,7 @@ const buildCommand = (values: CronJobType) => {values.timeoutMs)} else if (values.type === 'sql_function') {- command = `CALL ${values.schema}.${values.functionName}()`+ command = `SELECT ${values.schema}.${values.functionName}()`}return command}diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.tsindex 9b996b91bf9..c85514b75d8 100644--- a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts@@ -20,8 +20,8 @@ describe('parseCronJobCommand', () => {})})- it('should return a sql function command when the command is CALL auth.jwt ()', () => {- const command = 'CALL auth.jwt ()'+ it('should return a sql function command when the command is SELECT auth.jwt ()', () => {+ const command = 'SELECT auth.jwt ()'expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({type: 'sql_function',schema: 'auth',@@ -30,6 +30,16 @@ describe('parseCronJobCommand', () => {})})+ it('should return a sql function command when the command is SELECT public.test_fn(1, 2)', () => {+ const command = 'SELECT public.test_fn(1, 2)'+ expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({+ type: 'sql_function',+ schema: 'public',+ functionName: 'test_fn',+ snippet: command,+ })+ })+it('should return a edge function config when the command posts to its own supabase.co project', () => {const command = `select net.http_post( url:='https://random_project_ref.supabase.co/functions/v1/_', headers:=jsonb_build_object(), body:='', timeout_milliseconds:=5000 );`expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsindex 25f0ff6d043..10f77fcd892 100644--- a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts@@ -91,7 +91,7 @@ export const parseCronJobCommand = (originalCommand: string, projectRef: string)edgeFunctionName: url,httpHeaders: headersObjs,httpBody: body,- timeoutMs: +timeout ?? 1000,+ timeoutMs: Number(timeout ?? 1000),snippet: originalCommand,}}@@ -102,15 +102,16 @@ export const parseCronJobCommand = (originalCommand: string, projectRef: string)endpoint: url,httpHeaders: headersObjs,httpBody: body,- timeoutMs: +timeout ?? 1000,+ timeoutMs: Number(timeout ?? 1000),snippet: originalCommand,}}- if (command.toLocaleLowerCase().startsWith('call ')) {+ const regexDBFunction = /select\s+[a-zA-Z-_]*\.?[a-zA-Z-_]*\s*\(.+/g+ if (command.toLocaleLowerCase().match(regexDBFunction)) {const [schemaName, functionName] = command- .replace('CALL ', '')- .replace('()', '')+ .replace('SELECT ', '')+ .replace(/\(.*\)/, '').trim().split('.')