Skip to content

Commit

Permalink
Issue#917: Add a check to know if database is archived
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishgangaramani committed Nov 2, 2024
1 parent b332d6e commit cbe4081
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/cmd/db_shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,20 @@ var shellCmd = &cobra.Command{
if len(args[1]) == 0 {
return fmt.Errorf("no SQL command to execute")
}
err := checkArchiveStatus(db)
if err != nil {
return err
}
if args[1] == ".dump" {
return dump(getDbURLForDump(dbUrl), authToken)
}
return runShellLine(dbID, shellConfig, args[1])
}

err := checkArchiveStatus(db)
if err != nil {
return err
}
if nonInteractive {
// TODO: read chunks when interactive transactions are available
b, err := io.ReadAll(os.Stdin)
Expand All @@ -234,6 +242,13 @@ var shellCmd = &cobra.Command{
},
}

func checkArchiveStatus(db *turso.Database) error {
if db != nil && db.Sleeping {
return fmt.Errorf("Your DB might be archived. Please run `turso group unarchive " + db.Group + "` to unarchive it\n")
}
return nil
}

func runShell(dbID string, config shell.ShellConfig) error {
err := shell.RunShell(config)
if isAuthError(err) && dbID != "" {
Expand Down

0 comments on commit cbe4081

Please sign in to comment.