The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Remove duplicated types-query, use enumerated-types-query instead (#21632)
Joshen Lim0ddd1b4711ff
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsxindex 100cee3dee3..98872c0c5b1 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnDefaultValue.tsx@@ -1,7 +1,7 @@-import type { PostgresType } from '@supabase/postgres-meta'import { noop } from 'lodash'import { Select } from 'ui'+import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'import { POSTGRES_DATA_TYPES } from '../SidePanelEditor.constants'import { ColumnField } from '../SidePanelEditor.types'import { typeExpressionSuggestions } from './ColumnEditor.constants'@@ -10,7 +10,7 @@ import InputWithSuggestions from './InputWithSuggestions'interface ColumnDefaultValueProps {columnFields: ColumnField- enumTypes: PostgresType[]+ enumTypes: EnumeratedType[]onUpdateField: (changes: Partial<ColumnField>) => void}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsxindex 0d63b7684fb..5a432887f5b 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx@@ -20,8 +20,13 @@ import {import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'+import {+ CONSTRAINT_TYPE,+ Constraint,+ useTableConstraintsQuery,+} from 'data/database/constraints-query'import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'-import { usePostgresTypesQuery } from 'data/database/types-query'+import { useEnumeratedTypesQuery } from 'data/enumerated-types/enumerated-types-query'import { EXCLUDED_SCHEMAS_WITHOUT_EXTENSIONS } from 'lib/constants/schemas'import { Dictionary } from 'types'import ActionBar from '../ActionBar'@@ -40,11 +45,6 @@ import {import ColumnForeignKey from './ColumnForeignKey'import ColumnType from './ColumnType'import HeaderTitle from './HeaderTitle'-import {- CONSTRAINT_TYPE,- Constraint,- useTableConstraintsQuery,-} from 'data/database/constraints-query'export interface ColumnEditorProps {column?: PostgresColumn@@ -78,7 +78,7 @@ const ColumnEditor = ({const [columnFields, setColumnFields] = useState<ColumnField>()const [fkRelations, setFkRelations] = useState<ForeignKey[]>([])- const { data: types } = usePostgresTypesQuery({+ const { data: types } = useEnumeratedTypesQuery({projectRef: project?.ref,connectionString: project?.connectionString,})diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsxindex c3e4607a0bc..bd9443e4be8 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnType.tsx@@ -1,5 +1,4 @@import * as Tooltip from '@radix-ui/react-tooltip'-import type { PostgresType } from '@supabase/postgres-meta'import { noop } from 'lodash'import Link from 'next/link'import { ReactNode } from 'react'@@ -23,10 +22,11 @@ import {} from '../SidePanelEditor.constants'import { PostgresDataTypeOption } from '../SidePanelEditor.types'import { ListPlus } from 'lucide-react'+import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'interface ColumnTypeProps {value: string- enumTypes: PostgresType[]+ enumTypes: EnumeratedType[]size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge'layout?: 'vertical' | 'horizontal'className?: stringdiff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsxindex ccac707e934..b9104a5154e 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx@@ -1,7 +1,7 @@-import type { PostgresType } from '@supabase/postgres-meta'import { noop } from 'lodash'import { Checkbox, IconMenu, IconSettings, IconX, Input, Popover } from 'ui'+import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'import { EMPTY_ARR, EMPTY_OBJ } from 'lib/void'import { typeExpressionSuggestions } from '../ColumnEditor/ColumnEditor.constants'import { Suggestion } from '../ColumnEditor/ColumnEditor.types'@@ -29,7 +29,7 @@ import { ColumnField } from '../SidePanelEditor.types'interface ColumnProps {column: ColumnField- enumTypes: PostgresType[]+ enumTypes: EnumeratedType[]isNewRecord: booleanhasForeignKeys: booleanhasImportContent: boolean@@ -40,7 +40,7 @@ interface ColumnProps {const Column = ({column = EMPTY_OBJ as ColumnField,- enumTypes = EMPTY_ARR as PostgresType[],+ enumTypes = EMPTY_ARR as EnumeratedType[],isNewRecord = false,hasForeignKeys = false,hasImportContent = false,diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsxindex aa3b0193ce6..72decdd4b43 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx@@ -1,5 +1,4 @@import * as Tooltip from '@radix-ui/react-tooltip'-import type { PostgresType } from '@supabase/postgres-meta'import { isEmpty, noop, partition } from 'lodash'import {DragDropContext,@@ -11,6 +10,7 @@ import {import { Alert, Button, IconEdit, IconExternalLink, IconHelpCircle, IconKey, IconTrash } from 'ui'import InformationBox from 'components/ui/InformationBox'+import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'import { generateColumnField } from '../ColumnEditor/ColumnEditor.utils'import { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types'import { TEXT_TYPES } from '../SidePanelEditor.constants'@@ -21,7 +21,7 @@ import { ImportContent } from './TableEditor.types'interface ColumnManagementProps {columns?: ColumnField[]relations: ForeignKey[]- enumTypes: PostgresType[]+ enumTypes: EnumeratedType[]importContent?: ImportContentisNewRecord: booleanonColumnsUpdated: (columns: ColumnField[]) => voiddiff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsxindex d69ee875b54..6298a728cd6 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx@@ -7,11 +7,16 @@ import { Alert, Badge, Button, Checkbox, IconBookOpen, Input, Modal, SidePanel }import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import ConfirmationModal from 'components/ui/ConfirmationModal'import { useDatabasePublicationsQuery } from 'data/database-publications/database-publications-query'+import {+ CONSTRAINT_TYPE,+ Constraint,+ useTableConstraintsQuery,+} from 'data/database/constraints-query'import {ForeignKeyConstraint,useForeignKeyConstraintsQuery,} from 'data/database/foreign-key-constraints-query'-import { usePostgresTypesQuery } from 'data/database/types-query'+import { useEnumeratedTypesQuery } from 'data/enumerated-types/enumerated-types-query'import { useIsFeatureEnabled, useStore } from 'hooks'import { EXCLUDED_SCHEMAS_WITHOUT_EXTENSIONS } from 'lib/constants/schemas'import { useTableEditorStateSnapshot } from 'state/table-editor'@@ -32,11 +37,6 @@ import {generateTableFieldFromPostgresTable,validateFields,} from './TableEditor.utils'-import {- CONSTRAINT_TYPE,- Constraint,- useTableConstraintsQuery,-} from 'data/database/constraints-query'export interface TableEditorProps {table?: PostgresTable@@ -80,7 +80,7 @@ const TableEditor = ({const isNewRecord = isUndefined(table)const realtimeEnabled = useIsFeatureEnabled('realtime:all')- const { data: types } = usePostgresTypesQuery({+ const { data: types } = useEnumeratedTypesQuery({projectRef: project?.ref,connectionString: project?.connectionString,})diff --git a/apps/studio/data/database/keys.ts b/apps/studio/data/database/keys.tsindex 8135460f3f3..dbaccaee8f9 100644--- a/apps/studio/data/database/keys.ts+++ b/apps/studio/data/database/keys.ts@@ -1,6 +1,5 @@export const databaseKeys = {schemaList: (projectRef: string | undefined) => ['projects', projectRef, 'schemas'] as const,- postgresTypes: (projectRef: string | undefined) => ['projects', projectRef, 'types'] as const,backups: (projectRef: string | undefined) => [projectRef, 'database', 'backups'] as const,poolingConfiguration: (projectRef: string | undefined) =>[projectRef, 'database', 'pooling-configuration'] as const,diff --git a/apps/studio/data/database/types-query.ts b/apps/studio/data/database/types-query.tsdeleted file mode 100644index caf65f226d0..00000000000--- a/apps/studio/data/database/types-query.ts+++ /dev/null@@ -1,57 +0,0 @@-import { PostgresType } from '@supabase/postgres-meta'-import { QueryClient, useQuery, UseQueryOptions } from '@tanstack/react-query'--import { get } from 'data/fetchers'-import { ResponseError } from 'types'-import { databaseKeys } from './keys'--export type PostgresTypesVariables = {- projectRef?: string- connectionString?: string-}--export async function getPostgresTypes(- { projectRef, connectionString }: PostgresTypesVariables,- signal?: AbortSignal-) {- if (!projectRef) {- throw new Error('projectRef is required')- }-- let headers = new Headers()- if (connectionString) headers.set('x-connection-encrypted', connectionString)-- const { data, error } = await get('/platform/pg-meta/{ref}/types', {- // @ts-ignore [Joshen] query param is not required- params: {- header: {- 'x-connection-encrypted': connectionString!,- },- path: {- ref: projectRef,- },- },- headers: Object.fromEntries(headers),- signal,- })-- if (error) throw error- return data as PostgresType[]-}--export type PostgresTypesData = Awaited<ReturnType<typeof getPostgresTypes>>-export type PostgresTypesError = ResponseError--export const usePostgresTypesQuery = <TData = PostgresTypesData>(- { projectRef, connectionString }: PostgresTypesVariables,- { enabled = true, ...options }: UseQueryOptions<PostgresTypesData, PostgresTypesError, TData> = {}-) =>- useQuery<PostgresTypesData, PostgresTypesError, TData>(- databaseKeys.postgresTypes(projectRef),- ({ signal }) => getPostgresTypes({ projectRef, connectionString }, signal),- { enabled: enabled && typeof projectRef !== 'undefined', ...options }- )--export function invalidatePostgresTypesQuery(client: QueryClient, projectRef: string | undefined) {- return client.invalidateQueries(databaseKeys.postgresTypes(projectRef))-}diff --git a/apps/studio/data/enumerated-types/enumerated-types-query.ts b/apps/studio/data/enumerated-types/enumerated-types-query.tsindex 1fd4a788746..942ee05ff1a 100644--- a/apps/studio/data/enumerated-types/enumerated-types-query.ts+++ b/apps/studio/data/enumerated-types/enumerated-types-query.ts@@ -1,10 +1,9 @@-import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'-import { useCallback } from 'react'+import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { components } from 'data/api'+import { get, handleError } from 'data/fetchers'import { ResponseError } from 'types'import { enumeratedTypesKeys } from './keys'-import { components } from 'data/api'export type EnumeratedTypesVariables = {projectRef?: string@@ -32,7 +31,7 @@ export async function getEnumeratedTypes(signal,})- if (error) throw error+ if (error) handleError(error)const enumeratedTypes = data.filter((type) => type.enums.length > 0)return enumeratedTypes}