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

supabase / cli / 12707310256

10 Jan 2025 10:00AM UTC coverage: 58.531% (-0.09%) from 58.616%
12707310256

push

github

web-flow
fix: unmarshal remote override into base config (#3028)

* fix: unmarshal remote override into base config

* chore: account for project ref flag when loading config

* fix: restore project id from base config

36 of 76 new or added lines in 27 files covered. (47.37%)

13 existing lines in 2 files now uncovered.

7588 of 12964 relevant lines covered (58.53%)

202.7 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
        "github.com/supabase/cli/internal/utils/flags"
15
        "github.com/supabase/cli/pkg/config"
16
)
17

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

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

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

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

53
        return SaveDiff(output, file, fsys)
×
54
}
55

56
var output string
57

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

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

74
        p.Send(utils.StatusMsg("Diffing local database with current migrations..."))
×
75

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

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