Skip to content

Commit

Permalink
fix(link): take url as string arg
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Oct 26, 2021
1 parent 85eee76 commit db0799b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
20 changes: 4 additions & 16 deletions cmd/link.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
package cmd

import (
"errors"
"fmt"

"github.com/spf13/cobra"
"github.com/supabase/cli/internal/link"
)

var (
useUrl bool
deployDbUrl string

linkCmd = &cobra.Command{
Use: "link",
Short: "Link the current project to a remote deploy database.",
RunE: func(cmd *cobra.Command, args []string) error {
if useUrl {
var deployDbUrl string
fmt.Scanln(&deployDbUrl)
if len(deployDbUrl) == 0 {
return errors.New("Error on `supabase link`: URL is empty.")
}

return link.Link(deployDbUrl)
}

return errors.New("Use `--url` to pass the deploy database URL to link to.")
return link.Link(deployDbUrl)
},
}
)

func init() {
linkCmd.Flags().
BoolVar(&useUrl, "url", false, "Accept Postgres connection string of the deploy database from standard input.")
StringVar(&deployDbUrl, "url", "", "Postgres connection string of the deploy database.")
cobra.CheckErr(linkCmd.MarkFlagRequired("url"))

rootCmd.AddCommand(linkCmd)
}
2 changes: 1 addition & 1 deletion examples/tour/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ supabase init
This will create a `supabase` directory which is managed by the CLI. Then we need to link the current project with the deploy database. Use the connection string from your Supabase project here.

```sh
supabase link --url <<< 'postgresql://postgres:<your_password>@db.<your_project_ref>.supabase.co:5432/postgres'
supabase link --url 'postgresql://postgres:<your_password>@db.<your_project_ref>.supabase.co:5432/postgres'
```

Why do we need to do this? Because if we want to manage a database with a migration tool, we need a _baseline_ where both the migration tool and the database have consistent schemas. `supabase link` does this synchronization between the two.
Expand Down

0 comments on commit db0799b

Please sign in to comment.