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

supabase / cli / 9443940279

10 Jun 2024 07:06AM UTC coverage: 60.056% (-0.1%) from 60.152%
9443940279

push

github

sweatybridge
chore: use fetcher for validating sso metadata

0 of 9 new or added lines in 1 file covered. (0.0%)

235 existing lines in 11 files now uncovered.

6907 of 11501 relevant lines covered (60.06%)

633.21 hits per line

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

8.97
/internal/db/diff/pgadmin.go
1
package diff
2

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

9
        "github.com/jackc/pgconn"
10
        "github.com/spf13/afero"
11
        "github.com/supabase/cli/internal/db/start"
12
        "github.com/supabase/cli/internal/migration/new"
13
        "github.com/supabase/cli/internal/utils"
14
)
15

16
var warnDiff = `WARNING: The diff tool is not foolproof, so you may need to manually rearrange and modify the generated migration.
17
Run ` + utils.Aqua("supabase db reset") + ` to verify that the new migration does not generate errors.`
18

19
func SaveDiff(out, file string, fsys afero.Fs) error {
1✔
20
        if len(out) < 2 {
1✔
UNCOV
21
                fmt.Fprintln(os.Stderr, "No schema changes found")
×
22
        } else if len(file) > 0 {
2✔
23
                path := new.GetMigrationPath(utils.GetCurrentTimestamp(), file)
1✔
24
                if err := utils.WriteFile(path, []byte(out), fsys); err != nil {
1✔
UNCOV
25
                        return err
×
26
                }
×
27
                fmt.Fprintln(os.Stderr, warnDiff)
1✔
UNCOV
28
        } else {
×
29
                fmt.Println(out)
×
30
        }
×
31
        return nil
1✔
32
}
33

UNCOV
34
func RunPgAdmin(ctx context.Context, schema []string, file string, config pgconn.Config, fsys afero.Fs) error {
×
35
        // Sanity checks.
×
36
        {
×
37
                if err := utils.LoadConfigFS(fsys); err != nil {
×
38
                        return err
×
39
                }
×
40
                if err := utils.AssertSupabaseDbIsRunning(); err != nil {
×
41
                        return err
×
42
                }
×
43
        }
44

UNCOV
45
        if err := utils.RunProgram(ctx, func(p utils.Program, ctx context.Context) error {
×
46
                return run(p, ctx, schema, config, fsys)
×
47
        }); err != nil {
×
48
                return err
×
49
        }
×
50

UNCOV
51
        return SaveDiff(output, file, fsys)
×
52
}
53

54
var output string
55

UNCOV
56
func run(p utils.Program, ctx context.Context, schema []string, config pgconn.Config, fsys afero.Fs) error {
×
57
        p.Send(utils.StatusMsg("Creating shadow database..."))
×
58

×
59
        // 1. Create shadow db and run migrations
×
60
        shadow, err := CreateShadowDatabase(ctx, utils.Config.Db.ShadowPort)
×
61
        if err != nil {
×
62
                return err
×
63
        }
×
64
        defer utils.DockerRemove(shadow)
×
65
        if err := start.WaitForHealthyService(ctx, start.HealthTimeout, shadow); err != nil {
×
66
                return err
×
67
        }
×
68
        if err := MigrateShadowDatabase(ctx, shadow, fsys); err != nil {
×
69
                return err
×
70
        }
×
71

UNCOV
72
        p.Send(utils.StatusMsg("Diffing local database with current migrations..."))
×
73

×
74
        // 2. Diff local db (source) with shadow db (target), print it.
×
75
        source := utils.ToPostgresURL(config)
×
76
        target := fmt.Sprintf("postgresql://postgres:postgres@127.0.0.1:%d/postgres", utils.Config.Db.ShadowPort)
×
77
        output, err = DiffSchemaPgAdmin(ctx, source, target, schema, p)
×
78
        return err
×
79
}
80

UNCOV
81
func DiffSchemaPgAdmin(ctx context.Context, source, target string, schema []string, p utils.Program) (string, error) {
×
82
        stream := utils.NewDiffStream(p)
×
83
        args := []string{"--json-diff", source, target}
×
84
        if len(schema) == 0 {
×
85
                if err := utils.DockerRunOnceWithStream(
×
86
                        ctx,
×
87
                        utils.DifferImage,
×
88
                        nil,
×
89
                        args,
×
90
                        stream.Stdout(),
×
91
                        stream.Stderr(),
×
92
                ); err != nil {
×
93
                        return "", err
×
94
                }
×
95
        }
UNCOV
96
        for _, s := range schema {
×
97
                p.Send(utils.StatusMsg("Diffing schema: " + s))
×
98
                if err := utils.DockerRunOnceWithStream(
×
99
                        ctx,
×
100
                        utils.DifferImage,
×
101
                        nil,
×
102
                        append([]string{"--schema", s}, args...),
×
103
                        stream.Stdout(),
×
104
                        stream.Stderr(),
×
105
                ); err != nil {
×
106
                        return "", err
×
107
                }
×
108
        }
UNCOV
109
        diffBytes, err := stream.Collect()
×
110
        return string(diffBytes), err
×
111
}
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

© 2026 Coveralls, Inc