https://supabase.com/ logo
#help
Title
# help
g

Garett MacGowan

04/30/2022, 12:00 AM
Does an API endpoint exist such that I could programmatically add to the db_schema config of PostgREST? Trying to do this locally (for testing) as well as production. I've got supabase deployed in local docker for testing.
n

Needle

04/30/2022, 12:00 AM
Hello @Garett MacGowan! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
g

Garett MacGowan

04/30/2022, 12:06 AM
I don't believe I can use
https://api.supabase.io/platform/projects/{my-project-key}/config?app=postgrest
with auth as the bearer token since it will expire. Nothing has jumped out at me from the official/community repos.
g

garyaustin

04/30/2022, 12:14 AM
Can you say what you trying to accomplish? I think this API setting tells PostgREST what schemas can be accessed:
n

Needle

04/30/2022, 12:14 AM
Garett MacGowan (2022-04-30)
g

Garett MacGowan

04/30/2022, 12:17 AM
Yeah, I'm trying to programmatically change that setting. Basically, I need to know the local version of the endpoint above, and then I need to know how I can programmatically get the JWT bearer token so I can use the endpoint.
g

garyaustin

04/30/2022, 12:18 AM
Are you saying that setting is not available in local version of Supabase?
The setting "input toggle" is not implemented very well. You have to click on one of the tags( storage or public) or just to the right of storage to get the option to add schemas.
g

Garett MacGowan

04/30/2022, 12:27 AM
Yeah, I opened a ticket for that design issue. Basically, I'm unsure what the URL for the local version is, and I'm unsure about authorizing the request. I suppose I can just use the service_role secret (obviously just for a backend use)?
g

garyaustin

04/30/2022, 12:28 AM
I don't use local, so I'm asking again the local studio does not have that setting?
g

Garett MacGowan

04/30/2022, 12:29 AM
Oh, I see what you're saying. I haven't tried opening the local app.supabase.io. Wasn't even sure if that was included.
g

garyaustin

04/30/2022, 12:30 AM
There is a local studio version that does all the database stuff of the online dashboard.
As far as setting that with a call, I've never looked into that as it is set once and never used unless you change your schema plan.
g

Garett MacGowan

04/30/2022, 12:33 AM
Yeah, my use case is that I will be creating multiple schemas so I don't want to have to remember to toggle it manually every time.
Basically I want to get as close as possible to one-click boot my whole app with no manual config.
g

garyaustin

04/30/2022, 12:38 AM
You might look into the studio code and see what it does for that setting.
g

Garett MacGowan

04/30/2022, 6:06 AM
Local studio does not have the settings. I tried hitting the endpoint on the hosted Supabase that I scraped from the dev console when toggling schemas manually. I can't get the service_role key to work as the bearer token. The token I see in the console is unrecognizable. It works fine with the scraped bearer token, but that token expires quickly. I seem to have found a direct approach in https://postgrest.org/en/latest/configuration.html#in-database-configuration. Not sure how I would implement this since the pgrst schema does not appear to be exposed anywhere.
This repo https://github.com/supabase/supabase-admin-api looks like it has what I need but i'm not sure how to go about using it. It seems like its only intra-cluster. I would need these endpoints exposed for the local deployment as well as the supabase hosted one, via the service_role key, maybe.
Without access to these endpoints, I can't effectively automate the addition of more schemas to Realtime. I can't even add schemas to the local instance (or at least I haven't figured out how yet).
g

garyaustin

04/30/2022, 6:04 PM
I'm puzzled as even just using another schema with supabase.js (which would be more common than realtime) requires changing that setting. I've not run across any complaints before, not to say I've seen all discussions. (edit: but maybe you did get the dashboard working locally, it is just not sufficient for what you want to do)
One thing in the admin API it talks of settings needed for token and mentions needing supabase_admin role. You may need to create a token with that role to use the url you found early on.
More info on getting a jwt for use with the dashboard URL... https://supabase.com/docs/guides/hosting/overview#api-keys And https://supabase.com/docs/learn/auth-deep-dive/auth-deep-dive-jwts You should be able to set for no exp or very long exp time.
g

Garett MacGowan

04/30/2022, 10:34 PM
Much appreciated. I tried minting the JWT with the role through the link and through a python package and neither worked with the original URL
https://api.supabase.io/platform/projects/{my-project-key}/config?app=postgrest
. I think the supabase-admin-api is only deployed on the hosted image. I don't see any references to supabase-admin-api in the local docker container. It also isn't included in the architecture map. You can't access the config in the API since everything in the API is routed through Kong. If I try and access the pgrst schema of PostgREST (where I could update db-schema, theoretically) I get the same problem that only the UI can solve, except it can't, since the UI doesn't offer pgrst as a schema to include in the API. Only solution for me is direct manipulation of the config, which is only possible through local, and would take some tinkering. I think my interim solution might be to just run E2E tests on a dev instance of supabase and manually toggle schemas for now.
But I think the ultimate solution would be to expose the admin API to Kong and require a service_key to interact with it.
g

garyaustin

04/30/2022, 10:37 PM
well good luck. I'm going to stop monitoring this thread, so probably should start a new one for anything else.
g

Garett MacGowan

04/30/2022, 10:37 PM
Ok, thanks for the help.
s

Steve

05/01/2022, 6:47 AM
> Does an API endpoint exist such that I could programmatically add to the db_schema config of PostgREST? @Garett MacGowan This should be handled with care and is not exposed through the UI, but you can use: https://postgrest.org/en/stable/configuration.html#in-database-configuration Through an RPC to programatically add schemas to postgREST. (make sure to include the default schemas in the supabase UI - like storage)
Here's an example function: https://github.com/PostgREST/postgrest/blob/main/test/io/fixtures.sql#L49-L56 (you can change
postgrest_test_authenticator
to
authenticator
for Supabase)
g

Garett MacGowan

05/01/2022, 3:56 PM
Awesome, that worked. Unfortunately the UI doesn't update to reflect the changes to the config (I assume because its the intra DB config, and Supabase is probably reading from a file, but the intra DB config takes precedence). I can deal with that, though. I'll update my feature request to include this as an alternative.