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

supabase / cli / 8043495358

26 Feb 2024 04:02AM UTC coverage: 58.842% (-0.02%) from 58.864%
8043495358

Pull #1990

github

sweatybridge
chore: fix unit tests
Pull Request #1990: fix: check for sslmode explicitly when generating types

13 of 17 new or added lines in 2 files covered. (76.47%)

6 existing lines in 2 files now uncovered.

6189 of 10518 relevant lines covered (58.84%)

689.93 hits per line

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

39.13
/cmd/gen.go
1
package cmd
2

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

8
        env "github.com/Netflix/go-env"
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/typescript"
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
        keyOutput = utils.EnumFlag{
26
                Allowed: []string{
27
                        utils.OutputEnv,
28
                        utils.OutputJson,
29
                        utils.OutputToml,
30
                        utils.OutputYaml,
31
                },
32
                Value: utils.OutputEnv,
33
        }
34

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

54
        genTypesCmd = &cobra.Command{
55
                Use:   "types",
56
                Short: "Generate types from Postgres schema",
57
        }
58

59
        postgrestV9Compat bool
60

61
        genTypesTypescriptCmd = &cobra.Command{
62
                Use:   "typescript",
63
                Short: "Generate types for TypeScript",
64
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
65
                        if postgrestV9Compat && !cmd.Flags().Changed("db-url") {
×
66
                                return errors.New("--postgrest-v9-compat can only be used together with --db-url.")
×
67
                        }
×
68
                        return nil
×
69
                },
70
                RunE: func(cmd *cobra.Command, args []string) error {
×
NEW
71
                        ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
×
72
                        if flags.DbConfig.Host == "" {
×
73
                                // If no flag is specified, prompt for project id.
×
74
                                if err := flags.ParseProjectRef(ctx, afero.NewMemMapFs()); errors.Is(err, utils.ErrNotLinked) {
×
75
                                        return errors.New("Must specify one of --local, --linked, --project-id, or --db-url")
×
76
                                } else if err != nil {
×
77
                                        return err
×
78
                                }
×
79
                        }
80
                        return typescript.Run(ctx, flags.ProjectRef, flags.DbConfig, schema, postgrestV9Compat, afero.NewOsFs())
×
81
                },
82
                Example: `  supabase gen types typescript --local
83
  supabase gen types typescript --linked
84
  supabase gen types typescript --project-id abc-def-123 --schema public --schema private
85
  supabase gen types typescript --db-url 'postgresql://...' --schema public --schema auth`,
86
        }
87
)
88

89
func init() {
1✔
90
        genFlags := genTypesTypescriptCmd.Flags()
1✔
91
        genFlags.Bool("local", false, "Generate types from the local dev database.")
1✔
92
        genFlags.Bool("linked", false, "Generate types from the linked project.")
1✔
93
        genFlags.String("db-url", "", "Generate types from a database url.")
1✔
94
        genFlags.StringVar(&flags.ProjectRef, "project-id", "", "Generate types from a project ID.")
1✔
95
        genTypesTypescriptCmd.MarkFlagsMutuallyExclusive("local", "linked", "project-id", "db-url")
1✔
96
        genFlags.StringSliceVarP(&schema, "schema", "s", []string{}, "Comma separated list of schema to include.")
1✔
97
        genFlags.BoolVar(&postgrestV9Compat, "postgrest-v9-compat", false, "Generate types compatible with PostgREST v9 and below. Only use together with --db-url.")
1✔
98
        genTypesCmd.AddCommand(genTypesTypescriptCmd)
1✔
99
        genCmd.AddCommand(genTypesCmd)
1✔
100
        keyFlags := genKeysCmd.Flags()
1✔
101
        keyFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
1✔
102
        keyFlags.VarP(&keyOutput, "output", "o", "Output format of key variables.")
1✔
103
        keyFlags.StringSliceVar(&override, "override-name", []string{}, "Override specific variable names.")
1✔
104
        genCmd.AddCommand(genKeysCmd)
1✔
105
        rootCmd.AddCommand(genCmd)
1✔
106
}
1✔
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