• 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

43.04
/internal/db/diff/migra.go
1
package diff
2

3
import (
4
        "bytes"
5
        "context"
6
        _ "embed"
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/pgx/v4"
13
        "github.com/spf13/viper"
14
        "github.com/supabase/cli/internal/gen/types"
15
        "github.com/supabase/cli/internal/utils"
16
        "github.com/supabase/cli/pkg/config"
17
        "github.com/supabase/cli/pkg/migration"
18
)
19

20
var (
21
        //go:embed templates/migra.sh
22
        diffSchemaScript string
23
        //go:embed templates/migra.ts
24
        diffSchemaTypeScript string
25

26
        managedSchemas = []string{
27
                // Local development
28
                "_analytics",
29
                "_realtime",
30
                "_supavisor",
31
                // Owned by extensions
32
                "cron",
33
                "graphql",
34
                "graphql_public",
35
                "net",
36
                "pgroonga",
37
                "pgtle",
38
                "repack",
39
                "tiger_data",
40
                "vault",
41
                // Deprecated extensions
42
                "pgsodium",
43
                "pgsodium_masks",
44
                "timescaledb_experimental",
45
                "timescaledb_information",
46
                "_timescaledb_cache",
47
                "_timescaledb_catalog",
48
                "_timescaledb_config",
49
                "_timescaledb_debug",
50
                "_timescaledb_functions",
51
                "_timescaledb_internal",
52
                // Managed by Supabase
53
                "pgbouncer",
54
                "supabase_functions",
55
                "supabase_migrations",
56
        }
57
)
58

59
// Diffs local database schema against shadow, dumps output to stdout.
60
func DiffSchemaMigraBash(ctx context.Context, source, target string, schema []string, options ...func(*pgx.ConnConfig)) (string, error) {
×
61
        // Load all user defined schemas
×
62
        if len(schema) == 0 {
×
63
                var err error
×
64
                if schema, err = loadSchema(ctx, target, options...); err != nil {
×
65
                        return "", err
×
66
                }
×
67
        }
68
        env := []string{"SOURCE=" + source, "TARGET=" + target}
×
69
        // Passing in script string means command line args must be set manually, ie. "$@"
×
70
        args := "set -- " + strings.Join(schema, " ") + ";"
×
71
        cmd := []string{"/bin/sh", "-c", args + diffSchemaScript}
×
72
        var out, stderr bytes.Buffer
×
73
        if err := utils.DockerRunOnceWithConfig(
×
74
                ctx,
×
75
                container.Config{
×
76
                        Image: config.Images.Migra,
×
77
                        Env:   env,
×
78
                        Cmd:   cmd,
×
79
                },
×
80
                container.HostConfig{
×
81
                        NetworkMode: network.NetworkHost,
×
82
                },
×
83
                network.NetworkingConfig{},
×
84
                "",
×
85
                &out,
×
86
                &stderr,
×
87
        ); err != nil {
×
88
                return "", errors.Errorf("error diffing schema: %w:\n%s", err, stderr.String())
×
89
        }
×
90
        return out.String(), nil
×
91
}
92

93
func loadSchema(ctx context.Context, dbURL string, options ...func(*pgx.ConnConfig)) ([]string, error) {
×
94
        conn, err := utils.ConnectByUrl(ctx, dbURL, options...)
×
95
        if err != nil {
×
96
                return nil, err
×
97
        }
×
98
        defer conn.Close(context.Background())
×
99
        // RLS policies in auth and storage schemas can be included with -s flag
×
100
        return migration.ListUserSchemas(ctx, conn)
×
101
}
102

103
func DiffSchemaMigra(ctx context.Context, source, target string, schema []string, options ...func(*pgx.ConnConfig)) (string, error) {
2✔
104
        env := []string{"SOURCE=" + source, "TARGET=" + target}
2✔
105
        if ca, err := types.GetRootCA(ctx, target, options...); err != nil {
2✔
UNCOV
106
                return "", err
×
107
        } else if len(ca) > 0 {
2✔
NEW
108
                env = append(env, "SSL_CA="+ca)
×
UNCOV
109
        }
×
110
        if len(schema) > 0 {
4✔
111
                env = append(env, "INCLUDED_SCHEMAS="+strings.Join(schema, ","))
2✔
112
        } else {
2✔
113
                env = append(env, "EXCLUDED_SCHEMAS="+strings.Join(managedSchemas, ","))
×
114
        }
×
115
        cmd := []string{"edge-runtime", "start", "--main-service=."}
2✔
116
        if viper.GetBool("DEBUG") {
2✔
117
                cmd = append(cmd, "--verbose")
×
118
        }
×
119
        cmdString := strings.Join(cmd, " ")
2✔
120
        entrypoint := []string{"sh", "-c", `cat <<'EOF' > index.ts && ` + cmdString + `
2✔
121
` + diffSchemaTypeScript + `
2✔
122
EOF
2✔
123
`}
2✔
124
        var out, stderr bytes.Buffer
2✔
125
        if err := utils.DockerRunOnceWithConfig(
2✔
126
                ctx,
2✔
127
                container.Config{
2✔
128
                        Image:      utils.Config.EdgeRuntime.Image,
2✔
129
                        Env:        env,
2✔
130
                        Entrypoint: entrypoint,
2✔
131
                },
2✔
132
                container.HostConfig{
2✔
133
                        Binds:       []string{utils.EdgeRuntimeId + ":/root/.cache/deno:rw"},
2✔
134
                        NetworkMode: network.NetworkHost,
2✔
135
                },
2✔
136
                network.NetworkingConfig{},
2✔
137
                "",
2✔
138
                &out,
2✔
139
                &stderr,
2✔
140
        ); err != nil && !strings.HasPrefix(stderr.String(), "main worker has been destroyed") {
3✔
141
                return "", errors.Errorf("error diffing schema: %w:\n%s", err, stderr.String())
1✔
142
        }
1✔
143
        return out.String(), nil
1✔
144
}
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