• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 17260823135

27 Aug 2025 07:58AM UTC coverage: 54.744% (-0.02%) from 54.765%
17260823135

Pull #4082

github

web-flow
Merge abaa29aba into 7a28eabd9
Pull Request #4082: feat: support custom query timeout for type gen

24 of 32 new or added lines in 3 files covered. (75.0%)

9 existing lines in 3 files now uncovered.

6203 of 11331 relevant lines covered (54.74%)

6.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/gen.go
1
package cmd
2

3
import (
4
        "os"
5
        "os/signal"
6
        "time"
7

8
        env "github.com/Netflix/go-env"
9
        "github.com/go-errors/errors"
10
        "github.com/spf13/afero"
11
        "github.com/spf13/cobra"
12
        "github.com/supabase/cli/internal/gen/keys"
13
        "github.com/supabase/cli/internal/gen/signingkeys"
14
        "github.com/supabase/cli/internal/gen/types"
15
        "github.com/supabase/cli/internal/utils"
16
        "github.com/supabase/cli/internal/utils/flags"
17
        "github.com/supabase/cli/pkg/config"
18
)
19

20
var (
21
        genCmd = &cobra.Command{
22
                GroupID: groupLocalDev,
23
                Use:     "gen",
24
                Short:   "Run code generation tools",
25
        }
26

27
        keyNames keys.CustomName
28

29
        genKeysCmd = &cobra.Command{
30
                Use:   "keys",
31
                Short: "Generate keys for preview branch",
32
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
33
                        es, err := env.EnvironToEnvSet(override)
×
34
                        if err != nil {
×
35
                                return err
×
36
                        }
×
37
                        if err := env.Unmarshal(es, &keyNames); err != nil {
×
38
                                return err
×
39
                        }
×
40
                        cmd.GroupID = groupManagementAPI
×
41
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
42
                },
43
                RunE: func(cmd *cobra.Command, args []string) error {
×
44
                        format := utils.OutputFormat.Value
×
45
                        if format == utils.OutputPretty {
×
46
                                format = utils.OutputEnv
×
47
                        }
×
48
                        return keys.Run(cmd.Context(), flags.ProjectRef, format, keyNames, afero.NewOsFs())
×
49
                },
50
        }
51

52
        lang = utils.EnumFlag{
53
                Allowed: []string{
54
                        types.LangTypescript,
55
                        types.LangGo,
56
                        types.LangSwift,
57
                },
58
                Value: types.LangTypescript,
59
        }
60
        queryTimeout       time.Duration
61
        postgrestV9Compat  bool
62
        swiftAccessControl = utils.EnumFlag{
63
                Allowed: []string{
64
                        types.SwiftInternalAccessControl,
65
                        types.SwiftPublicAccessControl,
66
                },
67
                Value: types.SwiftInternalAccessControl,
68
        }
69

70
        genTypesCmd = &cobra.Command{
71
                Use:   "types",
72
                Short: "Generate types from Postgres schema",
73
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
74
                        if postgrestV9Compat && !cmd.Flags().Changed("db-url") {
×
75
                                return errors.New("--postgrest-v9-compat must used together with --db-url")
×
76
                        }
×
77
                        // Legacy commands specify language using arg, eg. gen types typescript
78
                        if len(args) > 0 && args[0] != types.LangTypescript && !cmd.Flags().Changed("lang") {
×
79
                                return errors.New("use --lang flag to specify the typegen language")
×
80
                        }
×
81
                        return nil
×
82
                },
83
                RunE: func(cmd *cobra.Command, args []string) error {
×
84
                        ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
×
85
                        if flags.DbConfig.Host == "" {
×
86
                                // If no flag is specified, prompt for project id.
×
87
                                if err := flags.ParseProjectRef(ctx, afero.NewMemMapFs()); errors.Is(err, utils.ErrNotLinked) {
×
88
                                        return errors.New("Must specify one of --local, --linked, --project-id, or --db-url")
×
89
                                } else if err != nil {
×
90
                                        return err
×
91
                                }
×
92
                        }
NEW
93
                        return types.Run(ctx, flags.ProjectRef, flags.DbConfig, lang.Value, schema, postgrestV9Compat, swiftAccessControl.Value, queryTimeout, afero.NewOsFs())
×
94
                },
