neon 8.4.5 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +7 -7
  2. package/dist/_chunks/{env-4WGRW2nw.js → env-BNm69Qh8.js} +2 -5
  3. package/dist/commands/config.js +11 -28
  4. package/dist/commands/dev.js +1 -1
  5. package/dist/commands/env.js +2 -3
  6. package/dist/commands/init.js +1 -2
  7. package/dist/commands/manifest.js +1 -3
  8. package/dist/commands/subscribe.js +16 -16
  9. package/dist/credential_io.js +1 -2
  10. package/dist/dev/env.js +1 -2
  11. package/dist/index.js +1 -1
  12. package/dist/init/run.js +1 -2
  13. package/dist/plugins/run.js +2 -1
  14. package/dist/psql/command/cmd_io.js +1 -2
  15. package/dist/psql/command/cmd_pipeline.js +1 -2
  16. package/dist/psql/core/common.js +1 -2
  17. package/dist/psql/core/startup.js +1 -2
  18. package/dist/psql/index.js +1 -2
  19. package/dist/psql/types/index.js +1 -2
  20. package/dist/skills/catalog.js +5 -0
  21. package/dist/utils/hooks.js +0 -2
  22. package/dist/utils/staging.js +1 -14
  23. package/{LICENSE → dist/vendor/postgres-meta/LICENSE} +0 -1
  24. package/dist/vendor/postgres-meta/constants.js +14 -0
  25. package/dist/vendor/postgres-meta/lib/PostgresMeta.js +49 -0
  26. package/dist/vendor/postgres-meta/lib/PostgresMetaColumnPrivileges.js +85 -0
  27. package/dist/vendor/postgres-meta/lib/PostgresMetaColumns.js +235 -0
  28. package/dist/vendor/postgres-meta/lib/PostgresMetaConfig.js +16 -0
  29. package/dist/vendor/postgres-meta/lib/PostgresMetaExtensions.js +79 -0
  30. package/dist/vendor/postgres-meta/lib/PostgresMetaForeignTables.js +81 -0
  31. package/dist/vendor/postgres-meta/lib/PostgresMetaFunctions.js +173 -0
  32. package/dist/vendor/postgres-meta/lib/PostgresMetaIndexes.js +42 -0
  33. package/dist/vendor/postgres-meta/lib/PostgresMetaMaterializedViews.js +84 -0
  34. package/dist/vendor/postgres-meta/lib/PostgresMetaPolicies.js +120 -0
  35. package/dist/vendor/postgres-meta/lib/PostgresMetaPublications.js +193 -0
  36. package/dist/vendor/postgres-meta/lib/PostgresMetaRelationships.js +87 -0
  37. package/dist/vendor/postgres-meta/lib/PostgresMetaRoles.js +203 -0
  38. package/dist/vendor/postgres-meta/lib/PostgresMetaSchemas.js +105 -0
  39. package/dist/vendor/postgres-meta/lib/PostgresMetaTablePrivileges.js +91 -0
  40. package/dist/vendor/postgres-meta/lib/PostgresMetaTables.js +183 -0
  41. package/dist/vendor/postgres-meta/lib/PostgresMetaTriggers.js +156 -0
  42. package/dist/vendor/postgres-meta/lib/PostgresMetaTypes.js +22 -0
  43. package/dist/vendor/postgres-meta/lib/PostgresMetaVersion.js +20 -0
  44. package/dist/vendor/postgres-meta/lib/PostgresMetaViews.js +83 -0
  45. package/dist/vendor/postgres-meta/lib/constants.js +8 -0
  46. package/dist/vendor/postgres-meta/lib/db.js +147 -0
  47. package/dist/vendor/postgres-meta/lib/generators.js +106 -0
  48. package/dist/vendor/postgres-meta/lib/helpers.js +26 -0
  49. package/dist/vendor/postgres-meta/lib/index.js +1 -0
  50. package/dist/vendor/postgres-meta/lib/sql/column_privileges.sql.js +154 -0
  51. package/dist/vendor/postgres-meta/lib/sql/columns.sql.js +123 -0
  52. package/dist/vendor/postgres-meta/lib/sql/common.js +1 -0
  53. package/dist/vendor/postgres-meta/lib/sql/config.sql.js +32 -0
  54. package/dist/vendor/postgres-meta/lib/sql/extensions.sql.js +20 -0
  55. package/dist/vendor/postgres-meta/lib/sql/foreign_tables.sql.js +20 -0
  56. package/dist/vendor/postgres-meta/lib/sql/functions.sql.js +141 -0
  57. package/dist/vendor/postgres-meta/lib/sql/indexes.sql.js +51 -0
  58. package/dist/vendor/postgres-meta/lib/sql/materialized_views.sql.js +21 -0
  59. package/dist/vendor/postgres-meta/lib/sql/policies.sql.js +53 -0
  60. package/dist/vendor/postgres-meta/lib/sql/publications.sql.js +46 -0
  61. package/dist/vendor/postgres-meta/lib/sql/roles.sql.js +40 -0
  62. package/dist/vendor/postgres-meta/lib/sql/schemas.sql.js +26 -0
  63. package/dist/vendor/postgres-meta/lib/sql/table.sql.js +109 -0
  64. package/dist/vendor/postgres-meta/lib/sql/table_privileges.sql.js +85 -0
  65. package/dist/vendor/postgres-meta/lib/sql/table_relationships.sql.js +52 -0
  66. package/dist/vendor/postgres-meta/lib/sql/triggers.sql.js +64 -0
  67. package/dist/vendor/postgres-meta/lib/sql/types.sql.js +65 -0
  68. package/dist/vendor/postgres-meta/lib/sql/version.sql.js +15 -0
  69. package/dist/vendor/postgres-meta/lib/sql/views.sql.js +22 -0
  70. package/dist/vendor/postgres-meta/lib/sql/views_key_dependencies.sql.js +198 -0
  71. package/dist/vendor/postgres-meta/lib/types.js +1 -0
  72. package/dist/vendor/postgres-meta/templates/typescript.js +608 -0
  73. package/package.json +13 -6
