Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Method to set schema on a call by call basis. #280

@GaryAustin1

Description

@GaryAustin1

Feature request

Right now you can only set a schema in initial supabase client setup.
It would be very useful to be able to override the default ('public' normally) schema on individual calls.

Describe the solution you'd like

Add a postgrest-js operation .schema('myschema') that can be used with other operations on a single call basis.

Describe alternatives you've considered

Currently the below works in my environment. It does not impact storage and auth, but have not tested on realtime yet.

let schema = ''
var supabase = supabase.createClient(SUPABASE_URL, SUPABASE_KEY, {
    fetch: (requestInfo, requestInit) => {
        if (schema) requestInit.headers['Accept-Profile'] = schema
        return(fetch(requestInfo,requestInit))
    }

Then you do the following for a different schema

    schema = 'storage'
    const response = await supabase
        .from('objects')
        .select('*')
    schema = ''

For modular code one could add

export function setSchema(schemaName) {
 schema = schemaName
}

And call that before and after supabase database call to another schema.

Additional context

It appears the only thing required to make PostgREST work with an API available schema is setting the Accept-Profile' header. This should be easily done in postgrest-js with a .schema('myschema') function added to postgrest calls.

    const response = await supabase
        .from('objects')
        .schema('storage')
        .select('*')

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions