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

supabase / cli / 3572813994

04 Dec 2022 06:36PM UTC coverage: 54.923% (-2.8%) from 57.76%
3572813994

Pull #648

github

Kevin Saliou
chore: remove all tabs & trailing spaces from SQL files
Pull Request #648: chore: remove all tabs & trailing spaces from SQL files

3057 of 5566 relevant lines covered (54.92%)

498.14 hits per line

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

28.57
/internal/link/link.go
1
package link
2

3
import (
4
        "context"
5
        "errors"
6
        "path/filepath"
7

8
        "github.com/spf13/afero"
9
        "github.com/supabase/cli/internal/db/remote/commit"
10
        "github.com/supabase/cli/internal/utils"
11
)
12

13
func Run(ctx context.Context, projectRef, username, password, database string, fsys afero.Fs) error {
×
14
        // 1. Validate access token + project ref
×
15
        if err := validateProjectRef(ctx, projectRef, fsys); err != nil {
×
16
                return err
×
17
        }
×
18
        if err := utils.LoadConfigFS(fsys); err != nil {
×
19
                return err
×
20
        }
×
21

22
        // 2. Check database connection
23
        {
×
24
                conn, err := commit.ConnectRemotePostgres(ctx, username, password, database, utils.GetSupabaseDbHost(projectRef))
×
25
                if err != nil {
×
26
                        return err
×
27
                }
×
28
                defer conn.Close(context.Background())
×
29
                // Assert db.major_version is compatible.
×
30
                if err := commit.AssertPostgresVersionMatch(conn); err != nil {
×
31
                        return err
×
32
                }
×
33
                // If `schema_migrations` doesn't exist on the remote database, create it.
34
                if _, err := conn.Exec(ctx, commit.CHECK_MIGRATION_EXISTS); err != nil {
×
35
                        if _, err := conn.Exec(ctx, commit.CREATE_MIGRATION_TABLE); err != nil {
×
36
                                return err
×
37
                        }
×
38
                }
39
        }
40

41
        // 2. Save project ref
42
        {
×
43
                if err := utils.MkdirIfNotExistFS(fsys, filepath.Dir(utils.ProjectRefPath)); err != nil {
×
44
                        return err
×
45
                }
×
46
                if err := afero.WriteFile(fsys, utils.ProjectRefPath, []byte(projectRef), 0644); err != nil {
×
47
                        return err
×
48
                }
×
49
        }
50

51
        return nil
×
52
}
53

54
func validateProjectRef(ctx context.Context, projectRef string, fsys afero.Fs) error {
5✔
55
        if !utils.ProjectRefPattern.MatchString(projectRef) {
6✔
56
                return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.")
1✔
57
        }
1✔
58

59
        resp, err := utils.GetSupabase().GetFunctionsWithResponse(ctx, projectRef)
4✔
60
        if err != nil {
5✔
61
                return err
1✔
62
        }
1✔
63

64
        if resp.JSON200 == nil {
5✔
65
                return errors.New("Authorization failed for the access token and project ref pair: " + string(resp.Body))
2✔
66
        }
2✔
67

68
        return nil
1✔
69
}
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