@@ -0,0 +1,154 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/column_privileges.sql.ts
2
+ const COLUMN_PRIVILEGES_SQL = (props) => `
3
+ -- Lists each column's privileges in the form of:
4
+ --
5
+ -- [
6
+ -- {
7
+ -- "column_id": "12345.1",
8
+ -- "relation_schema": "public",
9
+ -- "relation_name": "mytable",
10
+ -- "column_name": "mycolumn",
11
+ -- "privileges": [
12
+ -- {
13
+ -- "grantor": "postgres",
14
+ -- "grantee": "myrole",
15
+ -- "privilege_type": "SELECT",
16
+ -- "is_grantable": false
17
+ -- },
18
+ -- ...
19
+ -- ]
20
+ -- },
21
+ -- ...
22
+ -- ]
23
+ --
24
+ -- Modified from information_schema.column_privileges. We try to be as close as
25
+ -- possible to the view definition, obtained from:
26
+ --
27
+ -- select pg_get_viewdef('information_schema.column_privileges');
28
+ --
29
+ -- The main differences are:
30
+ -- - we include column privileges for materialized views
31
+ -- (reason for exclusion in information_schema.column_privileges:
32
+ -- https://www.postgresql.org/message-id/9136.1502740844%40sss.pgh.pa.us)
33
+ -- - we query a.attrelid and a.attnum to generate \`column_id\`
34
+ -- - \`table_catalog\` is omitted
35
+ -- - table_schema -> relation_schema, table_name -> relation_name
36
+ --
37
+ -- Column privileges are intertwined with table privileges in that table
38
+ -- privileges override column privileges. E.g. if we do:
39
+ --
40
+ -- grant all on mytable to myrole;
41
+ --
42
+ -- Then \`myrole\` is granted privileges for ALL columns. Likewise, if we do:
43
+ --
44
+ -- grant all (id) on mytable to myrole;
45
+ -- revoke all on mytable from myrole;
46
+ --
47
+ -- Then the grant on the \`id\` column is revoked.
48
+ --
49
+ -- This is unlike how grants for schemas and tables interact, where you need
50
+ -- privileges for BOTH the schema the table is in AND the table itself in order
51
+ -- to access the table.
52
+
53
+ select (x.attrelid || '.' || x.attnum) as column_id,
54
+ nc.nspname as relation_schema,
55
+ x.relname as relation_name,
56
+ x.attname as column_name,
57
+ coalesce(
58
+ jsonb_agg(
59
+ jsonb_build_object(
60
+ 'grantor', u_grantor.rolname,
61
+ 'grantee', grantee.rolname,
62
+ 'privilege_type', x.prtype,
63
+ 'is_grantable', x.grantable
64
+ )
65
+ ),
66
+ '[]'
67
+ ) as privileges
68
+ from
69
+ (select pr_c.grantor,
70
+ pr_c.grantee,
71
+ a.attrelid,
72
+ a.attnum,
73
+ a.attname,
74
+ pr_c.relname,
75
+ pr_c.relnamespace,
76
+ pr_c.prtype,
77
+ pr_c.grantable,
78
+ pr_c.relowner
79
+ from
80
+ (select pg_class.oid,
81
+ pg_class.relname,
82
+ pg_class.relnamespace,
83
+ pg_class.relowner,
84
+ (aclexplode(coalesce(pg_class.relacl, acldefault('r', pg_class.relowner)))).grantor as grantor,
85
+ (aclexplode(coalesce(pg_class.relacl, acldefault('r', pg_class.relowner)))).grantee as grantee,
86
+ (aclexplode(coalesce(pg_class.relacl, acldefault('r', pg_class.relowner)))).privilege_type as privilege_type,
87
+ (aclexplode(coalesce(pg_class.relacl, acldefault('r', pg_class.relowner)))).is_grantable as is_grantable
88
+ from pg_class
89
+ where (pg_class.relkind = any (array['r',
90
+ 'v',
91
+ 'm',
92
+ 'f',
93
+ 'p'])) ) pr_c(oid, relname, relnamespace, relowner, grantor, grantee, prtype, grantable),
94
+ pg_attribute a
95
+ where ((a.attrelid = pr_c.oid)
96
+ and (a.attnum > 0)
97
+ and (not a.attisdropped))
98
+ union select pr_a.grantor,
99
+ pr_a.grantee,
100
+ pr_a.attrelid,
101
+ pr_a.attnum,
102
+ pr_a.attname,
103
+ c.relname,
104
+ c.relnamespace,
105
+ pr_a.prtype,
106
+ pr_a.grantable,
107
+ c.relowner
108
+ from
109
+ (select a.attrelid,
110
+ a.attnum,
111
+ a.attname,
112
+ (aclexplode(coalesce(a.attacl, acldefault('c', cc.relowner)))).grantor as grantor,
113
+ (aclexplode(coalesce(a.attacl, acldefault('c', cc.relowner)))).grantee as grantee,
114
+ (aclexplode(coalesce(a.attacl, acldefault('c', cc.relowner)))).privilege_type as privilege_type,
115
+ (aclexplode(coalesce(a.attacl, acldefault('c', cc.relowner)))).is_grantable as is_grantable
116
+ from (pg_attribute a
117
+ join pg_class cc on ((a.attrelid = cc.oid)))
118
+ where ((a.attnum > 0)
119
+ and (not a.attisdropped))) pr_a(attrelid, attnum, attname, grantor, grantee, prtype, grantable),
120
+ pg_class c
121
+ where ((pr_a.attrelid = c.oid)
122
+ and (c.relkind = any (ARRAY['r',
123
+ 'v',
124
+ 'm',
125
+ 'f',
126
+ 'p'])))) x,
127
+ pg_namespace nc,
128
+ pg_authid u_grantor,
129
+ (select pg_authid.oid,
130
+ pg_authid.rolname
131
+ from pg_authid
132
+ union all select (0)::oid as oid,
133
+ 'PUBLIC') grantee(oid, rolname)
134
+ where ((x.relnamespace = nc.oid)
135
+ ${props.schemaFilter ? `and nc.nspname ${props.schemaFilter}` : ""}
136
+ ${props.columnIdsFilter ? `and (x.attrelid || '.' || x.attnum) ${props.columnIdsFilter}` : ""}
137
+ and (x.grantee = grantee.oid)
138
+ and (x.grantor = u_grantor.oid)
139
+ and (x.prtype = any (ARRAY['INSERT',
140
+ 'SELECT',
141
+ 'UPDATE',
142
+ 'REFERENCES']))
143
+ and (pg_has_role(u_grantor.oid, 'USAGE')
144
+ or pg_has_role(grantee.oid, 'USAGE')
145
+ or (grantee.rolname = 'PUBLIC')))
146
+ group by column_id,
147
+ nc.nspname,
148
+ x.relname,
149
+ x.attname
150
+ ${props.limit ? `limit ${props.limit}` : ""}
151
+ ${props.offset ? `offset ${props.offset}` : ""}
152
+ `;
153
+ //#endregion
154
+ export { COLUMN_PRIVILEGES_SQL };
@@ -0,0 +1,123 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/columns.sql.ts
2
+ const COLUMNS_SQL = (props) => `
3
+ -- Adapted from information_schema.columns
4
+
5
+ SELECT
6
+ c.oid :: int8 AS table_id,
7
+ nc.nspname AS schema,
8
+ c.relname AS table,
9
+ (c.oid || '.' || a.attnum) AS id,
10
+ a.attnum AS ordinal_position,
11
+ a.attname AS name,
12
+ CASE
13
+ WHEN a.atthasdef THEN pg_get_expr(ad.adbin, ad.adrelid)
14
+ ELSE NULL
15
+ END AS default_value,
16
+ CASE
17
+ WHEN t.typtype = 'd' THEN CASE
18
+ WHEN bt.typelem <> 0 :: oid
19
+ AND bt.typlen = -1 THEN 'ARRAY'
20
+ WHEN nbt.nspname = 'pg_catalog' THEN format_type(t.typbasetype, NULL)
21
+ ELSE 'USER-DEFINED'
22
+ END
23
+ ELSE CASE
24
+ WHEN t.typelem <> 0 :: oid
25
+ AND t.typlen = -1 THEN 'ARRAY'
26
+ WHEN nt.nspname = 'pg_catalog' THEN format_type(a.atttypid, NULL)
27
+ ELSE 'USER-DEFINED'
28
+ END
29
+ END AS data_type,
30
+ COALESCE(bt.typname, t.typname) AS format,
31
+ a.attidentity IN ('a', 'd') AS is_identity,
32
+ CASE
33
+ a.attidentity
34
+ WHEN 'a' THEN 'ALWAYS'
35
+ WHEN 'd' THEN 'BY DEFAULT'
36
+ ELSE NULL
37
+ END AS identity_generation,
38
+ a.attgenerated IN ('s') AS is_generated,
39
+ NOT (
40
+ a.attnotnull
41
+ OR t.typtype = 'd' AND t.typnotnull
42
+ ) AS is_nullable,
43
+ (
44
+ c.relkind IN ('r', 'p')
45
+ OR c.relkind IN ('v', 'f') AND pg_column_is_updatable(c.oid, a.attnum, FALSE)
46
+ ) AS is_updatable,
47
+ uniques.table_id IS NOT NULL AS is_unique,
48
+ check_constraints.definition AS "check",
49
+ array_to_json(
50
+ array(
51
+ SELECT
52
+ enumlabel
53
+ FROM
54
+ pg_catalog.pg_enum enums
55
+ WHERE
56
+ enums.enumtypid = coalesce(bt.oid, t.oid)
57
+ OR enums.enumtypid = coalesce(bt.typelem, t.typelem)
58
+ ORDER BY
59
+ enums.enumsortorder
60
+ )
61
+ ) AS enums,
62
+ col_description(c.oid, a.attnum) AS comment
63
+ FROM
64
+ pg_attribute a
65
+ LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid
66
+ AND a.attnum = ad.adnum
67
+ JOIN (
68
+ pg_class c
69
+ JOIN pg_namespace nc ON c.relnamespace = nc.oid
70
+ ) ON a.attrelid = c.oid
71
+ JOIN (
72
+ pg_type t
73
+ JOIN pg_namespace nt ON t.typnamespace = nt.oid
74
+ ) ON a.atttypid = t.oid
75
+ LEFT JOIN (
76
+ pg_type bt
77
+ JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid
78
+ ) ON t.typtype = 'd'
79
+ AND t.typbasetype = bt.oid
80
+ LEFT JOIN (
81
+ SELECT DISTINCT ON (table_id, ordinal_position)
82
+ conrelid AS table_id,
83
+ conkey[1] AS ordinal_position
84
+ FROM pg_catalog.pg_constraint
85
+ WHERE contype = 'u' AND cardinality(conkey) = 1
86
+ ) AS uniques ON uniques.table_id = c.oid AND uniques.ordinal_position = a.attnum
87
+ LEFT JOIN (
88
+ -- We only select the first column check
89
+ SELECT DISTINCT ON (table_id, ordinal_position)
90
+ conrelid AS table_id,
91
+ conkey[1] AS ordinal_position,
92
+ substring(
93
+ pg_get_constraintdef(pg_constraint.oid, true),
94
+ 8,
95
+ length(pg_get_constraintdef(pg_constraint.oid, true)) - 8
96
+ ) AS "definition"
97
+ FROM pg_constraint
98
+ WHERE contype = 'c' AND cardinality(conkey) = 1
99
+ ORDER BY table_id, ordinal_position, oid asc
100
+ ) AS check_constraints ON check_constraints.table_id = c.oid AND check_constraints.ordinal_position = a.attnum
101
+ WHERE
102
+ ${props.schemaFilter ? `nc.nspname ${props.schemaFilter} AND` : ""}
103
+ ${props.idsFilter ? `(c.oid || '.' || a.attnum) ${props.idsFilter} AND` : ""}
104
+ ${props.columnNameFilter ? `(c.relname || '.' || a.attname) ${props.columnNameFilter} AND` : ""}
105
+ ${props.tableIdFilter ? `c.oid ${props.tableIdFilter} AND` : ""}
106
+ ${props.tableIdentifierFilter ? `nc.nspname || '.' || c.relname ${props.tableIdentifierFilter} AND` : ""}
107
+ NOT pg_is_other_temp_schema(nc.oid)
108
+ AND a.attnum > 0
109
+ AND NOT a.attisdropped
110
+ AND (c.relkind IN ('r', 'v', 'm', 'f', 'p'))
111
+ AND (
112
+ pg_has_role(c.relowner, 'USAGE')
113
+ OR has_column_privilege(
114
+ c.oid,
115
+ a.attnum,
116
+ 'SELECT, INSERT, UPDATE, REFERENCES'
117
+ )
118
+ )
119
+ ${props.limit ? `limit ${props.limit}` : ""}
120
+ ${props.offset ? `offset ${props.offset}` : ""}
121
+ `;
122
+ //#endregion
123
+ export { COLUMNS_SQL };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/config.sql.ts
2
+ const CONFIG_SQL = (props) => `
3
+ SELECT
4
+ name,
5
+ setting,
6
+ category,
7
+ TRIM(split_part(category, '/', 1)) AS group,
8
+ TRIM(split_part(category, '/', 2)) AS subgroup,
9
+ unit,
10
+ short_desc,
11
+ extra_desc,
12
+ context,
13
+ vartype,
14
+ source,
15
+ min_val,
16
+ max_val,
17
+ enumvals,
18
+ boot_val,
19
+ reset_val,
20
+ sourcefile,
21
+ sourceline,
22
+ pending_restart
23
+ FROM
24
+ pg_settings
25
+ ORDER BY
26
+ category,
27
+ name
28
+ ${props.limit ? `limit ${props.limit}` : ""}
29
+ ${props.offset ? `offset ${props.offset}` : ""}
30
+ `;
31
+ //#endregion
32
+ export { CONFIG_SQL };
@@ -0,0 +1,20 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/extensions.sql.ts
2
+ const EXTENSIONS_SQL = (props) => `
3
+ SELECT
4
+ e.name,
5
+ n.nspname AS schema,
6
+ e.default_version,
7
+ x.extversion AS installed_version,
8
+ e.comment
9
+ FROM
10
+ pg_available_extensions() e(name, default_version, comment)
11
+ LEFT JOIN pg_extension x ON e.name = x.extname
12
+ LEFT JOIN pg_namespace n ON x.extnamespace = n.oid
13
+ WHERE
14
+ true
15
+ ${props.nameFilter ? `AND e.name ${props.nameFilter}` : ""}
16
+ ${props.limit ? `limit ${props.limit}` : ""}
17
+ ${props.offset ? `offset ${props.offset}` : ""}
18
+ `;
19
+ //#endregion
20
+ export { EXTENSIONS_SQL };
@@ -0,0 +1,20 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/foreign_tables.sql.ts
2
+ const FOREIGN_TABLES_SQL = (props) => `
3
+ SELECT
4
+ c.oid :: int8 AS id,
5
+ n.nspname AS schema,
6
+ c.relname AS name,
7
+ obj_description(c.oid) AS comment
8
+ FROM
9
+ pg_class c
10
+ JOIN pg_namespace n ON n.oid = c.relnamespace
11
+ WHERE
12
+ ${props.schemaFilter ? `n.nspname ${props.schemaFilter} AND` : ""}
13
+ ${props.idsFilter ? `c.oid ${props.idsFilter} AND` : ""}
14
+ ${props.tableIdentifierFilter ? `(n.nspname || '.' || c.relname) ${props.tableIdentifierFilter} AND` : ""}
15
+ c.relkind = 'f'
16
+ ${props.limit ? `limit ${props.limit}` : ""}
17
+ ${props.offset ? `offset ${props.offset}` : ""}
18
+ `;
19
+ //#endregion
20
+ export { FOREIGN_TABLES_SQL };
@@ -0,0 +1,141 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/functions.sql.ts
2
+ const FUNCTIONS_SQL = (props) => `
3
+ -- CTE with sane arg_modes, arg_names, and arg_types.
4
+ -- All three are always of the same length.
5
+ -- All three include all args, including OUT and TABLE args.
6
+ with functions as (
7
+ select
8
+ p.*,
9
+ -- proargmodes is null when all arg modes are IN
10
+ coalesce(
11
+ p.proargmodes,
12
+ array_fill('i'::text, array[cardinality(coalesce(p.proallargtypes, p.proargtypes))])
13
+ ) as arg_modes,
14
+ -- proargnames is null when all args are unnamed
15
+ coalesce(
16
+ p.proargnames,
17
+ array_fill(''::text, array[cardinality(coalesce(p.proallargtypes, p.proargtypes))])
18
+ ) as arg_names,
19
+ -- proallargtypes is null when all arg modes are IN
20
+ coalesce(p.proallargtypes, p.proargtypes) as arg_types,
21
+ array_cat(
22
+ array_fill(false, array[pronargs - pronargdefaults]),
23
+ array_fill(true, array[pronargdefaults])) as arg_has_defaults
24
+ from
25
+ pg_proc as p
26
+ ${props.schemaFilter ? `join pg_namespace n on p.pronamespace = n.oid` : ""}
27
+ where
28
+ ${props.schemaFilter ? `n.nspname ${props.schemaFilter} AND` : ""}
29
+ ${props.idsFilter ? `p.oid ${props.idsFilter} AND` : ""}
30
+ ${props.nameFilter ? `p.proname ${props.nameFilter} AND` : ""}
31
+ ${props.args === void 0 ? "" : props.args.length > 0 ? `p.proargtypes::text = ${props.args.length ? `(
32
+ SELECT STRING_AGG(type_oid::text, ' ') FROM (
33
+ SELECT (
34
+ split_args.arr[
35
+ array_length(
36
+ split_args.arr,
37
+ 1
38
+ )
39
+ ]::regtype::oid
40
+ ) AS type_oid FROM (
41
+ SELECT STRING_TO_ARRAY(
42
+ UNNEST(
43
+ ARRAY[${props.args}]
44
+ ),
45
+ ' '
46
+ ) AS arr
47
+ ) AS split_args
48
+ ) args
49
+ )` : "''"} AND` : ""}
50
+ p.prokind = 'f'
51
+ )
52
+ select
53
+ f.oid::int8 as id,
54
+ n.nspname as schema,
55
+ f.proname as name,
56
+ l.lanname as language,
57
+ case
58
+ when l.lanname = 'internal' then ''
59
+ else f.prosrc
60
+ end as definition,
61
+ case
62
+ when l.lanname = 'internal' then f.prosrc
63
+ else pg_get_functiondef(f.oid)
64
+ end as complete_statement,
65
+ coalesce(f_args.args, '[]') as args,
66
+ pg_get_function_arguments(f.oid) as argument_types,
67
+ pg_get_function_identity_arguments(f.oid) as identity_argument_types,
68
+ f.prorettype::int8 as return_type_id,
69
+ pg_get_function_result(f.oid) as return_type,
70
+ nullif(rt.typrelid::int8, 0) as return_type_relation_id,
71
+ f.proretset as is_set_returning_function,
72
+ case
73
+ when f.proretset then nullif(f.prorows, 0)
74
+ else null
75
+ end as prorows,
76
+ case
77
+ when f.provolatile = 'i' then 'IMMUTABLE'
78
+ when f.provolatile = 's' then 'STABLE'
79
+ when f.provolatile = 'v' then 'VOLATILE'
80
+ end as behavior,
81
+ f.prosecdef as security_definer,
82
+ f_config.config_params as config_params
83
+ from
84
+ functions f
85
+ left join pg_namespace n on f.pronamespace = n.oid
86
+ left join pg_language l on f.prolang = l.oid
87
+ left join pg_type rt on rt.oid = f.prorettype
88
+ left join (
89
+ select
90
+ oid,
91
+ jsonb_object_agg(param, value) filter (where param is not null) as config_params
92
+ from
93
+ (
94
+ select
95
+ oid,
96
+ (string_to_array(unnest(proconfig), '='))[1] as param,
97
+ (string_to_array(unnest(proconfig), '='))[2] as value
98
+ from
99
+ functions
100
+ ) as t
101
+ group by
102
+ oid
103
+ ) f_config on f_config.oid = f.oid
104
+ left join (
105
+ select
106
+ oid,
107
+ jsonb_agg(jsonb_build_object(
108
+ 'mode', t2.mode,
109
+ 'name', name,
110
+ 'type_id', type_id,
111
+ 'has_default', has_default
112
+ )) as args
113
+ from
114
+ (
115
+ select
116
+ oid,
117
+ unnest(arg_modes) as mode,
118
+ unnest(arg_names) as name,
119
+ unnest(arg_types)::int8 as type_id,
120
+ unnest(arg_has_defaults) as has_default
121
+ from
122
+ functions
123
+ ) as t1,
124
+ lateral (
125
+ select
126
+ case
127
+ when t1.mode = 'i' then 'in'
128
+ when t1.mode = 'o' then 'out'
129
+ when t1.mode = 'b' then 'inout'
130
+ when t1.mode = 'v' then 'variadic'
131
+ else 'table'
132
+ end as mode
133
+ ) as t2
134
+ group by
135
+ t1.oid
136
+ ) f_args on f_args.oid = f.oid
137
+ ${props.limit ? `limit ${props.limit}` : ""}
138
+ ${props.offset ? `offset ${props.offset}` : ""}
139
+ `;
140
+ //#endregion
141
+ export { FUNCTIONS_SQL };
@@ -0,0 +1,51 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/indexes.sql.ts
2
+ const INDEXES_SQL = (props) => `
3
+ SELECT
4
+ idx.indexrelid::int8 AS id,
5
+ idx.indrelid::int8 AS table_id,
6
+ n.nspname AS schema,
7
+ idx.indnatts AS number_of_attributes,
8
+ idx.indnkeyatts AS number_of_key_attributes,
9
+ idx.indisunique AS is_unique,
10
+ idx.indisprimary AS is_primary,
11
+ idx.indisexclusion AS is_exclusion,
12
+ idx.indimmediate AS is_immediate,
13
+ idx.indisclustered AS is_clustered,
14
+ idx.indisvalid AS is_valid,
15
+ idx.indcheckxmin AS check_xmin,
16
+ idx.indisready AS is_ready,
17
+ idx.indislive AS is_live,
18
+ idx.indisreplident AS is_replica_identity,
19
+ idx.indkey::smallint[] AS key_attributes,
20
+ idx.indcollation::integer[] AS collation,
21
+ idx.indclass::integer[] AS class,
22
+ idx.indoption::smallint[] AS options,
23
+ idx.indpred AS index_predicate,
24
+ obj_description(idx.indexrelid, 'pg_class') AS comment,
25
+ ix.indexdef as index_definition,
26
+ am.amname AS access_method,
27
+ jsonb_agg(
28
+ jsonb_build_object(
29
+ 'attribute_number', a.attnum,
30
+ 'attribute_name', a.attname,
31
+ 'data_type', format_type(a.atttypid, a.atttypmod)
32
+ )
33
+ ORDER BY a.attnum
34
+ ) AS index_attributes
35
+ FROM
36
+ pg_index idx
37
+ JOIN pg_class c ON c.oid = idx.indexrelid
38
+ JOIN pg_namespace n ON c.relnamespace = n.oid
39
+ JOIN pg_am am ON c.relam = am.oid
40
+ JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ANY(idx.indkey)
41
+ JOIN pg_indexes ix ON c.relname = ix.indexname
42
+ WHERE
43
+ ${props.schemaFilter ? `n.nspname ${props.schemaFilter}` : "true"}
44
+ ${props.idsFilter ? `AND idx.indexrelid ${props.idsFilter}` : ""}
45
+ GROUP BY
46
+ idx.indexrelid, idx.indrelid, n.nspname, idx.indnatts, idx.indnkeyatts, idx.indisunique, idx.indisprimary, idx.indisexclusion, idx.indimmediate, idx.indisclustered, idx.indisvalid, idx.indcheckxmin, idx.indisready, idx.indislive, idx.indisreplident, idx.indkey, idx.indcollation, idx.indclass, idx.indoption, idx.indexprs, idx.indpred, ix.indexdef, am.amname
47
+ ${props.limit ? `limit ${props.limit}` : ""}
48
+ ${props.offset ? `offset ${props.offset}` : ""}
49
+ `;
50
+ //#endregion
51
+ export { INDEXES_SQL };
@@ -0,0 +1,21 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/materialized_views.sql.ts
2
+ const MATERIALIZED_VIEWS_SQL = (props) => `
3
+ select
4
+ c.oid::int8 as id,
5
+ n.nspname as schema,
6
+ c.relname as name,
7
+ c.relispopulated as is_populated,
8
+ obj_description(c.oid) as comment
9
+ from
10
+ pg_class c
11
+ join pg_namespace n on n.oid = c.relnamespace
12
+ where
13
+ ${props.schemaFilter ? `n.nspname ${props.schemaFilter} AND` : ""}
14
+ ${props.idsFilter ? `c.oid ${props.idsFilter} AND` : ""}
15
+ ${props.materializedViewIdentifierFilter ? `(n.nspname || '.' || c.relname) ${props.materializedViewIdentifierFilter} AND` : ""}
16
+ c.relkind = 'm'
17
+ ${props.limit ? `limit ${props.limit}` : ""}
18
+ ${props.offset ? `offset ${props.offset}` : ""}
19
+ `;
20
+ //#endregion
21
+ export { MATERIALIZED_VIEWS_SQL };
@@ -0,0 +1,53 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/policies.sql.ts
2
+ const POLICIES_SQL = (props) => `
3
+ SELECT
4
+ pol.oid :: int8 AS id,
5
+ n.nspname AS schema,
6
+ c.relname AS table,
7
+ c.oid :: int8 AS table_id,
8
+ pol.polname AS name,
9
+ CASE
10
+ WHEN pol.polpermissive THEN 'PERMISSIVE' :: text
11
+ ELSE 'RESTRICTIVE' :: text
12
+ END AS action,
13
+ CASE
14
+ WHEN pol.polroles = '{0}' :: oid [] THEN array_to_json(
15
+ string_to_array('public' :: text, '' :: text) :: name []
16
+ )
17
+ ELSE array_to_json(
18
+ ARRAY(
19
+ SELECT
20
+ pg_roles.rolname
21
+ FROM
22
+ pg_roles
23
+ WHERE
24
+ pg_roles.oid = ANY (pol.polroles)
25
+ ORDER BY
26
+ pg_roles.rolname
27
+ )
28
+ )
29
+ END AS roles,
30
+ CASE
31
+ pol.polcmd
32
+ WHEN 'r' :: "char" THEN 'SELECT' :: text
33
+ WHEN 'a' :: "char" THEN 'INSERT' :: text
34
+ WHEN 'w' :: "char" THEN 'UPDATE' :: text
35
+ WHEN 'd' :: "char" THEN 'DELETE' :: text
36
+ WHEN '*' :: "char" THEN 'ALL' :: text
37
+ ELSE NULL :: text
38
+ END AS command,
39
+ pg_get_expr(pol.polqual, pol.polrelid) AS definition,
40
+ pg_get_expr(pol.polwithcheck, pol.polrelid) AS check
41
+ FROM
42
+ pg_policy pol
43
+ JOIN pg_class c ON c.oid = pol.polrelid
44
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
45
+ WHERE
46
+ ${props.schemaFilter ? `n.nspname ${props.schemaFilter}` : "true"}
47
+ ${props.idsFilter ? `AND pol.oid ${props.idsFilter}` : ""}
48
+ ${props.functionNameIdentifierFilter ? `AND (c.relname || '.' || pol.polname) ${props.functionNameIdentifierFilter}` : ""}
49
+ ${props.limit ? `limit ${props.limit}` : ""}
50
+ ${props.offset ? `offset ${props.offset}` : ""}
51
+ `;
52
+ //#endregion
53
+ export { POLICIES_SQL };
@@ -0,0 +1,46 @@
1
+ //#region src/vendor/postgres-meta/lib/sql/publications.sql.ts
2
+ const PUBLICATIONS_SQL = (props) => `
3
+ SELECT
4
+ p.oid :: int8 AS id,
5
+ p.pubname AS name,
6
+ p.pubowner::regrole::text AS owner,
7
+ p.pubinsert AS publish_insert,
8
+ p.pubupdate AS publish_update,
9
+ p.pubdelete AS publish_delete,
10
+ p.pubtruncate AS publish_truncate,
11
+ CASE
12
+ WHEN p.puballtables THEN NULL
13
+ ELSE pr.tables
14
+ END AS tables
15
+ FROM
16
+ pg_catalog.pg_publication AS p
17
+ LEFT JOIN LATERAL (
18
+ SELECT
19
+ COALESCE(
20
+ array_agg(
21
+ json_build_object(
22
+ 'id',
23
+ c.oid :: int8,
24
+ 'name',
25
+ c.relname,
26
+ 'schema',
27
+ nc.nspname
28
+ )
29
+ ),
30
+ '{}'
31
+ ) AS tables
32
+ FROM
33
+ pg_catalog.pg_publication_rel AS pr
34
+ JOIN pg_class AS c ON pr.prrelid = c.oid
35
+ join pg_namespace as nc on c.relnamespace = nc.oid
36
+ WHERE
37
+ pr.prpubid = p.oid
38
+ ) AS pr ON 1 = 1
39
+ WHERE
40
+ ${props.idsFilter ? `p.oid ${props.idsFilter}` : "true"}
41
+ ${props.nameFilter ? `AND p.pubname ${props.nameFilter}` : ""}
42
+ ${props.limit ? `limit ${props.limit}` : ""}
43
+ ${props.offset ? `offset ${props.offset}` : ""}
44
+ `;
45
+ //#endregion
46
+ export { PUBLICATIONS_SQL };