Skip to content

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

add data api page to integrations for self-hosted

Andrey A.b7cbc11d2126
diff --git a/apps/studio/components/interfaces/Integrations/DataApi/OverviewTab.tsx b/apps/studio/components/interfaces/Integrations/DataApi/OverviewTab.tsx
index f24c7fb34b6..56d230ab946 100644
--- a/apps/studio/components/interfaces/Integrations/DataApi/OverviewTab.tsx
+++ b/apps/studio/components/interfaces/Integrations/DataApi/OverviewTab.tsx
@@ -1,13 +1,14 @@
import { useParams } from 'common'
import { AlertCircle } from 'lucide-react'
import { Alert_Shadcn_, AlertTitle_Shadcn_, cn } from 'ui'
+import { Admonition } from 'ui-patterns/admonition'
import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'
import { DataApiEnableSwitch } from '@/components/interfaces/Settings/API/DataApiEnableSwitch'
import { DataApiProjectUrlCard } from '@/components/interfaces/Settings/API/DataApiProjectUrlCard'
import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
-import { PROJECT_STATUS } from '@/lib/constants'
+import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants'
export const DataApiOverviewTab = () => {
const { ref: projectRef } = useParams()
@@ -28,10 +29,22 @@ export const DataApiOverviewTab = () => {
</Alert_Shadcn_>
) : (
<>
- <div className={cn((isLoading || !isEnabled) && 'opacity-50 pointer-events-none')}>
+ <div
+ className={cn(
+ IS_PLATFORM && (isLoading || !isEnabled) && 'opacity-50 pointer-events-none'
+ )}
+ >
<DataApiProjectUrlCard />
</div>
- <DataApiEnableSwitch />
+ {IS_PLATFORM ? (
+ <DataApiEnableSwitch />
+ ) : (
+ <Admonition
+ type="default"
+ title="Managed via configuration variables"
+ description="Data API settings are configured via config.toml for CLI and local development, or via docker-compose.yml and .env for self-hosted deployments."
+ />
+ )}
</>
)}
</div>
diff --git a/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx b/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx
index fba36e35630..659177f0bce 100644
--- a/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx
+++ b/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx
@@ -4,12 +4,13 @@ import { PageContainer } from 'ui-patterns'
import { DataApiDisabledState } from '@/components/interfaces/Integrations/DataApi/DataApiDisabledState'
import { ServiceList } from '@/components/interfaces/Settings/API/ServiceList'
import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled'
+import { IS_PLATFORM } from '@/lib/constants'
export const DataApiSettingsTab = () => {
const { ref: projectRef } = useParams()
const { isEnabled, isPending } = useIsDataApiEnabled({ projectRef })
- if (!isPending && !isEnabled) {
+ if (IS_PLATFORM && !isPending && !isEnabled) {
return <DataApiDisabledState description="configure settings" />
}
diff --git a/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx b/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx
index ad6e2aa1079..7ac73ae4dfe 100644
--- a/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx
+++ b/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx
@@ -113,10 +113,6 @@ export const useAvailableIntegrations = () => {
return false
}
- if (integration.id === 'data_api' && !IS_PLATFORM) {
- return false
- }
-
return true
})
}, [integrationsWrappers, isCLI])
diff --git a/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx b/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx
index 584797e49e5..25a0e115196 100644
--- a/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx
+++ b/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx
@@ -3,7 +3,6 @@ import { useSchemasQuery } from 'data/database/schemas-query'
import { useFDWsQuery } from 'data/fdw/fdws-query'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
-import { IS_PLATFORM } from 'lib/constants'
import { EMPTY_ARR } from 'lib/void'
import { useMemo } from 'react'
@@ -27,9 +26,6 @@ export const useInstalledIntegrations = () => {
) {
return false
}
- if (!IS_PLATFORM && integration.id === 'data_api') {
- return false
- }
return true
})
}, [integrationsWrappers])
diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
index 2fe98e56239..89710a7cb06 100644
--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
@@ -51,6 +51,7 @@ import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useDataApiGrantTogglesEnabled } from '@/hooks/misc/useDataApiGrantTogglesEnabled'
import useLatest from '@/hooks/misc/useLatest'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
+import { IS_PLATFORM } from '@/lib/constants'
import { INTERNAL_SCHEMAS } from '@/hooks/useProtectedSchemas'
import { noop } from '@/lib/void'
import type { ResponseError } from '@/types'
@@ -152,8 +153,9 @@ export const PostgrestConfig = () => {
const formId = 'project-postgres-config'
- const { can: canUpdatePostgrestConfig, isSuccess: isPermissionsLoaded } =
+ const { can: canUpdatePostgrestConfigPermission, isSuccess: isPermissionsLoaded } =
useAsyncCheckPermissions(PermissionAction.UPDATE, 'custom_config_postgrest')
+ const canUpdatePostgrestConfig = IS_PLATFORM && canUpdatePostgrestConfigPermission
const isGraphqlExtensionEnabled =
(extensions ?? []).find((ext) => ext.name === 'pg_graphql')?.installed_version !== null
@@ -658,40 +660,44 @@ export const PostgrestConfig = () => {
)}
</form>
</Form_Shadcn_>
- <CardFooter className="border-t">
- <FormActions
- form={formId}
- isSubmitting={isUpdating}
- hasChanges={form.formState.isDirty}
- handleReset={resetForm}
- disabled={!canUpdatePostgrestConfig}
- helper={
- isPermissionsLoaded && !canUpdatePostgrestConfig
- ? "You need additional permissions to update your project's API settings"
- : undefined
- }
- />
- </CardFooter>
- </Card>
- <Card className="mb-4">
- <CardContent>
- <FormItemLayout
- isReactForm={false}
- layout="flex-row-reverse"
- label="Harden Data API"
- description="Expose a custom schema instead of the public schema"
- >
- <div className="flex gap-2 items-center justify-end">
- <Button type="default" icon={<Lock />} onClick={() => setShowModal(true)}>
- Harden Data API
- </Button>
- </div>
- </FormItemLayout>
- </CardContent>
+ {IS_PLATFORM && (
+ <CardFooter className="border-t">
+ <FormActions
+ form={formId}
+ isSubmitting={isUpdating}
+ hasChanges={form.formState.isDirty}
+ handleReset={resetForm}
+ disabled={!canUpdatePostgrestConfig}
+ helper={
+ isPermissionsLoaded && !canUpdatePostgrestConfigPermission
+ ? "You need additional permissions to update your project's API settings"
+ : undefined
+ }
+ />
+ </CardFooter>
+ )}
</Card>
+ {IS_PLATFORM && (
+ <Card className="mb-4">
+ <CardContent>
+ <FormItemLayout
+ isReactForm={false}
+ layout="flex-row-reverse"
+ label="Harden Data API"
+ description="Expose a custom schema instead of the public schema"
+ >
+ <div className="flex gap-2 items-center justify-end">
+ <Button type="default" icon={<Lock />} onClick={() => setShowModal(true)}>
+ Harden Data API
+ </Button>
+ </div>
+ </FormItemLayout>
+ </CardContent>
+ </Card>
+ )}
</PageSectionContent>
- <HardenAPIModal visible={showModal} onClose={() => setShowModal(false)} />
+ {IS_PLATFORM && <HardenAPIModal visible={showModal} onClose={() => setShowModal(false)} />}
</PageSection>
)
}
diff --git a/apps/studio/pages/api/platform/projects/[ref]/config/postgrest.ts b/apps/studio/pages/api/platform/projects/[ref]/config/postgrest.ts
index 8040a2381f1..c0411c96e84 100644
--- a/apps/studio/pages/api/platform/projects/[ref]/config/postgrest.ts
+++ b/apps/studio/pages/api/platform/projects/[ref]/config/postgrest.ts
@@ -19,11 +19,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const handleGet = async (req: NextApiRequest, res: NextApiResponse) => {
const responseObj: components['schemas']['GetPostgrestConfigResponse'] = {
db_anon_role: 'anon',
- db_extra_search_path: 'public',
- db_schema: 'public, storage',
+ db_extra_search_path: process.env.PGRST_DB_EXTRA_SEARCH_PATH ?? 'public',
+ db_schema: process.env.PGRST_DB_SCHEMAS ?? 'public,storage,graphql_public',
jwt_secret:
process.env.AUTH_JWT_SECRET ?? 'super-secret-jwt-token-with-at-least-32-characters-long',
- max_rows: 100,
+ max_rows: Number(process.env.PGRST_DB_MAX_ROWS) || 1000,
role_claim_key: '.role',
}
diff --git a/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx b/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx
index be24d7081de..8a9135c6541 100644
--- a/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx
+++ b/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx
@@ -151,10 +151,6 @@ const IntegrationPage: NextPageWithLayout = () => {
return null
}
- if (id === 'data_api' && !IS_PLATFORM) {
- return <UnknownInterface urlBack={`/project/${ref}/integrations`} />
- }
-
if (!integrationsWrappers && id?.endsWith('_wrapper')) {
return <UnknownInterface urlBack={`/project/${ref}/integrations`} />
}
diff --git a/docker/.env.example b/docker/.env.example
index a67cc5ef88f..5845ba13273 100644
--- a/docker/.env.example
+++ b/docker/.env.example
@@ -237,6 +237,12 @@ FUNCTIONS_VERIFY_JWT=false
# Postgres schemas exposed via the REST API
PGRST_DB_SCHEMAS=public,storage,graphql_public
+# Max number of rows returned by a request
+PGRST_DB_MAX_ROWS=1000
+
+# Extra schemas added to the search_path of every request
+PGRST_DB_EXTRA_SEARCH_PATH=public
+
############
# Analytics - Configuration for Logflare
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 21b66c6f802..c5b09781b69 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -37,6 +37,9 @@ services:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
PG_META_CRYPTO_KEY: ${PG_META_CRYPTO_KEY}
+ PGRST_DB_SCHEMAS: ${PGRST_DB_SCHEMAS}
+ PGRST_DB_MAX_ROWS: ${PGRST_DB_MAX_ROWS:-1000}
+ PGRST_DB_EXTRA_SEARCH_PATH: ${PGRST_DB_EXTRA_SEARCH_PATH:-"public"}
DEFAULT_ORGANIZATION_NAME: ${STUDIO_DEFAULT_ORGANIZATION}
DEFAULT_PROJECT_NAME: ${STUDIO_DEFAULT_PROJECT}
@@ -234,6 +237,8 @@ services:
environment:
PGRST_DB_URI: postgres://authenticator:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
PGRST_DB_SCHEMAS: ${PGRST_DB_SCHEMAS}
+ PGRST_DB_MAX_ROWS: ${PGRST_DB_MAX_ROWS:-1000}
+ PGRST_DB_EXTRA_SEARCH_PATH: ${PGRST_DB_EXTRA_SEARCH_PATH:-"public"}
PGRST_DB_ANON_ROLE: anon
PGRST_JWT_SECRET: ${JWT_SECRET}
PGRST_DB_USE_LEGACY_GUCS: "false"
diff --git a/turbo.json b/turbo.json
index 9687eb9f72d..cabd3802433 100644
--- a/turbo.json
+++ b/turbo.json
@@ -70,6 +70,9 @@
"PLATFORM_PG_META_URL",
"STUDIO_PG_META_URL",
"PG_META_CRYPTO_KEY",
+ "PGRST_DB_SCHEMAS",
+ "PGRST_DB_MAX_ROWS",
+ "PGRST_DB_EXTRA_SEARCH_PATH",
"POSTGRES_PASSWORD",
"POSTGRES_HOST",
"POSTGRES_USER_READ_WRITE",