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

supabase / cli / 13392899334

18 Feb 2025 02:28PM UTC coverage: 58.349% (+0.07%) from 58.278%
13392899334

push

github

sweatybridge
chore: remove unnecessary config load

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

252 existing lines in 9 files now uncovered.

7789 of 13349 relevant lines covered (58.35%)

201.84 hits per line

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

9.46
/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
        "github.com/supabase/cli/pkg/config"
15
)
16

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

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

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

41
        if err := utils.RunProgram(ctx, func(p utils.Program, ctx context.Context) error {
×
42
                return run(p, ctx, schema, config, fsys)
×
43
        }); err != nil {
×
44
                return err
×
45
        }
×
46

47
        return SaveDiff(output, file, fsys)
×
48
}
49

50
var output string
51

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

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

68
        p.Send(utils.StatusMsg("Diffing local database with current migrations..."))
×
69

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

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