Skip to content

Commit

Permalink
qrep: list views, materialized views, & foreign tables in drop down (#…
Browse files Browse the repository at this point in the history
…1550)

Runs into issues with GetTableSchema when trying to create table on destination
  • Loading branch information
serprex authored Mar 28, 2024
1 parent 1faf6a5 commit bb8545a
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions flow/cmd/peer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,14 @@ func (h *FlowRequestHandler) GetTablesInSchema(
defer peerConn.Close(ctx)

rows, err := peerConn.Query(ctx, `SELECT DISTINCT ON (t.relname)
t.relname,
CASE
WHEN con.contype = 'p' OR t.relreplident = 'i' OR t.relreplident = 'f' THEN true
ELSE false
END 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 AND con.contype = 'p'
WHERE
n.nspname = $1
AND
t.relkind = 'r'
ORDER BY
t.relname,
can_mirror DESC;
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 AND con.contype = 'p'
WHERE n.nspname = $1 AND t.relkind = 'r'
ORDER BY t.relname, can_mirror DESC;
`, req.SchemaName)
if err != nil {
slog.Info("failed to fetch publications", slog.Any("error", err))
Expand Down Expand Up @@ -161,7 +150,7 @@ func (h *FlowRequestHandler) GetAllTables(
rows, err := peerConn.Query(ctx, "SELECT n.nspname || '.' || c.relname AS schema_table "+
"FROM pg_class c "+
"JOIN pg_namespace n ON c.relnamespace = n.oid "+
"WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' AND c.relkind = 'r';")
"WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' AND c.relkind IN ('r', 'v', 'm', 'f');")
if err != nil {
return &protos.AllTablesResponse{Tables: nil}, err
}
Expand Down

0 comments on commit bb8545a

Please sign in to comment.