Using Custom Schemas
A guide from Supabase
Apps on Plentiful run on Supabase's open-source database, sign-in, file storage and live updates, so most of this guide applies. The differences: your app reaches its database through its own server — not Supabase's data API (supabase.from(…)) — there are no Edge Functions (your app's server does that work), and scheduled work uses Jobs. Where it says "Supabase dashboard", use your app's Dashboard. Ask the builder when in doubt.
By default, your database has a public schema which is automatically exposed on data APIs.
Creating custom schemas#
You can create your own custom schema/s by running the following SQL, substituting myschema with the name you want to use for your schema:
1CREATE SCHEMA myschema;Exposing custom schemas#
You can expose custom database schemas - to do so you need to follow these steps:
- Go to API settings and add your custom schema to "Exposed schemas".
- Run the following SQL, substituting
myschemawith your schema name:
1GRANT USAGE ON SCHEMA myschema TO anon, authenticated, service_role;2GRANT ALL ON ALL TABLES IN SCHEMA myschema TO anon, authenticated, service_role;3GRANT ALL ON ALL ROUTINES IN SCHEMA myschema TO anon, authenticated, service_role;4GRANT ALL ON ALL SEQUENCES IN SCHEMA myschema TO anon, authenticated, service_role;5ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON TABLES TO anon, authenticated, service_role;6ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON ROUTINES TO anon, authenticated, service_role;7ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON SEQUENCES TO anon, authenticated, service_role;Now you can access these schemas from data APIs:
1// Initialize the JS client2import { createClient } from '@supabase/supabase-js'3const supabase = createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {4 db: { schema: 'myschema' },5})67// Make a request8const { data: todos, error } = await supabase.from('todos').select('*')910// You can also change the target schema on a per-query basis11const { data: todos, error } = await supabase.schema('myschema').from('todos').select('*')