95
                Example: `  supabase gen types --local
96
  supabase gen types --linked --lang=go
97
  supabase gen types --project-id abc-def-123 --schema public --schema private
98
  supabase gen types --db-url 'postgresql://...' --schema public --schema auth`,
99
        }
100

101
        algorithm = utils.EnumFlag{
102
                Allowed: signingkeys.GetSupportedAlgorithms(),
103
                Value:   string(config.AlgES256),
104
        }
105
        appendKeys bool
106

107
        genSigningKeyCmd = &cobra.Command{
108
                Use:   "signing-key",
109
                Short: "Generate a JWT signing key",
110
                Long: `Securely generate a private JWT signing key for use in the CLI or to import in the dashboard.
111

112
Supported algorithms:
113
        ES256 - ECDSA with P-256 curve and SHA-256 (recommended)
114
        RS256 - RSA with SHA-256
115
`,
116
                RunE: func(cmd *cobra.Command, args []string) error {
×
117
                        return signingkeys.Run(cmd.Context(), algorithm.Value, appendKeys, afero.NewOsFs())
×
118
                },
×
119
        }
120
)
121

122
func init() {
×
123
        typeFlags := genTypesCmd.Flags()
×
124
        typeFlags.Bool("local", false, "Generate types from the local dev database.")
×
125
        typeFlags.Bool("linked", false, "Generate types from the linked project.")
×
126
        typeFlags.String("db-url", "", "Generate types from a database url.")
×
127
        typeFlags.StringVar(&flags.ProjectRef, "project-id", "", "Generate types from a project ID.")
×
128
        genTypesCmd.MarkFlagsMutuallyExclusive("local", "linked", "project-id", "db-url")
×
129
        typeFlags.Var(&lang, "lang", "Output language of the generated types.")
×
130
        typeFlags.StringSliceVarP(&schema, "schema", "s", []string{}, "Comma separated list of schema to include.")
×
NEW
131
        // Direct connection only flags
×
132
        typeFlags.Var(&swiftAccessControl, "swift-access-control", "Access control for Swift generated types.")
×
NEW
133
        genTypesCmd.MarkFlagsMutuallyExclusive("linked", "project-id", "swift-access-control")
×
NEW
134
        typeFlags.BoolVar(&postgrestV9Compat, "postgrest-v9-compat", false, "Generate types compatible with PostgREST v9 and below.")
×
NEW
135
        genTypesCmd.MarkFlagsMutuallyExclusive("linked", "project-id", "postgrest-v9-compat")
×
NEW
136
        typeFlags.DurationVar(&queryTimeout, "query-timeout", time.Second*15, "Maximum timeout allowed for the database query.")
×
NEW
137
        genTypesCmd.MarkFlagsMutuallyExclusive("linked", "project-id", "query-timeout")
×
138
        genCmd.AddCommand(genTypesCmd)
×
139
        keyFlags := genKeysCmd.Flags()
×
140
        keyFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
141
        keyFlags.StringSliceVar(&override, "override-name", []string{}, "Override specific variable names.")
×
142
        genCmd.AddCommand(genKeysCmd)
×
143
        signingKeyFlags := genSigningKeyCmd.Flags()
×
144
        signingKeyFlags.Var(&algorithm, "algorithm", "Algorithm for signing key generation.")
×
145
        signingKeyFlags.BoolVar(&appendKeys, "append", false, "Append new key to existing keys file instead of overwriting.")
×
146
        genCmd.AddCommand(genSigningKeyCmd)
×
147
        rootCmd.AddCommand(genCmd)
×
148
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc