Skip to content

Commit

Permalink
feat(db/create): allow size-limit flag (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
notrab authored Jul 30, 2024
1 parent 3020c76 commit 4c3142f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/cmd/db_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
addEnableExtensionsFlag(createCmd)
addSchemaFlag(createCmd)
addTypeFlag(createCmd)
addSizeLimitFlag(createCmd)
}

var createCmd = &cobra.Command{
Expand Down Expand Up @@ -77,7 +78,7 @@ var createCmd = &cobra.Command{
spinner := prompt.Spinner(fmt.Sprintf("Creating database %s in group %s...", internal.Emph(name), internal.Emph(group)))
defer spinner.Stop()

if _, err = client.Databases.Create(name, location, "", "", group, schemaFlag, typeFlag == "schema", seed); err != nil {
if _, err = client.Databases.Create(name, location, "", "", group, schemaFlag, typeFlag == "schema", seed, sizeLimitFlag); err != nil {
return fmt.Errorf("could not create database %s: %w", name, err)
}

Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/db_size_limit_flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cmd

import "github.com/spf13/cobra"

var sizeLimitFlag string

func addSizeLimitFlag(cmd *cobra.Command) {
cmd.Flags().StringVar(&sizeLimitFlag, "size-limit", "", "The maximum size of the database in bytes. Values with units are accepted, e.g. 1mb, 256mb, 1gb")
}
5 changes: 3 additions & 2 deletions internal/turso/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ type CreateDatabaseBody struct {
Seed *DBSeed `json:"seed,omitempty"`
Schema string `json:"schema,omitempty"`
IsSchema bool `json:"is_schema,omitempty"`
SizeLimit string `json:"size_limit,omitempty"`
}

func (d *DatabasesClient) Create(name, location, image, extensions, group string, schema string, isSchema bool, seed *DBSeed) (*CreateDatabaseResponse, error) {
params := CreateDatabaseBody{name, location, image, extensions, group, seed, schema, isSchema}
func (d *DatabasesClient) Create(name, location, image, extensions, group string, schema string, isSchema bool, seed *DBSeed, sizeLimit string) (*CreateDatabaseResponse, error) {
params := CreateDatabaseBody{name, location, image, extensions, group, seed, schema, isSchema, sizeLimit}

body, err := marshal(params)
if err != nil {
Expand Down

0 comments on commit 4c3142f

Please sign in to comment.