The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: using custom schemas
Bobbie Soedirgo1cb8b9e9bb1d
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 37803d4823b..e58c9c172c9 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -737,6 +737,7 @@ export const api: NavMenuConstant = {url: '/guides/api/joins-and-nesting',items: [],},+ { name: 'Using custom schemas', url: '/guides/api/using-custom-schemas', items: [] },],},{diff --git a/apps/docs/pages/guides/api/using-custom-schemas.mdx b/apps/docs/pages/guides/api/using-custom-schemas.mdxnew file mode 100644index 00000000000..87d791aa5d9--- /dev/null+++ b/apps/docs/pages/guides/api/using-custom-schemas.mdx@@ -0,0 +1,59 @@+import Layout from '~/layouts/DefaultGuideLayout'++export const meta = {+ id: 'using-custom-schemas',+ title: 'Using Custom Schemas',+ description: 'You need additional steps to use custom database schemas with Serverless APIs.',+}++By default, your database has a `public` schema which is automatically exposed on Serverless APIs. You can also expose custom database schemas - to do so you need to follow these steps:++1. Go to [API settings](https://supabase.com/dashboard/project/_/settings/api) and add your custom schema to "Exposed schemas".+2. Run the following SQL, substituting `myschema` with your schema name:++```sql+GRANT USAGE ON SCHEMA myschema TO anon, authenticated, service_role;+GRANT ALL ON ALL TABLES IN SCHEMA myschema TO anon, authenticated, service_role;+GRANT ALL ON ALL ROUTINES IN SCHEMA myschema TO anon, authenticated, service_role;+GRANT ALL ON ALL SEQUENCES IN SCHEMA myschema TO anon, authenticated, service_role;+ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON TABLES TO anon, authenticated, service_role;+ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON ROUTINES TO anon, authenticated, service_role;+ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON SEQUENCES TO anon, authenticated, service_role;+```++Now you can access these schemas from Serverless APIs:++<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="javascript"+>+<TabPanel id="javascript" label="JavaScript">++```js+// Initialize the JS client+import { createClient } from '@supabase/supabase-js'+const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, { db: { schema: 'myschema' } })++// Make a request+const { data: todos, error } = await supabase.from('todos').select('*')+```++</TabPanel>+<TabPanel id="curl" label="cURL">++```bash+# Append /rest/v1/ to your URL, and then use the table name as the route+curl '<SUPABASE_URL>/rest/v1/todos' \+ -H "apikey: <SUPABASE_ANON_KEY>" \+ -H "Authorization: Bearer <SUPABASE_ANON_KEY>" \+ -H "Accept-Profile: myschema"+```++</TabPanel>+</Tabs>++export const Page = ({ children }) => <Layout meta={meta} children={children} />++export default Page