The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add validation when creating enumerated types to ensure that name doesnt conflict with a native PG data type (#22120)
Joshen Lim8925d1f72eb8
diff --git a/apps/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsx b/apps/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsxindex 05dcf9740e0..a52ea05ad7a 100644--- a/apps/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsx+++ b/apps/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsx@@ -28,6 +28,7 @@ import * as z from 'zod'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import { useEnumeratedTypeCreateMutation } from 'data/enumerated-types/enumerated-type-create-mutation'import EnumeratedTypeValueRow from './EnumeratedTypeValueRow'+import { NATIVE_POSTGRES_TYPES } from './EnumeratedTypes.constants'interface CreateEnumeratedTypeSidePanelProps {visible: boolean@@ -51,7 +52,13 @@ const CreateEnumeratedTypeSidePanel = ({})const FormSchema = z.object({- name: z.string().min(1, 'Please provide a name for your enumerated type').default(''),+ name: z+ .string()+ .min(1, 'Please provide a name for your enumerated type')+ .refine((value) => !NATIVE_POSTGRES_TYPES.includes(value), {+ message: 'Name cannot be a native Postgres data type',+ })+ .default(''),description: z.string().default('').optional(),values: z.object({ value: z.string().min(1, 'Please provide a value') })diff --git a/apps/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.constants.ts b/apps/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.constants.tsnew file mode 100644index 00000000000..766bd65b186--- /dev/null+++ b/apps/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.constants.ts@@ -0,0 +1,64 @@+// [Joshen] Just FYI I do think that we should merge this with whats in SidePanelEditor.constants.ts+// Such that dashboard can work with _all_ native Postgres data types as listed here+// https://supabase.com/docs/guides/database/tables#data-types+// But for now, just make sure users cannot created enum types that share the same name as a native type++import {+ DATE_TYPES,+ JSON_TYPES,+ NUMERICAL_TYPES,+ OTHER_DATA_TYPES,+ TEXT_TYPES,+ TIMESTAMP_TYPES,+ TIME_TYPES,+} from 'components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants'++export const NATIVE_POSTGRES_TYPES = [+ ...NUMERICAL_TYPES,+ ...TEXT_TYPES,+ ...JSON_TYPES,+ ...TIMESTAMP_TYPES,+ ...TIME_TYPES,+ ...DATE_TYPES,+ ...OTHER_DATA_TYPES,+ 'bigint',+ 'bigserial',+ 'bit',+ 'bit varying',+ 'boolean',+ 'box',+ 'bytea',+ 'char',+ 'character',+ 'character varying',+ 'cidr',+ 'circle',+ 'date',+ 'double precision',+ 'inet',+ 'int',+ 'integer',+ 'interval',+ 'line',+ 'lseg',+ 'macaddr',+ 'macaddr8',+ 'money',+ 'numeric',+ 'decimal',+ 'path',+ 'pg_lsn',+ 'pg_snapshot',+ 'point',+ 'polygon',+ 'real',+ 'smallint',+ 'smallserial',+ 'serial',+ 'time with timezone',+ 'timestamp with timezone',+ 'tsquery',+ 'tsvector',+ 'txid_snapshot',+ 'xml',+]diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants.tsindex a57859a09a9..971c016b150 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants.ts+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants.ts@@ -18,7 +18,7 @@ export const DATE_TYPES = ['date']export const TIME_TYPES = ['time', 'timetz']export const DATETIME_TYPES = concat(TIMESTAMP_TYPES, DATE_TYPES, TIME_TYPES)-const OTHER_DATA_TYPES = ['uuid', 'bool', 'vector']+export const OTHER_DATA_TYPES = ['uuid', 'bool', 'vector']export const POSTGRES_DATA_TYPES = sortBy(concat(NUMERICAL_TYPES, JSON_TYPES, TEXT_TYPES, DATETIME_TYPES, OTHER_DATA_TYPES))