cli icon indicating copy to clipboard operation
cli copied to clipboard

Obtaining DB_URL from the CLI

Open scherven opened this issue 1 year ago • 9 comments

Is your feature request related to a problem? Please describe. I am attempting to set up branch previews (similar to Vercel) in railway. To do this, I need to update some environment variables on the railway side, including SUPABASE_DB_URL.

Describe the solution you'd like I'd like to be able to run some supabase CLI command to obtain the DB_URl automatically, so I don't have to add it manually as a variable whenever I make a new branch. However, I cannot find a CLI command that will do this. gen keys gives me the password but not the user, the port, the database, or the host. branches get has the user, port, and host, but these conflict with the information shown in my dashboard. (I assume the database is always postgres?)

Describe alternatives you've considered I've looked in the docs for the CLI and the javascript library, and neither of them seems to provide the database url. Any help is appreciated!

scherven avatar Dec 10 '24 23:12 scherven

Hi @Innoviox, thanks for the suggestion.

We can definitely make branches get more useful by adding a --output env flag to format the output. We already have a list of envs that users typically want exposed. These include both pooling (shown in cli) and non-pooling (shown on dashboard) db urls.

I will probably have time to look into this early 2025.

sweatybridge avatar Dec 11 '24 09:12 sweatybridge

@sweatybridge , if this issue is open, then may I work on this issue? I've a lot of experience in Go and have previously contributed to Keploy, Meshery(both CNCF projects) and Taipy. May I work on this issue, if it's open to all 👀 ?

yaten2302 avatar Dec 20 '24 12:12 yaten2302

@yaten2302 sure thing. We have some examples of using the output flag in status command.

Feel free to tag me if you have any questions or want a review.

sweatybridge avatar Dec 20 '24 13:12 sweatybridge

Thanks for your suggestions @sweatybridge! I've a few doubts, regarding the same, could you please help me with those:

  1. Firstly, what exactly we're doing here is that, currently there's no command to export the supabase DB_URL from the .env file and we need to add a flag --output env to the existing command - branches get?
  2. As mentioned by you in this comment, the one's with pooling are shown in cli and ones with non_pooling, are shown on the supabase dashboard. So, I need to export this - POSTGRES_URL = "POSTGRES_URL", to the cli, am I right? Is there anything else also that needs to be exported?

And yes, I'll take help from the status command to check how to add a new flag to a command, which you mentioned in your previous comment 👍

yaten2302 avatar Dec 20 '24 17:12 yaten2302

Any update on this @sweatybridge :)

yaten2302 avatar Dec 24 '24 14:12 yaten2302

Currently branches get command prints the database connection details, but not the full connection string. The code for building the full connection string is available in bootstrap command. Also in the bootstrap command, we expose both pooling and non pooling url.

So there are a few tasks I would suggest as next steps

  1. Add --output flag to branches get command while keeping all existing output fields. For eg, the current table output includes db user field, so specifying --output env should also include a POSTGRES_USER env var.

  2. Next, we can add postgres_url and postgres_url_non_pooling to the env output. The code for this can be reused from bootstrap command.

Hope it clarifies.

sweatybridge avatar Dec 24 '24 15:12 sweatybridge

Got it @sweatybridge 👍 I've understood the workflow, working on it, I'll create a draft PR soon!! Thanks

yaten2302 avatar Dec 25 '24 12:12 yaten2302

@sweatybridge I've created a draft PR for this issue 👍

yaten2302 avatar Dec 25 '24 18:12 yaten2302

Hey @sweatybridge , could you please guide regarding the PR, whenever you get time :) Thanks

yaten2302 avatar Dec 29 '24 06:12 yaten2302