ra-data-postgrest icon indicating copy to clipboard operation
ra-data-postgrest copied to clipboard

use schema other than public?

Open braco opened this issue 2 years ago • 3 comments

Is there any way to use a different schema from public?

I didn't see an obvious way to do this; not sure if the limitation is in this package or supabase.

braco avatar Oct 04 '22 18:10 braco

In supabase you can expose multiple schemas. Under the hood supabase is using Postgrest for exposing its api, and Postgrest allows targeting other/multiple schemas using the Accept-Profile and Content-Profile headers.

These 2 headers are not implemented by ra-data-postgrest yet.

I would propose to implement this using React-admin's meta-parameter, in a way that a dataProvider request would look like this.

const { data, isLoading, error } = useGetOne(
    'books',
    {
        id: 1,
        meta: { schema: 'data' }
    },
);

When ra-data-postgrest would find a schema in meta, it would then add the appropriate header (depending on the http method) to make Postgrest query the table/view/function from that schema.

Thoughts?

christiaanwesterbeek avatar Oct 04 '22 19:10 christiaanwesterbeek

Thank you!!!

I'm not that familiar with postgrest or react-admin internals, so am probably the wrong person to give feedback.

My generic perspective is that the separation between 'books' and meta.schema.data is strange, and I would expect either a 1. factory method since postgrest apparently exposes only one schema at a time, or 2. simpler notation like 'data.books', since that's where the table is always going to be.

Or what about something like this?

const dataProvider = postgrestRestProvider('....', switchSchema('data'));

or object style

const dataProvider = postgrestRestProvider({ url, schema });

braco avatar Oct 05 '22 21:10 braco

Hey @braco, we are currently working on several improvements and subsequently will add new features. Thus, we currently have kind of a feature-freeze. As of now, I like your suggestion of adding the schema as a parameter.

scheiblr avatar Oct 07 '22 08:10 scheiblr

@braco , I just released v2.0.0-aplha.2 which includes custom schema functionality. Feel free to test it and whether you encounter any issues, I would be glad to hear of it ;) In that case, feel free to reopen this issue or create a new one.

scheiblr avatar Apr 24 '23 21:04 scheiblr