## Context
Related to FE-2557
Part of shifting manually written dashboard queries into
packages/pg-meta where
- pg-meta can be code owners of
- we can write tests for the queries
This PR just shifts all the `.sql.ts` files that we previously created
into packages/pg-meta
There's still other areas where we need to shift over as well which I'll
address in subsequent PRs
## Notable changes
- `getTableRowsCountSql` -> Opted to shift `formatFilterValue` logic out
before calling this method (ref `table-rows-count-query`)
- `getDeleteOldCronJobRunDetailsByCtidSql` -> Opted to shift
`validatePageNumber` logic out before calling this method (ref
`CronJobsTab.useCleanupActions`)
## Context
Related to Dashboard Scalability, specifically having Postgres team as
CODEOWNERS for dashboard queries
This is just a clean up as we're currently piling manual queries into
one folder under `data/sql/queries`, whereas I reckon it'll be better
for each query to sit within their RQ folder for better context.
Am opting the naming format for files housing queries to be `*.sql.ts`,
and also updating CODEOWNERS to reflect as such
Next step will also be to shift all the dashboard queries within pg-meta
into studio itself as requested by the pg-meta team
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Consolidated and reorganized internal module structure for the data
layer to improve maintainability and reduce redundancy.
* Streamlined import paths across components to align with new
consolidated module organization.
* **Chores**
* Updated code ownership patterns to reflect reorganized file structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Ali Waseem <waseema393@gmail.com>
## Context
The Integrations -> Cron overview page renders a list of cron jobs by
doing a join on both `cron.jobs` and `cron.job_run_details` in order to
pull the data for "Latest run" and "Status" ("Next run" is just derived
from "Latest Run" and the job's schedule)
In the past, we've had users run into issues where this query would time
out, likely due to the join on `job_run_details` especially if that
table is really big (and the columns on that table aren't indexed), and
our solution was to inform users to clear out that table + schedule a
job to clean the `job_run_details` table on a certain cadence. This CTA
however blocks the UI from rendering the cron jobs overview entirely
<img width="1644" height="590" alt="image"
src="https://github.com/user-attachments/assets/1a0458e9-f686-452b-88bc-44459bc7c615"
/>
## Changes involved
Am opting to use the new preflight check introduced
[here](https://github.com/supabase/supabase/pulls?q=is%3Apr+author%3Ajoshenlim+is%3Aclosed)
- Attempt to fetch the data for the cron jobs overview normally
- If preflight check rejects (due to high cost), then opt to fetch the
data while omitting the join
- Show a banner instead to inform the user accordingly
- So that way users can still view their cron jobs (the latest run
column is a nice to have convenience really)
<img width="1151" height="379" alt="image"
src="https://github.com/user-attachments/assets/72cfaafb-e951-4601-b54e-c36a6f36332d"
/>
- Clicking learn more will then open a dialog to explain what this is
all about
- The steps to clear the `job_run_details` table + schedule a clean up
job still remains
<img width="450" height="484" alt="image"
src="https://github.com/user-attachments/assets/4491e766-64a1-40c9-9703-2e8b0da11c3f"
/>
<img width="450" height="610" alt="Screenshot 2026-02-05 at 12 56 39"
src="https://github.com/user-attachments/assets/644c9a7b-5afb-46bb-8c1e-9ece3986c2fb"
/>
<img width="450" height="507" alt="Screenshot 2026-02-05 at 13 01 37"
src="https://github.com/user-attachments/assets/9f0f40f2-7376-4c28-90f1-0b21a1a4560a"
/>
- Non-UI related changes include
- Automatically refresh cron jobs after scheduling a job, remove manual
CTA to refresh the jobs after scheduling the clean up job
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Previous Runs tab on cron job pages
* Interactive "Learn more" cleanup dialog with guided delete and
schedule steps
* Close-confirmation modal when editing cron jobs
* High-cost banner that enables a lightweight "minimal" list mode
* **Bug Fixes**
* Clearer placeholder (minus icon/message) when a job has no runs
* **Performance**
* Safer, more efficient fetching and pagination for large cron job
lists; reduced retries on high-cost queries
* **Tests**
* Expanded end-to-end tests covering high-cost flows and the cleanup
dialog
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
* fix(studio): check job_run_details size in cron display
When cron.job_run_details grows too large (200k+ rows), loading the
cron jobs overview can timeout and affect other queries by pulling
excessive data into shared buffers.
This change:
- Estimates table size using pg_stat before fetching cron jobs data
- Shows a cleanup notice when the table exceeds the threshold
- Provides batched deletion using ctid ranges to avoid buffer pollution
- Allows scheduling an automated daily cleanup cron job
- Handles timeout errors gracefully with a "suspected overflow" state
The useCronJobsData hook now returns a discriminated union status that
tracks loading, estimate-error, overflow-confirmed, overflow-suspected,
and ready states, allowing the UI to respond appropriately to each case.
* fix(studio): use index when querying cron.job_run_details
cron.job_run_details is only indexed by runid, not by start_time. Change
the query to use the runid index (which gives the same result, since
runid is auto-incrementing).
* Bump the deps, refactor deprecated code.
* Migrate keepPreviousData usage.
* Migrate all uses of InfiniteQuery.
* Fix refetchInterval in queries.
* Migrate all use of isLoading to isPending in mutations.
* Fix accessing location in claim-project.
* Fix a bug in duplicate query keys.
* Migrate all queries to use isPending.
* Revert "Fix accessing location in claim-project."
This reverts commit 2a07df64b5.
* Revert the rss.xml file to master.
* Add custom types for queries, mutations and infinite queries.
* Migrate all queries to use the new type.
* Migrate all infinite queries to useCustomInfiniteQueryOptions.
* Migrate all mutations to use useCustomMutationOptions.
* Add type to all imports in `types` folder.
* Migrate all uses of invalidateQueries to use object syntax.
* Migrate the remainder of useInfiniteQuery.
* Migrate all setQueriesData.
* Migrate all fetchQuery uses.
* Migrate some leftover functions from RQ.
* Fix issues found by Charis.
The cron jobs details detail will throw a client side exception while
cron jobs are in running status. This is because the types that we've
defined for cron job details expect both return_message and end_time to
be strings, but they will be null until the cron job is finished.
Fixed the types and added some defensive checks to fix the bug.
Also made some minor tweaks to the table. Figured that end time and
duration can also be shown for failed jobs, doesn't only have to be
succeeded ones.
* integrations refine
* refactoring
* integration page updates
* div
* clean up
* prettier
* Couple of minor refactors and fixes
* Fix missing base path for integration card image
* Fix editing a cron job in the previous job run tab, not updating the cron job details in the page header
* Cron job bread crumb to use job name instead of id if available, and add loading state for cron job subtitle
* Fixy fix
* Small fi
* ANother one
* Do not reroute after purging queue
* nit
* Final final final v3
---------
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
* Fix query to fetch cron jobs resulting in duplicate if job previous run succeeded, but latest failed
* Fix integration tabs child label
* Add a key to the rows in the data grid.
* Fix the small loading state when clicking the create cron job button.
* Wrap try catch around getDatabaseCronJob when validating cron job name
---------
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
* Use DataGrid for cron jobs interface instead of cards
* Deprecate CronJobCard and database-cron-jobs-run-query.ts
* Add tooltip for editing unnamed job
* Implement infinite scrolling to cron jobs + server side searching
* Deprecate database-cron-jobs-query, and add a singular database-cron-job-query
* Add hover card for cron job table cell command
* Fix the CronJob type because its name is optional.
* The Job previous runs page should be identified by job id, not job name because it can be undefined. Fix the tabs to show the job name by using additional query param.
* Add a tooltip explaining that cron jobs without names can't be edited.
* The parser for cron jobs should handle URLS with query params or hashes.
* Remove the .only description from the tests.
* Show Unknown for cron jobs which have "" as name.
* Fix a crash when a cron job has "1 second" (singular) as schedule.
* Calculate the next run properly when the schedule is "1 second".
* Show a simplified confirm modal when deleting a cron job without a name.
* Add copy action to cron job card command
* Fix
* Remove unused code
* Refactor the cron job parsing. Expanded some of the existing tests. Added more tests.
* The last run data can be undefined if the cron was just created. The data for caching in RQ can't be undefined so it's forced to null.
* Test whether the edge function points to its own project. If not, parse it as a HTTP request.
* Use toStrictEqual instead of toMatchObject for more correct tests.
* Add min height to the codeblock, the copy button was obscured if the code was a one-liner.
* Add snippet to all types of cron jobs. Automatically update it when the form changes.
* Minor fixes.
---------
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
* Redo cron ui to use a data table
* Add component for form header
* Add next run column
* add cron jobs page
* Load jobs from url, add runs footer, link to logs
* Type issue
* Fix height of tab area
* Use nuqs with history
* improve pgcron logs, add severity filters
* Check for v1.5 to see if seconds are supported
* fix cron jobs logs table name
* Add type to the table
* Move expression warning to own function
* Fit to new layout
* Types
* Fix long code blocks
* Revert some of the changes.
* Use job name as a tab name. Other minor fixes.
* Use Infinite query for the cron runs.
* Revert some extra changes. Will be added to another PR.
* Rename pg functions
---------
Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Jordi Enric <jordi.err@gmail.com>
* 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>