The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: enums in other schemas (#18653)
Alaister Young9def73b26913
diff --git a/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsx b/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsxindex 79e3ec4be99..cc446dc5bfd 100644--- a/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsx+++ b/studio/components/interfaces/Database/EnumeratedTypes/CreateEnumeratedTypeSidePanel.tsx@@ -32,11 +32,13 @@ import EnumeratedTypeValueRow from './EnumeratedTypeValueRow'interface CreateEnumeratedTypeSidePanelProps {visible: booleanonClose: () => void+ schema: string}const CreateEnumeratedTypeSidePanel = ({visible,onClose,+ schema,}: CreateEnumeratedTypeSidePanelProps) => {const submitRef = useRef<HTMLButtonElement>(null)const { project } = useProjectContext()@@ -80,6 +82,7 @@ const CreateEnumeratedTypeSidePanel = ({createEnumeratedType({projectRef: project.ref,connectionString: project.connectionString,+ schema,name: data.name,description: data.description?.replaceAll("'", "''"),values: data.values.filter((x) => x.value.length > 0).map((x) => x.value),diff --git a/studio/components/interfaces/Database/EnumeratedTypes/EditEnumeratedTypeSidePanel.tsx b/studio/components/interfaces/Database/EnumeratedTypes/EditEnumeratedTypeSidePanel.tsxindex 81f517b1465..b9d6e352d70 100644--- a/studio/components/interfaces/Database/EnumeratedTypes/EditEnumeratedTypeSidePanel.tsx+++ b/studio/components/interfaces/Database/EnumeratedTypes/EditEnumeratedTypeSidePanel.tsx@@ -44,8 +44,8 @@ const EditEnumeratedTypeSidePanel = ({const submitRef = useRef<HTMLButtonElement>(null)const { project } = useProjectContext()const { mutate: updateEnumeratedType, isLoading: isCreating } = useEnumeratedTypeUpdateMutation({- onSuccess: () => {- toast.success(`Successfully updated type "${name}"`)+ onSuccess: (_, vars) => {+ toast.success(`Successfully updated type "${vars.name.updated}"`)onClose()},})@@ -97,10 +97,12 @@ const EditEnumeratedTypeSidePanel = ({return console.error('selectedEnumeratedType required')const payload: {+ schema: stringname: { original: string; updated: string }values: { original: string; updated: string; isNew: boolean }[]description?: string} = {+ schema: selectedEnumeratedType.schema,name: { original: selectedEnumeratedType.name, updated: data.name },values: data.values.filter((x) => x.updatedValue.length !== 0)diff --git a/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.tsx b/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.tsxindex cfee5a7bdd0..9d72cc5c0a3 100644--- a/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.tsx+++ b/studio/components/interfaces/Database/EnumeratedTypes/EnumeratedTypes.tsx@@ -78,9 +78,11 @@ const EnumeratedTypes = () => {icon={<IconSearch size={14} />}/></div>- <Button type="primary" onClick={() => setShowCreateTypePanel(true)}>- Create type- </Button>+ {!isLocked && (+ <Button type="primary" onClick={() => setShowCreateTypePanel(true)}>+ Create type+ </Button>+ )}</div>{isLocked && <ProtectedSchemaWarning schema={selectedSchema} entity="enumerated types" />}@@ -173,6 +175,7 @@ const EnumeratedTypes = () => {<CreateEnumeratedTypeSidePanelvisible={showCreateTypePanel}onClose={() => setShowCreateTypePanel(false)}+ schema={selectedSchema}/><EditEnumeratedTypeSidePaneldiff --git a/studio/data/enumerated-types/enumerated-type-create-mutation.ts b/studio/data/enumerated-types/enumerated-type-create-mutation.tsindex 73b9da1be3c..29e53e4c136 100644--- a/studio/data/enumerated-types/enumerated-type-create-mutation.ts+++ b/studio/data/enumerated-types/enumerated-type-create-mutation.ts@@ -9,6 +9,7 @@ import { wrapWithTransaction } from 'data/sql/utils/transaction'export type EnumeratedTypeCreateVariables = {projectRef: stringconnectionString: string+ schema: stringname: stringdescription?: stringvalues: string[]@@ -17,13 +18,16 @@ export type EnumeratedTypeCreateVariables = {export async function createEnumeratedType({projectRef,connectionString,+ schema,name,description,values,}: EnumeratedTypeCreateVariables) {- const createSql = `create type "${name}" as enum (${values.map((x) => `'${x}'`).join(', ')});`+ const createSql = `create type "${schema}"."${name}" as enum (${values+ .map((x) => `'${x}'`)+ .join(', ')});`const commentSql =- description !== undefined ? `comment on type "${name}" is '${description}';` : ''+ description !== undefined ? `comment on type "${schema}"."${name}" is '${description}';` : ''const sql = wrapWithTransaction(`${createSql} ${commentSql}`)const { result } = await executeSql({ projectRef, connectionString, sql })return resultdiff --git a/studio/data/enumerated-types/enumerated-type-update-mutation.ts b/studio/data/enumerated-types/enumerated-type-update-mutation.tsindex e97b4b74ffc..6048694212d 100644--- a/studio/data/enumerated-types/enumerated-type-update-mutation.ts+++ b/studio/data/enumerated-types/enumerated-type-update-mutation.ts@@ -9,6 +9,7 @@ import { wrapWithTransaction } from 'data/sql/utils/transaction'export type EnumeratedTypeUpdateVariables = {projectRef: stringconnectionString: string+ schema: stringname: { original: string; updated: string }description?: stringvalues?: { original: string; updated: string; isNew: boolean }[]@@ -17,13 +18,14 @@ export type EnumeratedTypeUpdateVariables = {export async function updateEnumeratedType({projectRef,connectionString,+ schema,name,description,values = [],}: EnumeratedTypeUpdateVariables) {const statements: string[] = []if (name.original !== name.updated) {- statements.push(`alter type "${name.original}" rename to "${name.updated}";`)+ statements.push(`alter type "${schema}"."${name.original}" rename to "${name.updated}";`)}if (values.length > 0) {values.forEach((x, idx) => {@@ -32,24 +34,24 @@ export async function updateEnumeratedType({// Consider if any new enums were added before any existing enumsconst firstExistingEnumValue = values.find((x) => !x.isNew)statements.push(- `alter type "${name.updated}" add value '${x.updated}' before '${firstExistingEnumValue?.original}';`+ `alter type "${schema}"."${name.updated}" add value '${x.updated}' before '${firstExistingEnumValue?.original}';`)} else {statements.push(- `alter type "${name.updated}" add value '${x.updated}' after '${+ `alter type "${schema}"."${name.updated}" add value '${x.updated}' after '${values[idx - 1].updated}';`)}} else if (x.original !== x.updated) {statements.push(- `alter type "${name.updated}" rename value '${x.original}' to '${x.updated}';`+ `alter type "${schema}"."${name.updated}" rename value '${x.original}' to '${x.updated}';`)}})}if (description !== undefined) {- statements.push(`comment on type "${name.updated}" is '${description}';`)+ statements.push(`comment on type "${schema}"."${name.updated}" is '${description}';`)}const sql = wrapWithTransaction(statements.join(' '))