publications.ts40 lines · main
1import { safeSql } from '../pg-format'
2
3export const PUBLICATIONS_SQL = /* SQL */ safeSql`
4SELECT
5 p.oid :: int8 AS id,
6 p.pubname AS name,
7 p.pubowner::regrole::text AS owner,
8 p.pubinsert AS publish_insert,
9 p.pubupdate AS publish_update,
10 p.pubdelete AS publish_delete,
11 p.pubtruncate AS publish_truncate,
12 CASE
13 WHEN p.puballtables THEN NULL
14 ELSE pr.tables
15 END AS tables
16FROM
17 pg_catalog.pg_publication AS p
18 LEFT JOIN LATERAL (
19 SELECT
20 COALESCE(
21 array_agg(
22 json_build_object(
23 'id',
24 c.oid :: int8,
25 'name',
26 c.relname,
27 'schema',
28 nc.nspname
29 )
30 ),
31 '{}'
32 ) AS tables
33 FROM
34 pg_catalog.pg_publication_rel AS pr
35 JOIN pg_class AS c ON pr.prrelid = c.oid
36 join pg_namespace as nc on c.relnamespace = nc.oid
37 WHERE
38 pr.prpubid = p.oid
39 ) AS pr ON 1 = 1
40`