Skip to content

Commit

Permalink
fix display of p tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Jun 14, 2024
1 parent 61567c8 commit 7c5cb00
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion flow/cmd/peer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

connpostgres "github.com/PeerDB-io/peer-flow/connectors/postgres"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/shared"
)

func (h *FlowRequestHandler) getPGPeerConfig(ctx context.Context, peerName string) (*protos.PostgresConfig, error) {
Expand Down Expand Up @@ -87,14 +88,27 @@ func (h *FlowRequestHandler) GetTablesInSchema(
defer tunnel.Close()
defer peerConn.Close(ctx)

pgVersion, err := shared.GetMajorVersion(ctx, peerConn)
if err != nil {
slog.Error("unable to get pgversion for schema tables", slog.Any("error", err))
return &protos.SchemaTablesResponse{Tables: nil}, err
}

relKindFilterClause := "t.relkind IN ('r', 'p')"
if pgVersion <= shared.POSTGRES_12 {
relKindFilterClause = "t.relkind = 'r'"
}

rows, err := peerConn.Query(ctx, `SELECT DISTINCT ON (t.relname)
t.relname,
(con.contype = 'p' OR t.relreplident in ('i', 'f')) AS can_mirror,
pg_size_pretty(pg_total_relation_size(t.oid))::text AS table_size
FROM pg_class t
LEFT JOIN pg_namespace n ON t.relnamespace = n.oid
LEFT JOIN pg_constraint con ON con.conrelid = t.oid
WHERE n.nspname = $1 AND t.relkind = 'r' ORDER BY t.relname, can_mirror DESC;
WHERE n.nspname = $1 AND `+
relKindFilterClause+
`AND t.relispartition IS NOT TRUE ORDER BY t.relname, can_mirror DESC;
`, req.SchemaName)
if err != nil {
slog.Info("failed to fetch publications", slog.Any("error", err))
Expand Down

0 comments on commit 7c5cb00

Please sign in to comment.