The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Hook up TCE
Joshen Lim6d23225aeb70
diff --git a/studio/components/interfaces/Settings/Vault/Keys/EncryptionKeySelector.tsx b/studio/components/interfaces/Settings/Vault/Keys/EncryptionKeySelector.tsxindex e46894cce50..64aeac9c118 100644--- a/studio/components/interfaces/Settings/Vault/Keys/EncryptionKeySelector.tsx+++ b/studio/components/interfaces/Settings/Vault/Keys/EncryptionKeySelector.tsx@@ -8,6 +8,7 @@ interface Props {label?: stringlabelOptional?: stringselectedKeyId?: any+ error?: stringonSelectKey: (keyId: string) => voidonUpdateDescription?: (desc: string) => void}@@ -18,6 +19,7 @@ const EncryptionKeySelector: FC<Props> = ({label = 'Encryption key',labelOptional,selectedKeyId,+ error,onSelectKey = () => {},onUpdateDescription = () => {},}) => {@@ -64,6 +66,7 @@ const EncryptionKeySelector: FC<Props> = ({<Inputid={nameId}label="Name"+ error={error}onChange={(event) => onUpdateDescription(event.target.value)}/>)}diff --git a/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsx b/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsxindex ff74b6513bf..f43299a8672 100644--- a/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsx+++ b/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsx@@ -26,6 +26,8 @@ const AddNewSecretModal: FC<Props> = ({ visible, onClose }) => {const errors: any = {}if (values.name.length === 0) errors.name = 'Please provide a name for your secret'if (values.secret.length === 0) errors.secret = 'Please enter your secret value'+ if (selectedKeyId === 'create-new' && values.keyName.length === 0)+ errors.keyName = 'Please provide a name for your new key'return errors}@@ -34,7 +36,7 @@ const AddNewSecretModal: FC<Props> = ({ visible, onClose }) => {let encryptionKeyId = selectedKeyIdif (values.keyId === 'create-new') {- const addKeyRes = await vault.addKey(values.keyDescription || undefined)+ const addKeyRes = await vault.addKey(values.keyName || undefined)if (addKeyRes.error) {return ui.setNotification({error: addKeyRes.error,@@ -81,7 +83,7 @@ const AddNewSecretModal: FC<Props> = ({ visible, onClose }) => {><Formid="add-new-secret-form"- initialValues={{ name: '', description: '', secret: '', keyId: '', keyDescription: '' }}+ initialValues={{ name: '', description: '', secret: '', keyId: '', keyName: '' }}validate={validate}validateOnBlur={false}onSubmit={onAddNewSecret}@@ -114,7 +116,7 @@ const AddNewSecretModal: FC<Props> = ({ visible, onClose }) => {<div className="py-4 space-y-4"><EncryptionKeySelectorid="keyId"- nameId="keyDescription"+ nameId="keyName"label="Select a key to encrypt your secret with"labelOptional="Optional"selectedKeyId={selectedKeyId}diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsxindex 03a98f82c48..7326d4816d2 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx@@ -40,7 +40,12 @@ interface Props {payload: CreateColumnPayload | UpdateColumnPayload,foreignKey: Partial<PostgresRelationship> | undefined,isNewRecord: boolean,- configuration: { columnId: string | undefined },+ configuration: {+ columnId: string | undefined+ isEncrypted: boolean+ keyId?: string+ keyName?: string+ },resolve: any) => voidupdateEditorDirty: () => void@@ -64,7 +69,7 @@ const ColumnEditor: FC<Props> = ({(type: PostgresType) => !meta.excludedSchemas.includes(type.schema))const keys = vault.listKeys()- const defaultKey = keys.find((key) => key.status === 'default')+ const defaultKey = keys.find((key) => key.name === 'default_vault_key') || keys[0]const [errors, setErrors] = useState<Dictionary<any>>({})const [columnFields, setColumnFields] = useState<ColumnField>()@@ -139,7 +144,7 @@ const ColumnEditor: FC<Props> = ({columnId: column?.id,isEncrypted: columnFields.isEncrypted,keyId: columnFields.keyId,- keyDescription: columnFields.keyDescription,+ keyName: columnFields.keyName,}// [Joshen TODO], we'll need to update the callback here to@@ -324,9 +329,10 @@ const ColumnEditor: FC<Props> = ({{columnFields.isEncrypted && (<EncryptionKeySelectorlabel="Select a key to encrypt your column with"+ error={errors?.keyName}selectedKeyId={columnFields.keyId}onSelectKey={(id) => onUpdateField({ keyId: id })}- onUpdateDescription={(desc) => onUpdateField({ keyDescription: desc })}+ onUpdateDescription={(name) => onUpdateField({ keyName: name })}/>)}</FormSectionContent>diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.tsindex be7e62bafd3..c3e33805929 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.utils.ts@@ -165,6 +165,9 @@ export const validateFields = (field: ColumnField) => {if (field.format.length === 0) {errors['format'] = `Please select a type for your column`}+ if (field.keyId === 'create-new' && (field?.keyName ?? '').length === 0) {+ errors['keyName'] = 'Please provide a name for your new key'+ }return errors}diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxindex 5a4fc21a283..b5b3bdd782e 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx@@ -122,17 +122,19 @@ const SidePanelEditor: FC<Props> = ({payload: CreateColumnPayload | UpdateColumnPayload,foreignKey: Partial<PostgresRelationship> | undefined,isNewRecord: boolean,- configuration: { columnId?: string },+ configuration: { columnId?: string; isEncrypted: boolean; keyId?: string; keyName?: string },resolve: any) => {+ const { columnId, ...securityConfig } = configurationconst response = isNewRecord? await meta.createColumn(payload as CreateColumnPayload,selectedTable as PostgresTable,- foreignKey+ foreignKey,+ securityConfig): await meta.updateColumn(- configuration.columnId as string,+ columnId as string,payload as UpdateColumnPayload,selectedTable as PostgresTable,foreignKeydiff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.tsindex 64fa197810a..3fc105799d3 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.types.ts@@ -70,9 +70,9 @@ export interface ColumnField {isPrimaryKey: booleanisNewColumn: boolean- isEncrypted?: boolean+ isEncrypted: booleankeyId?: string- keyDescription?: string+ keyName?: string}export interface PostgresDataTypeOption {diff --git a/studio/stores/pgmeta/MetaStore.ts b/studio/stores/pgmeta/MetaStore.tsindex 7829d7a7d77..05f9e61dec8 100644--- a/studio/stores/pgmeta/MetaStore.ts+++ b/studio/stores/pgmeta/MetaStore.ts@@ -1,6 +1,6 @@import Papa from 'papaparse'import { makeObservable, observable } from 'mobx'-import { find, isUndefined, isEqual, isEmpty, chunk } from 'lodash'+import { find, isUndefined, isEqual, isEmpty, chunk, values } from 'lodash'import { Query } from 'components/grid/query/Query'import {@@ -87,7 +87,8 @@ export interface IMetaStore {createColumn: (payload: CreateColumnPayload,selectedTable: PostgresTable,- foreignKey?: Partial<PostgresRelationship>+ foreignKey?: Partial<PostgresRelationship>,+ securityConfiguration?: { isEncrypted: boolean; keyId?: string; keyName?: string }) => anyupdateColumn: (id: string,@@ -347,8 +348,13 @@ export default class MetaStore implements IMetaStore {async createColumn(payload: CreateColumnPayload,selectedTable: PostgresTable,- foreignKey?: Partial<PostgresRelationship>+ foreignKey?: Partial<PostgresRelationship>,+ securityConfiguration?: { isEncrypted: boolean; keyId?: string; keyName?: string }) {+ const toastId = this.rootStore.ui.setNotification({+ category: 'loading',+ message: `Creating column "${payload.name}"...`,+ })try {// Once pg-meta supports composite keys, we can remove this logicconst { isPrimaryKey, ...formattedPayload } = payload@@ -358,6 +364,11 @@ export default class MetaStore implements IMetaStore {// Firing createColumn in createTable will bypass this blockif (isPrimaryKey) {+ this.rootStore.ui.setNotification({+ id: toastId,+ category: 'loading',+ message: 'Assigning primary key to column...',+ })// Same logic in createTable: Remove any primary key constraints first (we'll add it back later)// @ts-ignoreconst existingPrimaryKeys = selectedTable.primary_keys.map((x) => x.name)@@ -373,10 +384,45 @@ export default class MetaStore implements IMetaStore {}if (!isUndefined(foreignKey)) {+ this.rootStore.ui.setNotification({+ id: toastId,+ category: 'loading',+ message: 'Adding foreign key to column...',+ })const relation: any = await this.addForeignKey(foreignKey)if (relation.error) throw relation.error}++ const { isEncrypted, keyId, keyName } = securityConfiguration || {}+ if (isEncrypted) {+ this.rootStore.ui.setNotification({+ id: toastId,+ category: 'loading',+ message: 'Encrypting column...',+ })+ let encryptionKey = keyId+ if (keyId === 'create-new') {+ const addKeyRes = await this.rootStore.vault.addKey(keyName)+ if (addKeyRes.error) throw addKeyRes.error+ else encryptionKey = addKeyRes[0].id+ }+ const query = `security label for pgsodium on column "${column.table}"."${column.name}" is 'ENCRYPT WITH KEY ID ${encryptionKey}';`+ const encryptColumnRes = await this.rootStore.meta.query(query)+ if (encryptColumnRes.error) throw encryptColumnRes.error+ }+ this.rootStore.ui.setNotification({+ id: toastId,+ category: 'success',+ message: `Successfully created column ${column.name}`,+ })} catch (error: any) {+ this.rootStore.ui.setNotification({+ id: toastId,+ category: 'error',+ message: `An error occured while creating the column "${payload.name}"`,+ })+ const query = `alter table "${selectedTable.name}" drop column if exists "${payload.name}";`+ await this.rootStore.meta.query(query)return { error }}}