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

supabase / cli / 5072142569

24 May 2023 06:27PM UTC coverage: 62.969% (+0.01%) from 62.956%
5072142569

Pull #1145

github

Qiao Han
chore: do not map remote db password
Pull Request #1145: fix: use db password everywhere

30 of 30 new or added lines in 8 files covered. (100.0%)

4513 of 7167 relevant lines covered (62.97%)

1006.67 hits per line

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

58.82
/internal/migration/up/up.go
1
package up
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7

8
        "github.com/jackc/pgconn"
9
        "github.com/jackc/pgx/v4"
10
        "github.com/spf13/afero"
11
        "github.com/supabase/cli/internal/migration/apply"
12
        "github.com/supabase/cli/internal/migration/list"
13
        "github.com/supabase/cli/internal/utils"
14
)
15

16
var errConflict = errors.New("supabase_migrations.schema_migrations table conflicts with the contents of " + utils.Bold(utils.MigrationsDir) + ".")
17

18
func Run(ctx context.Context, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
×
19
        if err := utils.LoadConfigFS(fsys); err != nil {
×
20
                return err
×
21
        }
×
22
        conn, err := utils.ConnectLocalPostgres(ctx, pgconn.Config{}, options...)
×
23
        if err != nil {
×
24
                return err
×
25
        }
×
26
        defer conn.Close(context.Background())
×
27
        pending, err := GetPendingMigrations(ctx, conn, fsys)
×
28
        if err != nil {
×
29
                return err
×
30
        }
×
31
        return apply.MigrateUp(ctx, conn, pending, fsys)
×
32
}
33

34
func GetPendingMigrations(ctx context.Context, conn *pgx.Conn, fsys afero.Fs) ([]string, error) {
9✔
35
        remoteMigrations, err := list.LoadRemoteMigrations(ctx, conn)
9✔
36
        if err != nil {
10✔
37
                return nil, err
1✔
38
        }
1✔
39
        localMigrations, err := list.LoadLocalMigrations(fsys)
8✔
40
        if err != nil {
9✔
41
                return nil, err
1✔
42
        }
1✔
43
        // Check remote is in-sync or behind local
44
        if len(remoteMigrations) > len(localMigrations) {
8✔
45
                return nil, fmt.Errorf("%w; Found %d versions and %d migrations.", errConflict, len(remoteMigrations), len(localMigrations))
1✔
46
        }
1✔
47
        for i, remote := range remoteMigrations {
9✔
48
                filename := localMigrations[i]
3✔
49
                // LoadLocalMigrations guarantees we always have a match
3✔
50
                local := utils.MigrateFilePattern.FindStringSubmatch(filename)[1]
3✔
51
                if remote != local {
4✔
52
                        return nil, fmt.Errorf("%w; Expected version %s but found migration %s at index %d.", errConflict, remote, filename, i)
1✔
53
                }
1✔
54
        }
55
        return localMigrations[len(remoteMigrations):], nil
5✔
56
}
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