Skip to content

Commit

Permalink
UI: Fix display of partitioned tables (#1841)
Browse files Browse the repository at this point in the history
```
t.relispartition IS NOT TRUE ORDER BY t.relname, can_mirror DESC;
```
this is so that we only show the root table as we use
publish_via_partition_root
  • Loading branch information
Amogh-Bharadwaj authored Jun 14, 2024
1 parent 532ef98 commit f04d242
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 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,28 @@ 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')"
// publish_via_partition_root is only available in PG13 and above
if pgVersion <= shared.POSTGRES_13 {
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 f04d242

Please sign in to comment.