Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:2964 obtain Postgres DB URL from ENV using branches get command #2996

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from

Conversation

yaten2302
Copy link

What kind of change does this PR introduce?

This PR introduces a new feature to enable users to obtain the Postgres db url from the .env using the branches get command.

What is the current behavior?

Fixes #2964

What is the new behavior?

This PR adds a new flag to the branches get command to help users to get the postgres db url from the env.

Additional context

Add any other context or screenshots.

@yaten2302
Copy link
Author

@sweatybridge , I've a doubt, that as you mentioned in this comment, that a new --output flag should be added to the branches get command. But, while implementing that, it's showing an error that the output flag is being redeclared. So, is it possible that instead of using the output flag, we can use a Boolean var postgres-url?

Also, as you mentioned, that the postgres_url and prostgres_url_non_pooling has to be added if this flag is mentioned with the command and the code can be reused from the bootstrap command. But, while I was checking the writeDotEnv func, it writes the complete thing to the .env file. But, I'm confused that how can I get the postgres_db_url from the writeDotEnv func? Because, I was having some issues in adding the postgres_db_url to the resp, could you guide that how can I add the same to the resp, so that it can be used to display it on the output table for the user.

@yaten2302 yaten2302 marked this pull request as ready for review December 31, 2024 18:14
@yaten2302 yaten2302 requested a review from a team as a code owner December 31, 2024 18:14
@yaten2302
Copy link
Author

Hey @sweatybridge , could you please have a look at this PR, I've made the required changes, kindly review and LMK if any more are required!!
Thanks

@coveralls
Copy link

coveralls commented Dec 31, 2024

Pull Request Test Coverage Report for Build 12609893240

Details

  • 0 of 20 (0.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.1%) to 59.622%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/branches/get/get.go 0 20 0.0%
Files with Coverage Reduction New Missed Lines %
internal/branches/get/get.go 1 0.0%
internal/gen/keys/keys.go 5 12.9%
Totals Coverage Status
Change from base Build 12595878677: -0.1%
Covered Lines: 7668
Relevant Lines: 12861

💛 - Coveralls

@sweatybridge
Copy link
Contributor

Let's do this in smaller steps so I can provide more detailed guidance.

But, while implementing that, it's showing an error that the output flag is being redeclared.

This is how golang works: any variable declared in the same package is shared by all code in that package. Since the output variable is already declared in cmd package, you don't need to redeclare for this command.

For your first commit, simply passing it down to branches get command will do. No need to implement the actual behaviour for env output.

After you've done that, tag me again so I can check before providing more details for the actual implementation.

Copy link
Contributor

@sweatybridge sweatybridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to open a new PR if it's easier for you.

@sweatybridge
Copy link
Contributor

Also, sorry for the late reply as I was on holiday for the last 2 weeks and there were a lot to catch up on. I will review more promptly this week and next if you plan to make the changes.

@yaten2302
Copy link
Author

Heyy @sweatybridge , sorry, actually, I was pushing some changes right now only and that's why didn't see your comment on this PR.

Let's do this in smaller steps so I can provide more detailed guidance.

But, while implementing that, it's showing an error that the output flag is being redeclared.

This is how golang works: any variable declared in the same package is shared by all code in that package. Since the output variable is already declared in cmd package, you don't need to redeclare for this command.

For your first commit, simply passing it down to branches get command will do. No need to implement the actual behaviour for env output.

After you've done that, tag me again so I can check before providing more details for the actual implementation.

Also, yes, for this, I was also researching about the same and now I understood that, vars are shared across the same package files in Go.
I've made some changes now, I think that these might fix this --output-env flag. Could you have a look at it, whenever you're free!!
Thanks :)

cmd/branches.go Outdated Show resolved Hide resolved
cmd/branches.go Outdated Show resolved Hide resolved
cmd/branches.go Outdated Show resolved Hide resolved
cmd/branches.go Outdated Show resolved Hide resolved
@yaten2302
Copy link
Author

Now, how should the Run() func be changed in internal/branches/get/get.go in order to get the POSTGRES_URL_NON_POOLING from the internal/bootstrap/bootstrap.go?

cmd/branches.go Outdated Show resolved Hide resolved
internal/branches/get/get.go Show resolved Hide resolved
internal/branches/get/get.go Outdated Show resolved Hide resolved
cmd/branches.go Outdated Show resolved Hide resolved
internal/branches/get/get.go Show resolved Hide resolved
cmd/branches.go Outdated Show resolved Hide resolved
internal/branches/get/get.go Outdated Show resolved Hide resolved
|-|-|-|-|-|-|-|
config := pgconn.Config{
Host: utils.GetSupabaseDbHost(resp.JSON200.DbHost),
Port: uint16(resp.JSON200.DbPort),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Port: uint16(resp.JSON200.DbPort),
Port: uint16(cast.IntToUint(resp.JSON200.DbPort)),

To fix lint check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaten2302 in case you missed it, there are more linter errors to fix https://github.com/supabase/cli/actions/runs/12608039666

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sweatybridge , yes, ig I forgot about the linter errors, I've a doubt, that in here, these 2 errors are being show

image

In the 2nd one, should I remove cast.IntToUInt(...), I think the error is arising because of that only?
For the first one, I've pushed a commit, I think it should be fixed now (formatted the file)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the 2nd one, should I remove cast.IntToUInt(...), I think the error is arising because of that only?

We need to implement a new method for safely casting UInt to UInt16 and call it. You can check the existing examples in cast.go on how to check for overflows. But if you feel stuck, I can also take over from here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll research upon it a and then ask if I encounter any doubts! Also, I wanted to ask that, is it possible to check the linter errors are failing or passing without pushing the changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Obtaining DB_URL from the CLI
3 participants