Skip to content

Commit

Permalink
Allow forking databases group databases
Browse files Browse the repository at this point in the history
  • Loading branch information
athoscouto committed Sep 12, 2023
1 parent 98c82ac commit b97b23f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/cmd/db_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
dbCmd.AddCommand(createCmd)
addCanaryFlag(createCmd)
addGroupFlag(createCmd)
addForkFlag(createCmd)
addEnableExtensionsFlag(createCmd)
addDbFromFileFlag(createCmd)
addLocationFlag(createCmd, "Location ID. If no ID is specified, closest location to you is used by default.")
Expand Down Expand Up @@ -180,7 +181,7 @@ var createCmd = &cobra.Command{
description := fmt.Sprintf("Creating database %s%s in %s", internal.Emph(name), dbText, internal.Emph(locationText))
spinner := prompt.Spinner(description)
defer spinner.Stop()
if _, err = client.Databases.Create(name, locationId, image, extensions, groupFlag); err != nil {
if _, err = client.Databases.Create(name, locationId, image, extensions, groupFlag, forkFlag); err != nil {
return fmt.Errorf("could not create database %s: %w", name, err)
}

Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/group_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ func addGroupFlag(cmd *cobra.Command) {
return groups, cobra.ShellCompDirectiveNoFileComp
})
}

var forkFlag string

func addForkFlag(cmd *cobra.Command) {
cmd.Flags().StringVar(&forkFlag, "fork", "", "fork the new database from an existing one")
cmd.Flags().MarkHidden("fork")
cmd.RegisterFlagCompletionFunc("fork", dbNameArg)
}
6 changes: 3 additions & 3 deletions internal/turso/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ type CreateDatabaseResponse struct {
Username string
}

func (d *DatabasesClient) Create(name, region, image, extensions, group string) (*CreateDatabaseResponse, error) {
type Body struct{ Name, Region, Image, Extensions, Group string }
body, err := marshal(Body{name, region, image, extensions, group})
func (d *DatabasesClient) Create(name, region, image, extensions, group, fork string) (*CreateDatabaseResponse, error) {
type Body struct{ Name, Region, Image, Extensions, Group, Fork string }
body, err := marshal(Body{name, region, image, extensions, group, fork})
if err != nil {
return nil, fmt.Errorf("could not serialize request body: %w", err)
}
Expand Down

0 comments on commit b97b23f

Please sign in to comment.