The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Always send project id when saving a sql snippet. Row level errors occur if you dont.
Ivan Vasilov9b9009fb0ffe
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsxindex 2f98b98e936..92e9a53a582 100644--- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx+++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx@@ -19,7 +19,6 @@ import {Input_Shadcn_,} from 'ui'-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'import { useSqlEditMutation } from 'data/ai/sql-edit-mutation'import { useSqlGenerateMutation } from 'data/ai/sql-generate-mutation'@@ -87,7 +86,7 @@ const SQLEditor = () => {const router = useRouter()const telemetryProps = useTelemetryProps()const { profile } = useProfile()- const { project } = useProjectContext()+ const project = useSelectedProject()const snap = useSqlEditorStateSnapshot()const { mutateAsync: generateSql, isLoading: isGenerateSqlLoading } = useSqlGenerateMutation()const { mutateAsync: editSql, isLoading: isEditSqlLoading } = useSqlEditMutation()@@ -228,10 +227,15 @@ const SQLEditor = () => {if (!ref) return console.error('Project ref is required')try {- const snippet = createSqlSnippetSkeleton({ name, sql, owner_id: profile?.id })- const data = { ...snippet, id: uuidv4() }- snap.addSnippet(data as SqlSnippet, ref)- router.push(`/project/${ref}/sql/${data.id}`)+ const snippet = createSqlSnippetSkeleton({+ id: uuidv4(),+ name,+ sql,+ owner_id: profile?.id,+ project_id: project?.id,+ })+ snap.addSnippet(snippet as SqlSnippet, ref)+ router.push(`/project/${ref}/sql/${snippet.id}`)} catch (error: any) {ui.setNotification({category: 'error',@@ -239,7 +243,7 @@ const SQLEditor = () => {})}},- [profile, ref, router, snap, ui]+ [profile?.id, project?.id, ref, router, snap, ui])const acceptAiHandler = useCallback(async () => {diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLAI.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLAI.tsxindex 011f50a3605..29733c439fa 100644--- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLAI.tsx+++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLAI.tsx@@ -21,10 +21,10 @@ import { useState } from 'react'import { format } from 'sql-formatter'import { useSqlEditorStateSnapshot } from 'state/sql-editor'import { AiIcon, AiIconAnimation, IconCornerDownLeft, IconSettings, Input } from 'ui'+import AISchemaSuggestionPopover from '../AISchemaSuggestionPopover'import AISettingsModal from '../AISettingsModal'import { sqlAiDisclaimerComment } from '../SQLEditor.constants'import { createSqlSnippetSkeleton } from '../SQLEditor.utils'-import AISchemaSuggestionPopover from '../AISchemaSuggestionPopover'const SQLAI = () => {const { ui } = useStore()@@ -76,10 +76,15 @@ const SQLAI = () => {}try {- const snippet = createSqlSnippetSkeleton({ name, sql, owner_id: profile?.id })- const data = { ...snippet, id: uuidv4() }- snap.addSnippet(data as SqlSnippet, ref)- router.push(`/project/${ref}/sql/${data.id}`)+ const snippet = createSqlSnippetSkeleton({+ id: uuidv4(),+ name,+ sql,+ owner_id: profile?.id,+ project_id: selectedProject?.id,+ })+ snap.addSnippet(snippet as SqlSnippet, ref)+ router.push(`/project/${ref}/sql/${snippet.id}`)} catch (error: any) {ui.setNotification({category: 'error',diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLQuickstarts.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLQuickstarts.tsxindex 6b134ef1ad2..8ee9194a042 100644--- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLQuickstarts.tsx+++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLQuickstarts.tsx@@ -5,7 +5,7 @@ import { observer } from 'mobx-react-lite'import { useParams, useTelemetryProps } from 'common'import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.constants'import { SqlSnippet } from 'data/content/sql-snippets-query'-import { useCheckPermissions, useStore } from 'hooks'+import { useCheckPermissions, useSelectedProject, useStore } from 'hooks'import { uuidv4 } from 'lib/helpers'import { useProfile } from 'lib/profile'import Telemetry from 'lib/telemetry'@@ -19,6 +19,7 @@ const SQLQuickstarts = observer(() => {const { ref } = useParams()const router = useRouter()const { profile } = useProfile()+ const project = useSelectedProject()const [, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })const telemetryProps = useTelemetryProps()@@ -40,10 +41,15 @@ const SQLQuickstarts = observer(() => {}try {- const snippet = createSqlSnippetSkeleton({ name, sql, owner_id: profile?.id })- const data = { ...snippet, id: uuidv4() }- snap.addSnippet(data as SqlSnippet, ref)- router.push(`/project/${ref}/sql/${data.id}`)+ const snippet = createSqlSnippetSkeleton({+ id: uuidv4(),+ name,+ sql,+ owner_id: profile?.id,+ project_id: project?.id,+ })+ snap.addSnippet(snippet as SqlSnippet, ref)+ router.push(`/project/${ref}/sql/${snippet.id}`)} catch (error: any) {ui.setNotification({category: 'error',diff --git a/studio/components/layouts/SQLEditorLayout/QueryItem.tsx b/studio/components/layouts/SQLEditorLayout/QueryItem.tsxindex 402da1ca2ff..1db2b63f574 100644--- a/studio/components/layouts/SQLEditorLayout/QueryItem.tsx+++ b/studio/components/layouts/SQLEditorLayout/QueryItem.tsx@@ -6,7 +6,7 @@ import { createSqlSnippetSkeleton } from 'components/interfaces/SQLEditor/SQLEdiimport ConfirmationModal from 'components/ui/ConfirmationModal'import { useContentDeleteMutation } from 'data/content/content-delete-mutation'import { SqlSnippet } from 'data/content/sql-snippets-query'-import { useCheckPermissions, useFlag, useStore } from 'hooks'+import { useCheckPermissions, useFlag, useSelectedProject, useStore } from 'hooks'import { IS_PLATFORM } from 'lib/constants'import { uuidv4 } from 'lib/helpers'import { useProfile } from 'lib/profile'@@ -90,6 +90,7 @@ const QueryItemActions = observer(({ tabInfo, activeId }: QueryItemActionsProps)const router = useRouter()const snap = useSqlEditorStateSnapshot()const { profile } = useProfile()+ const project = useSelectedProject()const sharedSnippetsFeature = useFlag<boolean>('sharedSnippets')const { mutate: deleteContent } = useContentDeleteMutation({onSuccess(data) {@@ -162,10 +163,15 @@ const QueryItemActions = observer(({ tabInfo, activeId }: QueryItemActionsProps)if (!ref) return console.error('Project ref is required')if (!id) return console.error('Snippet ID is required')try {- const snippet = createSqlSnippetSkeleton({ name, sql: content.sql, owner_id: profile?.id })- const data = { ...snippet, id: uuidv4() }- snap.addSnippet(data as SqlSnippet, ref)- router.push(`/project/${ref}/sql/${data.id}`)+ const snippet = createSqlSnippetSkeleton({+ id: uuidv4(),+ name,+ sql: content.sql,+ owner_id: profile?.id,+ project_id: project?.id,+ })+ snap.addSnippet(snippet as SqlSnippet, ref)+ router.push(`/project/${ref}/sql/${snippet.id}`)} catch (error: any) {ui.setNotification({category: 'error',diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsxindex 5ea866cd820..fe201ad5f87 100644--- a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx@@ -9,7 +9,7 @@ import { createSqlSnippetSkeleton } from 'components/interfaces/SQLEditor/SQLEdiimport ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem'import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { SqlSnippet, useSqlSnippetsQuery } from 'data/content/sql-snippets-query'-import { useCheckPermissions, useFlag, useStore } from 'hooks'+import { useCheckPermissions, useFlag, useSelectedProject, useStore } from 'hooks'import { uuidv4 } from 'lib/helpers'import { useProfile } from 'lib/profile'import { useSnippets, useSqlEditorStateSnapshot } from 'state/sql-editor'@@ -21,6 +21,7 @@ const SideBarContent = observer(() => {const { ref } = useParams()const router = useRouter()const { profile } = useProfile()+ const project = useSelectedProject()const sharedSnippetsFeature = useFlag<boolean>('sharedSnippets')const [personalSnippetsFilterString, setPersonalSnippetsFilterString] = useState('')@@ -95,14 +96,15 @@ const SideBarContent = observer(() => {try {const snippet = createSqlSnippetSkeleton({+ id: uuidv4(),name: untitledSnippetTitle,owner_id: profile?.id,+ project_id: project?.id,})- const data = { ...snippet, id: uuidv4() }- snap.addSnippet(data as SqlSnippet, ref)+ snap.addSnippet(snippet as SqlSnippet, ref)- router.push(`/project/${ref}/sql/${data.id}`)+ router.push(`/project/${ref}/sql/${snippet.id}`)// reset all search inputs when a new query is addedsetPersonalSnippetsFilterString('')setProjectSnippetsFilterString('')