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

Allow seeding databases with content from existing group databases #626

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading