Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

adds rq invalidations after updating tables

Alaister Youngaf818f9558b8
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
index 6dac7be0af3..9b002df95d9 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
@@ -6,6 +6,7 @@ import { Modal } from 'ui'
import type { PostgresTable, PostgresColumn } from '@supabase/postgres-meta'
import { useStore } from 'hooks'
+import { entityTypeKeys } from 'data/entity-types/keys'
import { useTableRowCreateMutation } from 'data/table-rows/table-row-create-mutation'
import { useTableRowUpdateMutation } from 'data/table-rows/table-row-update-mutation'
import { RowEditor, ColumnEditor, TableEditor } from '.'
@@ -297,21 +298,27 @@ const SidePanelEditor = ({
try {
if (isDuplicating) {
const duplicateTable = find(tables, { id: tableId }) as PostgresTable
+
toastId = ui.setNotification({
category: 'loading',
message: `Duplicating table: ${duplicateTable.name}...`,
})
+
const table: any = await meta.duplicateTable(payload, {
isRLSEnabled,
isRealtimeEnabled,
isDuplicateRows,
duplicateTable,
})
+
+ await queryClient.invalidateQueries(entityTypeKeys.list(project?.ref))
+
ui.setNotification({
id: toastId,
category: 'success',
message: `Table ${duplicateTable.name} has been successfully duplicated into ${table.name}!`,
})
+
onTableCreated(table)
} else if (isNewRecord) {
toastId = ui.setNotification({
@@ -327,17 +334,22 @@ const SidePanelEditor = ({
isRealtimeEnabled,
importContent
)
+
+ await queryClient.invalidateQueries(entityTypeKeys.list(project?.ref))
+
ui.setNotification({
id: toastId,
category: 'success',
message: `Table ${table.name} is good to go!`,
})
+
onTableCreated(table)
} else if (selectedTableToEdit) {
toastId = ui.setNotification({
category: 'loading',
message: `Updating table: ${selectedTableToEdit?.name}...`,
})
+
const { table, hasError }: any = await meta.updateTable(
toastId,
selectedTableToEdit,
@@ -345,6 +357,7 @@ const SidePanelEditor = ({
columns,
isRealtimeEnabled
)
+
if (hasError) {
ui.setNotification({
id: toastId,
@@ -352,6 +365,8 @@ const SidePanelEditor = ({
message: `Table ${table.name} has been updated, but there were some errors`,
})
} else {
+ await queryClient.invalidateQueries(entityTypeKeys.list(project?.ref))
+
ui.setNotification({
id: toastId,
category: 'success',
@@ -359,6 +374,7 @@ const SidePanelEditor = ({
})
}
}
+
queryClient.invalidateQueries(sqlKeys.query(project?.ref, ['foreign-key-constraints']))
} catch (error: any) {
saveTableError = true
diff --git a/studio/data/entity-types/keys.ts b/studio/data/entity-types/keys.ts
index 7444a19f161..affef0d559c 100644
--- a/studio/data/entity-types/keys.ts
+++ b/studio/data/entity-types/keys.ts
@@ -1,4 +1,4 @@
export const entityTypeKeys = {
- list: (projectRef: string | undefined, search: string | undefined) =>
- ['projects', projectRef, 'entity-types', { search }] as const,
+ list: (projectRef: string | undefined, search?: string) =>
+ ['projects', projectRef, 'entity-types', ...(search ? [{ search }] : [])] as const,
}
diff --git a/studio/pages/project/[ref]/editor/[id].tsx b/studio/pages/project/[ref]/editor/[id].tsx
index cf7756ecb7a..9fd9ca0e2dc 100644
--- a/studio/pages/project/[ref]/editor/[id].tsx
+++ b/studio/pages/project/[ref]/editor/[id].tsx
@@ -1,3 +1,4 @@
+import { useQueryClient } from '@tanstack/react-query'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
@@ -7,6 +8,7 @@ import { Alert, Button, Checkbox, IconExternalLink, Modal } from 'ui'
import type { PostgresTable, PostgresColumn } from '@supabase/postgres-meta'
import { useStore, withAuth, useUrlState, useParams } from 'hooks'
+import { entityTypeKeys } from 'data/entity-types/keys'
import { Entity } from 'data/entity-types/entity-type-query'
import { Dictionary } from 'components/grid'
import { TableEditorLayout } from 'components/layouts'
@@ -22,6 +24,8 @@ const TableEditorPage: NextPageWithLayout = () => {
const { id, ref: projectRef } = useParams()
const [_, setParams] = useUrlState({ arrayKeys: ['filter', 'sort'] })
+ const queryClient = useQueryClient()
+
const { meta, ui } = useStore()
const [selectedSchema, setSelectedSchema] = useState<string>()
@@ -202,6 +206,8 @@ const TableEditorPage: NextPageWithLayout = () => {
const tables = meta.tables.list((table: PostgresTable) => table.schema === selectedSchema)
+ await queryClient.invalidateQueries(entityTypeKeys.list(projectRef))
+
// For simplicity for now, we just open the first table within the same schema
if (tables.length > 0) {
router.push(`/project/${projectRef}/editor/${tables[0].id}`)