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

supabase / cli / 16189480091

10 Jul 2025 07:59AM UTC coverage: 55.516% (-0.04%) from 55.551%
16189480091

Pull #3602

github

web-flow
Merge da972ff45 into 0d1caf9c4
Pull Request #3602: feat(typegen): add postgrest-version params

4 of 9 new or added lines in 2 files covered. (44.44%)

5 existing lines in 1 file now uncovered.

6079 of 10950 relevant lines covered (55.52%)

6.25 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

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

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

24
        keyNames keys.CustomName
25

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

49
        lang = utils.EnumFlag{
50
                Allowed: []string{
51
                        types.LangTypescript,
52
                        types.LangGo,
53
                        types.LangSwift,
54
                },
55
                Value: types.LangTypescript,
56
        }
57
        postgrestV9Compat  bool
58
        postgrestVersion   string
59
        swiftAccessControl = utils.EnumFlag{
60
                Allowed: []string{
61
                        types.SwiftInternalAccessControl,
62
                        types.SwiftPublicAccessControl,
63
                },
64
                Value: types.SwiftInternalAccessControl,
65
        }
66

67
        genTypesCmd = &cobra.Command{
68
                Use:   "types",
69
                Short: "Generate types from Postgres schema",
70
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
71
                        if postgrestV9Compat && !cmd.Flags().Changed("db-url") {
×
72
                                return errors.New("--postgrest-v9-compat must used together with --db-url")
×
73
                        }
×
NEW
74
                        if postgrestVersion != "" && !cmd.Flags().Changed("db-url") {
×
NEW
75
                                return errors.New("--postgrest-version must used together with --db-url")
×
NEW
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, postgrestVersion, swiftAccessControl.Value, 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

102
func init() {
×
103
        typeFlags := genTypesCmd.Flags()
×
104
        typeFlags.Bool("local", false, "Generate types from the local dev database.")
×
105
        typeFlags.Bool("linked", false, "Generate types from the linked project.")
×
106
        typeFlags.String("db-url", "", "Generate types from a database url.")
×
107
        typeFlags.StringVar(&flags.ProjectRef, "project-id", "", "Generate types from a project ID.")
×
108
        genTypesCmd.MarkFlagsMutuallyExclusive("local", "linked", "project-id", "db-url")
×
109
        typeFlags.Var(&lang, "lang", "Output language of the generated types.")
×
110
        typeFlags.StringSliceVarP(&schema, "schema", "s", []string{}, "Comma separated list of schema to include.")
×
111
        typeFlags.Var(&swiftAccessControl, "swift-access-control", "Access control for Swift generated types.")
×
112
        typeFlags.BoolVar(&postgrestV9Compat, "postgrest-v9-compat", false, "Generate types compatible with PostgREST v9 and below. Only use together with --db-url.")
×
NEW
113
        typeFlags.StringVar(&postgrestVersion, "postgrest-version", "", "Generate types with __InternalSupabase schema using the right version of postgrest. Only use together with --db-url.")
×
114
        genCmd.AddCommand(genTypesCmd)
×
115
        keyFlags := genKeysCmd.Flags()
×
116
        keyFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
117
        keyFlags.StringSliceVar(&override, "override-name", []string{}, "Override specific variable names.")
×
118
        genCmd.AddCommand(genKeysCmd)
×
119
        rootCmd.AddCommand(genCmd)
×
120
}
×
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