The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Added in even more query templates, added template filtering
TzeYiingb4e0fbbf278b
diff --git a/studio/components/interfaces/Home/ProjectUsage.tsx b/studio/components/interfaces/Home/ProjectUsage.tsxindex f9e510fbb13..7ca67a69d93 100644--- a/studio/components/interfaces/Home/ProjectUsage.tsx+++ b/studio/components/interfaces/Home/ProjectUsage.tsx@@ -64,9 +64,9 @@ const ProjectUsage: FC<Props> = ({ project }) => {if (timestampDigits < 16) {// pad unix timestamp with additional 0 and then forwardconst paddedTimestamp = String(timestamp) + '0'.repeat(16 - timestampDigits)- router.push(`/project/${ref}/settings/logs/rest?te=${paddedTimestamp}&s=${search}`)+ router.push(`/project/${ref}/settings/logs/api?te=${paddedTimestamp}`)} else {- router.push(`/project/${ref}/settings/logs/rest?te=${timestamp}&s=${search}`)+ router.push(`/project/${ref}/settings/logs/api?te=${timestamp}`)}}return (diff --git a/studio/components/interfaces/Settings/Logs/Logs.constants.ts b/studio/components/interfaces/Settings/Logs/Logs.constants.tsindex dd14431a029..db9360e4e80 100644--- a/studio/components/interfaces/Settings/Logs/Logs.constants.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.constants.ts@@ -1,25 +1,63 @@-import { LogTemplate } from '.'+import { LogTemplate, LogType } from '.'export const TEMPLATES: LogTemplate[] = [- { label: 'Recent Errors', mode: 'simple', searchString: '[Ee]rror|\\s[45][0-9][0-9]\\s' },+ {+ label: 'Recent Errors',+ mode: 'simple',+ searchString: '[Ee]rror|\\s[45][0-9][0-9]\\s',+ for: ['api'],+ },+ {+ label: 'Commits',+ mode: 'simple',+ searchString: 'COMMIT',+ for: ['database'],+ },++ {+ label: '10 Minutes Ago',+ mode: 'simple',+ searchString: 'timestamp < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 10 MINUTE)',+ for: ['database', 'api'],+ },{label: 'POST or PATCH',mode: 'custom',searchString:"REGEXP_CONTAINS(event_message, 'POST') OR REGEXP_CONTAINS(event_message, 'PATCH')",+ for: ['api'],},{label: 'Metadata IP',mode: 'custom',- searchString:- `SELECT timestamp, h.x_real_ip+ searchString: `SELECT timestamp, h.x_real_ipFROM edge_logsLEFT JOIN UNNEST(metadata) as m ON TRUELEFT JOIN UNNEST(m.request) AS r ON TRUELEFT JOIN UNNEST(r.headers) AS h ON TRUEWHERE h.x_real_ip IS NOT NULL`,+ for: ['database'],+ },+ {+ label: 'Requests by Country',+ mode: 'custom',+ searchString: `SELECT+ cf.country, count(*) as count+FROM edge_logs+ LEFT JOIN UNNEST(metadata) as m ON TRUE+ LEFT JOIN UNNEST(m.request) AS r ON TRUE+ LEFT JOIN UNNEST(r.cf) AS cf ON TRUE+GROUP BY+ cf.country+ORDER BY+ DESC count+`,+ for: ['api'],},]-export const DEFAULT_QUERY = 'SELECT timestamp, event_message FROM postgres_logs;'+export const LOG_TYPE_LABEL_MAPPING: { [k: LogType]: string } = {+ api: 'API',+ database: 'Database',+}diff --git a/studio/components/interfaces/Settings/Logs/Logs.types.ts b/studio/components/interfaces/Settings/Logs/Logs.types.tsindex f93d5c747fe..01a1dff24f6 100644--- a/studio/components/interfaces/Settings/Logs/Logs.types.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.types.ts@@ -1,7 +1,11 @@interface Metadata {[key: string]: string | number | Object | Object[]}-export type LogSearchCallback = (filters: { query: string; from?: string, fromMicro?: number }) => void+export type LogSearchCallback = (filters: {+ query: string+ from?: string+ fromMicro?: number+}) => voidexport interface LogData {id: stringtimestamp: number@@ -12,6 +16,7 @@ export interface LogData {export interface LogTemplate {label?: stringmode: 'custom' | 'simple'+ for?: LogType[]searchString: string}diff --git a/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts b/studio/components/layouts/SettingsLayout/SettingsMenu.utils.tsindex a1547dfa076..8e8d24baeea 100644--- a/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts+++ b/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts@@ -1,7 +1,9 @@+import { LogType, LOG_TYPE_LABEL_MAPPING } from 'components/interfaces/Settings/Logs'import { ProductMenuGroup } from 'components/ui/ProductMenu/ProductMenu.types'-import { LOG_TYPE_LABEL_MAPPING } from 'lib/constants'export const generateSettingsMenu = (ref: string): ProductMenuGroup[] => {+ const logTypes: LogType[] = ['database', 'api']+return [{title: 'Project settings',@@ -20,15 +22,12 @@ export const generateSettingsMenu = (ref: string): ProductMenuGroup[] => {},{title: 'Logs',- // items: ['database', 'auth', 'realtime', 'rest', 'storage'].map((type: string) => {- items: ['database', 'rest'].map((type: string) => {- return {- name: LOG_TYPE_LABEL_MAPPING[type],- key: `logs-${type}`,- url: `/project/${ref}/settings/logs/${type}`,- items: [],- }- }),+ items: logTypes.map((type: string) => ({+ name: LOG_TYPE_LABEL_MAPPING[type],+ key: `logs-${type}`,+ url: `/project/${ref}/settings/logs/${type}`,+ items: [],+ })),},]}diff --git a/studio/lib/constants/index.ts b/studio/lib/constants/index.tsindex eda02a194b6..d76636cd817 100644--- a/studio/lib/constants/index.ts+++ b/studio/lib/constants/index.ts@@ -88,14 +88,6 @@ export const POLICY_MODAL_VIEWS = {REVIEW: 'REVIEW',}-export const LOG_TYPE_LABEL_MAPPING: { [k: string]: string } = {- rest: 'API',- realtime: 'Realtime',- auth: 'Auth',- storage: 'Storage',- database: 'Database',-}-export const GOTRUE_ERRORS = {UNVERIFIED_GITHUB_USER: 'Error sending confirmation mail',}diff --git a/studio/pages/project/[ref]/settings/logs/[type].tsx b/studio/pages/project/[ref]/settings/logs/[type].tsxindex c7ea980fd04..9d457237e5f 100644--- a/studio/pages/project/[ref]/settings/logs/[type].tsx+++ b/studio/pages/project/[ref]/settings/logs/[type].tsx@@ -15,7 +15,7 @@ import {import { withAuth } from 'hooks'import { get } from 'lib/common/fetch'-import { API_URL, LOG_TYPE_LABEL_MAPPING } from 'lib/constants'+import { API_URL } from 'lib/constants'import { SettingsLayout } from 'components/layouts/'import CodeEditor from 'components/ui/CodeEditor'import {@@ -28,6 +28,8 @@ import {TEMPLATES,LogData,LogSearchCallback,+ LogType,+ LOG_TYPE_LABEL_MAPPING,} from 'components/interfaces/Settings/Logs'import { uuidv4 } from 'lib/helpers'import useSWRInfinite from 'swr/infinite'@@ -64,7 +66,7 @@ export const LogPage: NextPage = () => {timestamp_start: '',timestamp_end: '',})- const title = `Logs - ${LOG_TYPE_LABEL_MAPPING[type as string]}`+ const title = `Logs - ${LOG_TYPE_LABEL_MAPPING[type as LogType]}`const checkIfSelectQuery = (value: string) =>value.toLowerCase().includes('select') ? true : falseconst isSelectQuery = checkIfSelectQuery(editorValue)@@ -246,7 +248,7 @@ export const LogPage: NextPage = () => {isCustomQuery={mode === 'custom'}isLoading={isValidating}newCount={newCount}- templates={TEMPLATES}+ templates={TEMPLATES.filter((template) => template.for?.includes(type as LogType))}onRefresh={handleRefresh}onSearch={handleSearch}defaultSearchValue={params.search_query}