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

supabase / cli / 8666347059

12 Apr 2024 06:20PM UTC coverage: 57.73%. First build
8666347059

Pull #2134

github

sweatybridge
chore: bold created project url
Pull Request #2134: Prod deploy

14 of 100 new or added lines in 25 files covered. (14.0%)

6378 of 11048 relevant lines covered (57.73%)

662.63 hits per line

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

0.0
/internal/inspect/role_connections/role_connections.go
1
package role_connections
2

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

7
        "github.com/go-errors/errors"
8
        "github.com/jackc/pgconn"
9
        "github.com/jackc/pgx/v4"
10
        "github.com/spf13/afero"
11
        "github.com/supabase/cli/internal/inspect"
12
        "github.com/supabase/cli/internal/migration/list"
13
        "github.com/supabase/cli/internal/utils"
14
        "github.com/supabase/cli/internal/utils/pgxv5"
15
)
16

17
type Result struct {
18
        Rolname            string
19
        Active_connections int
20
        Connection_limit   int
21
}
22

23
func Run(ctx context.Context, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
×
24
        conn, err := utils.ConnectByConfig(ctx, config, options...)
×
25
        if err != nil {
×
26
                return err
×
27
        }
×
NEW
28
        rows, err := conn.Query(ctx, inspect.ROLE_CONNECTIONS_QUERY)
×
29
        if err != nil {
×
30
                return errors.Errorf("failed to query rows: %w", err)
×
31
        }
×
32
        result, err := pgxv5.CollectRows[Result](rows)
×
33
        if err != nil {
×
34
                return err
×
35
        }
×
36

37
        table := "|Role Name|Active connction|\n|-|-|\n"
×
38
        sum := 0
×
39
        for _, r := range result {
×
40
                table += fmt.Sprintf("|`%s`|`%d`|\n", r.Rolname, r.Active_connections)
×
41
                sum += r.Active_connections
×
42
        }
×
43

44
        if err := list.RenderTable(table); err != nil {
×
45
                return err
×
46
        }
×
47

48
        if len(result) > 0 {
×
49
                fmt.Printf("\nActive connections %d/%d\n\n", sum, result[0].Connection_limit)
×
50
        }
×
51

52
        if matches := utils.ProjectHostPattern.FindStringSubmatch(config.Host); len(matches) == 4 {
×
53
                fmt.Println("Go to the dashboard for more here:")
×
54
                fmt.Printf("https://app.supabase.com/project/%s/database/roles\n", matches[2])
×
55
        }
×
56

57
        return nil
×
58
}
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