mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
* Add crons option in the database menu. * Add react-hook-form to the studio package.json. * Refactor the functionSelector to be used by other features. * Add the bulk of the functionality for the cron UI. Some of the code is copy-pasted from functions feature, needs to be cleaned before merging. * Tons of changes, the Create Cron sheet works now. * Added some more functionality for the cronjob feature. * Convert the Cron table to a listing with cards. * Add click-to-copy in the Auth Hooks feature. * Remove extra prop. * Fix type errors. * Fix some random issues. Fix the tests. * Fix the tests. * Add a style for disabled radio button item. * Make the default SQL snippet. Handle the case pg_net is not installed. * Fix the heading and save button when creating a new cron job. * Change the name of the custom label in the schedule dropdown. * Minor fixes. * Rename all mentions of cronjobs to cron jobs. * Always show the cron jobs link. * Rename the link from crons to cron-jobs. * Fix the disabled state for the stacked radio group. * More minor fixes. * More small fixes. * Fix the tests. * Minor UI tweaks * More minor tweaks * Add padding bottom * Add feature flag for the cron ui. * Fix the SQL function option. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import { ResponseError } from 'types'
|
|
import { databaseCronJobsKeys } from './keys'
|
|
|
|
export type DatabaseCronJobsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string
|
|
}
|
|
|
|
export type CronJob = {
|
|
jobid: number
|
|
schedule: string
|
|
command: string
|
|
nodename: string
|
|
nodeport: number
|
|
database: string
|
|
username: string
|
|
active: boolean
|
|
jobname: string
|
|
}
|
|
|
|
const cronJobSqlQuery = `select * from cron.job order by jobid;`
|
|
|
|
export async function getDatabaseCronJobs({
|
|
projectRef,
|
|
connectionString,
|
|
}: DatabaseCronJobsVariables) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { result } = await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql: cronJobSqlQuery,
|
|
})
|
|
return result
|
|
}
|
|
|
|
export type DatabaseCronJobData = CronJob[]
|
|
export type DatabaseCronJobError = ResponseError
|
|
|
|
export const useCronJobsQuery = <TData = DatabaseCronJobData>(
|
|
{ projectRef, connectionString }: DatabaseCronJobsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<DatabaseCronJobData, DatabaseCronJobError, TData> = {}
|
|
) =>
|
|
useQuery<DatabaseCronJobData, DatabaseCronJobError, TData>(
|
|
databaseCronJobsKeys.list(projectRef),
|
|
() => getDatabaseCronJobs({ projectRef, connectionString }),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|