Skip to content

Commit

Permalink
Merge pull request #648 from tursodatabase/athos/group-fixes
Browse files Browse the repository at this point in the history
Small fixes for groups
  • Loading branch information
athoscouto authored Sep 25, 2023
2 parents 5f9c966 + 90e1575 commit 77a1cc6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 42 deletions.
25 changes: 0 additions & 25 deletions internal/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,6 @@ func closestLocation(client *turso.Client) (string, error) {
return closest, nil
}

func isNorthAmerica(location string) bool {
switch location {
case "atl", "bos", "den", "dfw", "ewr", "iad", "lax", "mia", "ord", "sea", "sjc", "yul", "yyz":
return true
default:
return false
}
}

func suggestedLocation(mainLocation string, locations map[string]string) (string, string) {
if isNorthAmerica(mainLocation) {
return "fra", "Europe"
} else {
return "iad", "North America"
}
}

func isValidLocation(client *turso.Client, location string) bool {
locations, err := locations(client)
if err != nil {
Expand All @@ -220,14 +203,6 @@ func isValidLocation(client *turso.Client, location string) bool {
return ok
}

func locationDescription(client *turso.Client, id string) string {
locations, _ := locations(client)
if desc, ok := locations[id]; ok {
return desc
}
return fmt.Sprintf("Location ID: %s", id)
}

func formatLocation(client *turso.Client, id string) string {
locations, _ := locations(client)
if desc, ok := locations[id]; ok {
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/db_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func init() {
addFromDBFlag(createCmd)
addDbFromFileFlag(createCmd)
addLocationFlag(createCmd, "Location ID. If no ID is specified, closest location to you is used by default.")

addWaitFlag(createCmd, "Wait for the database to be ready to receive requests.")
addCanaryFlag(createCmd)
addEnableExtensionsFlag(createCmd)
}

var createCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/db_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func dbListTable(databases []turso.Database) (headers []string, data [][]string)
}

sort.Slice(data, func(i, j int) bool {
return data[i][0] > data[j][0]
return data[i][0] < data[j][0]
})

return []string{"Name", "Locations", "Group", "URL"}, data
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/db_replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var replicateCmd = &cobra.Command{

if ok, _ := canReplicate(client, dbName); !ok {
cmd := internal.Emph(fmt.Sprintf("turso group locations add %s %s", database.Group, location))
return fmt.Errorf("database %s is part of a group.\nUse %s to replicate the group instead.", internal.Emph(dbName), cmd)
return fmt.Errorf("database %s is part of a group.\nUse %s to replicate the group instead", internal.Emph(dbName), cmd)
}

instance, err := replicate(client, database, location)
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/db_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ var showCmd = &cobra.Command{
fmt.Println("Name: ", db.Name)
fmt.Println("URL: ", getDatabaseUrl(&db))
fmt.Println("ID: ", db.ID)
if db.Group != "" {
fmt.Println("Group: ", db.Group)
}
if db.Version != "" {
fmt.Println("Version: ", db.Version)
}
Expand Down
15 changes: 0 additions & 15 deletions internal/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,6 @@ func dbNameAndOrgArgs(cmd *cobra.Command, args []string, toComplete string) ([]s
return dbNameArg(cmd, args, toComplete)
}

func isSQLiteFile(file *os.File) (bool, error) {
defer file.Seek(0, io.SeekStart)
header := make([]byte, 16)
_, err := file.Read(header)
if err != nil && err != io.EOF {
return false, err
}

if string(header) == "SQLite format 3\000" {
return true, nil
}

return false, nil
}

func fetchLatestVersion() (string, error) {
client, err := createUnauthenticatedTursoClient()
if err != nil {
Expand Down

0 comments on commit 77a1cc6

Please sign in to comment.