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

supabase / cli / 8337180401

19 Mar 2024 03:36AM UTC coverage: 58.954%. First build
8337180401

Pull #2035

github

web-flow
feat: added initialisation flag for IntelliJ Deno Config (#2045)

* update: libraries update, gitignore update for intellij

* feat: added flag --with-intellij-settings to create and insert settings for deno in IntelliJ IDEA

* test: added test cases for intellij deno config

* fix: lint issue

* fix: go mod tidy

* Update internal/init/templates/.idea/deno.xml

Co-authored-by: Han Qiao <sweatybridge@gmail.com>

* Update internal/init/init.go

Co-authored-by: Han Qiao <sweatybridge@gmail.com>

* fix: deno config functions reduces

* chore: use utils function to write file

---------

Co-authored-by: Han Qiao <sweatybridge@gmail.com>
Co-authored-by: Qiao Han <qiao@supabase.io>
Pull Request #2035: Prod deploy

156 of 216 new or added lines in 25 files covered. (72.22%)

6255 of 10610 relevant lines covered (58.95%)

689.7 hits per line

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

0.0
/internal/db/remote/commit/commit.go
1
package commit
2

3
import (
4
        "context"
5
        _ "embed"
6
        "errors"
7
        "fmt"
8
        "path/filepath"
9

10
        "github.com/jackc/pgconn"
11
        "github.com/jackc/pgx/v4"
12
        "github.com/spf13/afero"
13
        "github.com/supabase/cli/internal/db/diff"
14
        "github.com/supabase/cli/internal/db/dump"
15
        "github.com/supabase/cli/internal/migration/list"
16
        "github.com/supabase/cli/internal/migration/repair"
17
        "github.com/supabase/cli/internal/utils"
18
)
19

20
func Run(ctx context.Context, schema []string, config pgconn.Config, fsys afero.Fs) error {
×
21
        // Sanity checks.
×
22
        {
×
23
                if err := utils.AssertDockerIsRunning(ctx); err != nil {
×
24
                        return err
×
25
                }
×
26
                if err := utils.LoadConfigFS(fsys); err != nil {
×
27
                        return err
×
28
                }
×
29
        }
30

31
        if err := utils.RunProgram(ctx, func(p utils.Program, ctx context.Context) error {
×
32
                return run(p, ctx, schema, config, fsys)
×
33
        }); err != nil {
×
34
                return err
×
35
        }
×
36

37
        fmt.Println("Finished " + utils.Aqua("supabase db remote commit") + ".")
×
38
        return nil
×
39
}
40

41
func run(p utils.Program, ctx context.Context, schema []string, config pgconn.Config, fsys afero.Fs) error {
×
42
        // 1. Assert `supabase/migrations` and `schema_migrations` are in sync.
×
NEW
43
        w := utils.StatusWriter{Program: p}
×
NEW
44
        conn, err := utils.ConnectByConfigStream(ctx, config, w)
×
45
        if err != nil {
×
46
                return err
×
47
        }
×
48
        defer conn.Close(context.Background())
×
49
        if err := assertRemoteInSync(ctx, conn, fsys); err != nil {
×
50
                return err
×
51
        }
×
52

53
        // 2. Fetch remote schema changes
54
        if len(schema) == 0 {
×
55
                schema, err = diff.LoadUserSchemas(ctx, conn)
×
56
                if err != nil {
×
57
                        return err
×
58
                }
×
59
        }
60
        timestamp := utils.GetCurrentTimestamp()
×
61
        if err := fetchRemote(p, ctx, schema, timestamp, config, fsys); err != nil {
×
62
                return err
×
63
        }
×
64

65
        // 3. Insert a row to `schema_migrations`
66
        return repair.UpdateMigrationTable(ctx, conn, []string{timestamp}, repair.Applied, false, fsys)
×
67
}
68

69
func fetchRemote(p utils.Program, ctx context.Context, schema []string, timestamp string, config pgconn.Config, fsys afero.Fs) error {
×
70
        path := filepath.Join(utils.MigrationsDir, timestamp+"_remote_commit.sql")
×
71
        // Special case if this is the first migration
×
72
        if migrations, err := list.LoadLocalMigrations(fsys); err != nil {
×
73
                return err
×
74
        } else if len(migrations) == 0 {
×
75
                p.Send(utils.StatusMsg("Committing initial migration on remote database..."))
×
76
                return dump.Run(ctx, path, config, nil, nil, false, false, false, false, false, fsys)
×
77
        }
×
78

79
        w := utils.StatusWriter{Program: p}
×
80
        // Diff remote db (source) & shadow db (target) and write it as a new migration.
×
81
        output, err := diff.DiffDatabase(ctx, schema, config, w, fsys, diff.DiffSchemaMigra)
×
82
        if err != nil {
×
83
                return err
×
84
        }
×
85
        if len(output) == 0 {
×
86
                return errors.New("no schema changes found")
×
87
        }
×
88
        return afero.WriteFile(fsys, path, []byte(output), 0644)
×
89
}
90

91
func assertRemoteInSync(ctx context.Context, conn *pgx.Conn, fsys afero.Fs) error {
×
92
        remoteMigrations, err := list.LoadRemoteMigrations(ctx, conn)
×
93
        if err != nil {
×
NEW
94
                return err
×
95
        }
×
96
        localMigrations, err := list.LoadLocalMigrations(fsys)
×
97
        if err != nil {
×
98
                return err
×
99
        }
×
100

101
        conflictErr := errors.New("The remote database's migration history is not in sync with the contents of " + utils.Bold(utils.MigrationsDir) + `. Resolve this by:
×
102
- Updating the project from version control to get the latest ` + utils.Bold(utils.MigrationsDir) + `,
×
103
- Pushing unapplied migrations with ` + utils.Aqua("supabase db push") + `,
×
104
- Or failing that, manually editing supabase_migrations.schema_migrations table with ` + utils.Aqua("supabase migration repair") + ".")
×
105
        if len(remoteMigrations) != len(localMigrations) {
×
106
                return conflictErr
×
107
        }
×
108

109
        for i, remoteTimestamp := range remoteMigrations {
×
110
                // LoadLocalMigrations guarantees we always have a match
×
111
                localTimestamp := utils.MigrateFilePattern.FindStringSubmatch(localMigrations[i])[1]
×
112
                if localTimestamp != remoteTimestamp {
×
113
                        return conflictErr
×
114
                }
×
115
        }
116

117
        return nil
×
118
}
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