The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
swaps entity type to an enum
Alaister Youngc6fce98c8870
diff --git a/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx b/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsxindex ea487c512ea..0ba39aab31a 100644--- a/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx+++ b/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx@@ -6,6 +6,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'import { checkPermissions, useParams, useStore } from 'hooks'import { Entity } from 'data/entity-types/entity-type-query'+import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'import ProjectLayout from '../ProjectLayout/ProjectLayout'import TableEditorMenu from './TableEditorMenu'import NoPermission from 'components/ui/NoPermission'@@ -71,11 +72,11 @@ const TableEditorLayout = ({function loadTable() {if (entity?.type) {switch (entity.type) {- case 'materialized_view':- case 'view':+ case ENTITY_TYPE.MATERIALIZED_VIEW:+ case ENTITY_TYPE.VIEW:return meta.views.loadById(entity.id)- case 'foreign_table':+ case ENTITY_TYPE.FOREIGN_TABLE:return meta.foreignTables.loadById(entity.id)default:diff --git a/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsxindex 207707de655..088984868c0 100644--- a/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx+++ b/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx@@ -25,6 +25,7 @@ import type { PostgresSchema } from '@supabase/postgres-meta'import { checkPermissions, useStore, useParams } from 'hooks'import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'+import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'import { Entity } from 'data/entity-types/entity-type-query'import { useProjectContext } from '../ProjectLayout/ProjectContext'import InfiniteList from 'components/ui/InfiniteList'@@ -315,55 +316,53 @@ const EntityListItem = ({isActive={isActive}icon={<div className="flex items-center justify-center text-xs h-4 w-4 rounded-[2px] text-scale-1100 bg-scale-800">- {entity.type[0]?.toUpperCase()}+ {Object.entries(ENTITY_TYPE)+ .find(([, value]) => value === entity.type)?.[0]?.[0]+ ?.toUpperCase()}</div>}action={- entity.type === 'table' &&+ entity.type === ENTITY_TYPE.TABLE &&isActive &&!isLocked && (<Dropdownsize="small"side="bottom"align="start"- overlay={- entity.type === 'table'- ? [- <Dropdown.Item- key="edit-table"- icon={<IconEdit size="tiny" />}- onClick={() => onEditTable(entity)}- disabled={isLoadingTableMetadata}- >- Edit Table- </Dropdown.Item>,- <Dropdown.Item- key="duplicate-table"- icon={<IconCopy size="tiny" />}- onClick={() => onDuplicateTable(entity)}- disabled={isLoadingTableMetadata}- >- Duplicate Table- </Dropdown.Item>,- <Link href={`/project/${projectRef}/auth/policies?search=${entity.id}`}>- <a>- <Dropdown.Item key="delete-table" icon={<IconLock size="tiny" />}>- View Policies- </Dropdown.Item>- </a>- </Link>,- <Dropdown.Separator key="separator" />,- <Dropdown.Item- key="delete-table"- icon={<IconTrash size="tiny" />}- onClick={() => onDeleteTable(entity)}- disabled={isLoadingTableMetadata}- >- Delete Table- </Dropdown.Item>,- ]- : null- }+ overlay={[+ <Dropdown.Item+ key="edit-table"+ icon={<IconEdit size="tiny" />}+ onClick={() => onEditTable(entity)}+ disabled={isLoadingTableMetadata}+ >+ Edit Table+ </Dropdown.Item>,+ <Dropdown.Item+ key="duplicate-table"+ icon={<IconCopy size="tiny" />}+ onClick={() => onDuplicateTable(entity)}+ disabled={isLoadingTableMetadata}+ >+ Duplicate Table+ </Dropdown.Item>,+ <Link href={`/project/${projectRef}/auth/policies?search=${entity.id}`}>+ <a>+ <Dropdown.Item key="delete-table" icon={<IconLock size="tiny" />}>+ View Policies+ </Dropdown.Item>+ </a>+ </Link>,+ <Dropdown.Separator key="separator" />,+ <Dropdown.Item+ key="delete-table"+ icon={<IconTrash size="tiny" />}+ onClick={() => onDeleteTable(entity)}+ disabled={isLoadingTableMetadata}+ >+ Delete Table+ </Dropdown.Item>,+ ]}><div className="text-scale-900 transition-colors hover:text-scale-1200"><IconChevronDown size={14} strokeWidth={2} />diff --git a/studio/data/entity-types/entity-type-constants.ts b/studio/data/entity-types/entity-type-constants.tsnew file mode 100644index 00000000000..b3129322766--- /dev/null+++ b/studio/data/entity-types/entity-type-constants.ts@@ -0,0 +1,7 @@+export enum ENTITY_TYPE {+ TABLE = 'r',+ VIEW = 'v',+ MATERIALIZED_VIEW = 'm',+ FOREIGN_TABLE = 'f',+ PARTITIONED_TABLE = 'p',+}diff --git a/studio/data/entity-types/entity-type-query.ts b/studio/data/entity-types/entity-type-query.tsindex d1f3f8696a6..96c2fb624bb 100644--- a/studio/data/entity-types/entity-type-query.ts+++ b/studio/data/entity-types/entity-type-query.ts@@ -1,6 +1,7 @@import { UseQueryOptions } from '@tanstack/react-query'import { useCallback } from 'react'import { ExecuteSqlData, useExecuteSqlPrefetch, useExecuteSqlQuery } from '../sql/execute-sql-query'+import { ENTITY_TYPE } from './entity-type-constants'type EntityTypeArgs = {id?: number@@ -12,13 +13,7 @@ export const entityTypeSqlQuery = ({ id }: EntityTypeArgs) => {c.oid::int8 as "id",nc.nspname as "schema",c.relname as "name",- case c.relkind- when 'r' then 'table'- when 'v' then 'view'- when 'm' then 'materialized_view'- when 'f' then 'foreign_table'- when 'p' then 'partitioned_table'- end as "type",+ c.relkind as "type",obj_description(c.oid) as "comment",count(*) over() as "count"from@@ -46,7 +41,7 @@ export type Entity = {id: numberschema: stringname: string- type: 'table' | 'view' | 'materialized_view' | 'foreign_table' | 'partitioned_table'+ type: ENTITY_TYPEcomment: string | null}diff --git a/studio/data/entity-types/entity-types-infinite-query.ts b/studio/data/entity-types/entity-types-infinite-query.tsindex 1c7b6b1b7be..c696e64444e 100644--- a/studio/data/entity-types/entity-types-infinite-query.ts+++ b/studio/data/entity-types/entity-types-infinite-query.ts@@ -35,13 +35,7 @@ export async function getEntityTypes(c.oid::int8 as "id",nc.nspname as "schema",c.relname as "name",- case c.relkind- when 'r' then 'table'- when 'v' then 'view'- when 'm' then 'materialized_view'- when 'f' then 'foreign_table'- when 'p' then 'partitioned_table'- end as "type",+ c.relkind as "type",obj_description(c.oid) as "comment",count(*) over() as "count"from