-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathpostgres.go
68 lines (58 loc) · 2.79 KB
/
postgres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cmd
import (
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/supabase/cli/internal/postgresConfig/delete"
"github.com/supabase/cli/internal/postgresConfig/get"
"github.com/supabase/cli/internal/postgresConfig/update"
"github.com/supabase/cli/internal/utils/flags"
)
var (
postgresCmd = &cobra.Command{
GroupID: groupManagementAPI,
Use: "postgres-config",
Short: "Manage Postgres database config",
}
postgresConfigGetCmd = &cobra.Command{
Use: "get",
Short: "Get the current Postgres database config overrides",
RunE: func(cmd *cobra.Command, args []string) error {
return get.Run(cmd.Context(), flags.ProjectRef, afero.NewOsFs())
},
}
postgresConfigUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update Postgres database config",
Long: `Overriding the default Postgres config could result in unstable database behavior.
Custom configuration also overrides the optimizations generated based on the compute add-ons in use.`,
RunE: func(cmd *cobra.Command, args []string) error {
return update.Run(cmd.Context(), flags.ProjectRef, postgresConfigValues, postgresConfigUpdateReplaceMode, noRestart, afero.NewOsFs())
},
}
postgresConfigDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete specific Postgres database config overrides",
Long: "Delete specific config overrides, reverting them to their default values.",
RunE: func(cmd *cobra.Command, args []string) error {
return delete.Run(cmd.Context(), flags.ProjectRef, postgresConfigKeysToDelete, noRestart, afero.NewOsFs())
},
}
postgresConfigValues []string
postgresConfigUpdateReplaceMode bool
postgresConfigKeysToDelete []string
noRestart bool
)
func init() {
postgresCmd.PersistentFlags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
postgresCmd.AddCommand(postgresConfigGetCmd)
postgresCmd.AddCommand(postgresConfigUpdateCmd)
postgresCmd.AddCommand(postgresConfigDeleteCmd)
updateFlags := postgresConfigUpdateCmd.Flags()
updateFlags.StringSliceVar(&postgresConfigValues, "config", []string{}, "Config overrides specified as a 'key=value' pair")
updateFlags.BoolVar(&postgresConfigUpdateReplaceMode, "replace-existing-overrides", false, "If true, replaces all existing overrides with the ones provided. If false (default), merges existing overrides with the ones provided.")
updateFlags.BoolVar(&noRestart, "no-restart", false, "Do not restart the database after updating config.")
deleteFlags := postgresConfigDeleteCmd.Flags()
deleteFlags.StringSliceVar(&postgresConfigKeysToDelete, "config", []string{}, "Config keys to delete (comma-separated)")
deleteFlags.BoolVar(&noRestart, "no-restart", false, "Do not restart the database after deleting config.")
rootCmd.AddCommand(postgresCmd)
}