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

supabase / cli / 8043579157

23 Feb 2024 11:24AM UTC coverage: 58.859% (-0.005%) from 58.864%
8043579157

Pull #1986

github

felixgabler
fix: resolve openai key as env variable
Pull Request #1986: feat: enable Supabase AI during local development

2 of 2 new or added lines in 2 files covered. (100.0%)

15 existing lines in 3 files now uncovered.

6192 of 10520 relevant lines covered (58.86%)

689.82 hits per line

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

96.92
/internal/gen/types/typescript/typescript.go
1
package typescript
2

3
import (
4
        "context"
5
        "fmt"
6
        "os"
7
        "strings"
8

9
        "github.com/docker/docker/api/types/container"
10
        "github.com/docker/docker/api/types/network"
11
        "github.com/go-errors/errors"
12
        "github.com/jackc/pgconn"
13
        "github.com/spf13/afero"
14
        "github.com/supabase/cli/internal/utils"
15
        "github.com/supabase/cli/pkg/api"
16
)
17

18
func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, schemas []string, postgrestV9Compat bool, fsys afero.Fs) error {
19
        // Add default schemas if --schema flag is not specified
7✔
20
        if len(schemas) == 0 {
7✔
21
                schemas = utils.RemoveDuplicates(append([]string{"public"}, utils.Config.Api.Schemas...))
13✔
22
        }
6✔
23
        included := strings.Join(schemas, ",")
6✔
24

7✔
25
        if projectId != "" {
7✔
26
                resp, err := utils.GetSupabase().GetTypescriptTypesWithResponse(ctx, projectId, &api.GetTypescriptTypesParams{
10✔
27
                        IncludedSchemas: &included,
3✔
28
                })
3✔
29
                if err != nil {
3✔
30
                        return errors.Errorf("failed to get typescript types: %w", err)
4✔
31
                }
1✔
32

1✔
33
                if resp.JSON200 == nil {
34
                        return errors.New("failed to retrieve generated types: " + string(resp.Body))
3✔
35
                }
1✔
36

1✔
37
                fmt.Print(resp.JSON200.Types)
38
                return nil
1✔
39
        }
1✔
40

41
        if utils.IsLocalDatabase(dbConfig) {
42
                if err := utils.AssertSupabaseDbIsRunning(); err != nil {
7✔
43
                        return err
4✔
44
                }
1✔
45

1✔
46
                if strings.Contains(utils.Config.Api.Image, "v9") {
47
                        postgrestV9Compat = true
3✔
48
                }
1✔
49
        } else {
1✔
50
                // Additional configs for pg-meta with enforce ssl
51
                if dbConfig.RuntimeParams == nil {
52
                        dbConfig.RuntimeParams = make(map[string]string, 1)
3✔
53
                }
5✔
54
                dbConfig.RuntimeParams["sslmode"] = "prefer"
2✔
55
        }
2✔
56

3✔
57
        fmt.Fprintln(os.Stderr, "Connecting to", dbConfig.Host, dbConfig.Port)
4✔
58
        if len(dbConfig.Database) == 0 {
1✔
59
                dbConfig.Database = "postgres"
5✔
60
        }
2✔
61
        escaped := utils.ToPostgresURL(dbConfig)
2✔
62
        return utils.DockerRunOnceWithConfig(
2✔
63
                ctx,
64
                container.Config{
2✔
65
                        Image: utils.PgmetaImage,
2✔
66
                        Env: []string{
2✔
67
                                "PG_META_DB_URL=" + escaped,
2✔
68
                                "PG_META_GENERATE_TYPES=typescript",
2✔
69
                                "PG_META_GENERATE_TYPES_INCLUDED_SCHEMAS=" + included,
2✔
70
                                fmt.Sprintf("PG_META_GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS=%v", !postgrestV9Compat),
2✔
71
                        },
2✔
72
                        Cmd: []string{"node", "dist/server/server.js"},
2✔
73
                },
2✔
74
                container.HostConfig{
2✔
75
                        NetworkMode: container.NetworkMode("host"),
2✔
76
                },
2✔
77
                network.NetworkingConfig{},
2✔
78
                "",
2✔
79
                os.Stdout,
2✔
80
                os.Stderr,
2✔
81
        )
2✔
82
}
2✔
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