postgresai 0.18.0-dev.10 → 0.18.0-dev.11

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.
@@ -40,7 +40,7 @@ grant usage on schema public to {{ROLE_IDENT}};
40
40
  -- Grant access to the schema where pg_stat_statements is installed.
41
41
  -- Some providers (e.g., Supabase) install extensions in a separate 'extensions' schema
42
42
  -- rather than pg_catalog. This DO block detects the schema and grants USAGE if needed.
43
- do $$
43
+ do {{DO_QUOTE}}
44
44
  declare
45
45
  ext_schema text;
46
46
  begin
@@ -51,16 +51,16 @@ begin
51
51
 
52
52
  -- Only grant if extension exists and is in a non-standard schema
53
53
  if ext_schema is not null and ext_schema not in ('pg_catalog', 'public') then
54
- execute format('grant usage on schema %I to {{ROLE_IDENT}}', ext_schema);
54
+ execute format('grant usage on schema %I to %I', ext_schema, {{ROLE_LITERAL}});
55
55
  end if;
56
- end $$;
56
+ end {{DO_QUOTE}};
57
57
 
58
58
  -- [SEARCH_PATH_BLOCK_START] Resolve built-ins from pg_catalog first; keep pg_temp last.
59
59
  -- Do not include the role-named schema: it may be writable by that role.
60
60
  -- public stays for pg_stat_statements. Residual risk: a function in public with
61
61
  -- an exact-type match (e.g. public.quote_ident(name)) still beats pg_catalog.
62
62
  -- The path for this database includes its pg_stat_statements schema if it is in a non-standard location.
63
- do $$
63
+ do {{DO_QUOTE}}
64
64
  declare
65
65
  ext_schema text;
66
66
  role_path constant text := 'pg_catalog, postgres_ai, public, pg_temp';
@@ -88,11 +88,9 @@ begin
88
88
  and setdatabase = 0
89
89
  and ('search_path=' || role_path) = any (setconfig)
90
90
  ) then
91
- execute format('alter user {{ROLE_IDENT}} set search_path = %s', role_path);
91
+ execute format('alter user %I set search_path = %s', {{ROLE_LITERAL}}, role_path);
92
92
  end if;
93
93
  -- This database's value: other databases keep their own pg_stat_statements schema.
94
- execute format('alter user {{ROLE_IDENT}} in database %I set search_path = %s', pg_catalog.current_database(), db_path);
95
- end $$;
94
+ execute format('alter user %I in database %I set search_path = %s', {{ROLE_LITERAL}}, pg_catalog.current_database(), db_path);
95
+ end {{DO_QUOTE}};
96
96
  -- [SEARCH_PATH_BLOCK_END]
97
-
98
-
@@ -1,5 +1,18 @@
1
1
  -- Helper functions for postgres_ai monitoring user (template-filled by cli/lib/init.ts)
2
2
 
3
+ -- Remove the retired helper from databases prepared by older CLI versions.
4
+ -- Only its owner or a superuser can drop it: anyone else gets a warning here. Releases
5
+ -- installed table_describe with the same owner, so replacing it below then fails.
6
+ do {{DO_QUOTE}}
7
+ begin
8
+ -- Runs as the admin: resolve names from pg_catalog only (CVE-2018-1058).
9
+ set local search_path = pg_catalog, pg_temp;
10
+ drop function if exists postgres_ai.explain_generic(text, text, text);
11
+ exception when insufficient_privilege then
12
+ raise warning 'postgres_ai: legacy SECURITY DEFINER helper was NOT removed: %', sqlerrm
13
+ using hint = 'Its owner or a superuser must drop it, then re-run prepare-db.';
14
+ end {{DO_QUOTE}};
15
+
3
16
  /*
4
17
  * table_describe
5
18
  *
@@ -14,7 +14,7 @@ drop view if exists postgres_ai.pg_statistic;
14
14
  -- permissions (04, 05). A non-superuser admin cannot revoke a grant that a
15
15
  -- superuser made. Pass 1 revokes. Pass 2 sends one "grant left" WARNING for
16
16
  -- each grant that stays. The CLI shows these WARNINGs and exits 1.
17
- do $$
17
+ do {{DO_QUOTE}}
18
18
  declare
19
19
  role_oid oid;
20
20
  stmt text;
@@ -80,7 +80,7 @@ begin
80
80
  end if;
81
81
  end loop;
82
82
  end loop;
83
- end $$;
83
+ end {{DO_QUOTE}};
84
84
 
85
85
  -- Note: USAGE on public is typically granted by default; we don't revoke it
86
86
  -- to avoid breaking other applications that may rely on it.
@@ -5,7 +5,7 @@
5
5
  set local search_path = pg_catalog, pg_temp;
6
6
 
7
7
  -- Use a DO block to handle the case where the role doesn't exist
8
- do $$ begin
8
+ do {{DO_QUOTE}} begin
9
9
  -- Reassign owned objects to current user before dropping
10
10
  -- This handles any objects that might have been created by the role
11
11
  begin
@@ -27,4 +27,4 @@ do $$ begin
27
27
  exception when undefined_object then
28
28
  null; -- Role doesn't exist, that's fine
29
29
  end;
30
- end $$;
30
+ end {{DO_QUOTE}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.18.0-dev.10",
3
+ "version": "0.18.0-dev.11",
4
4
  "description": "postgres_ai CLI",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,
@@ -40,7 +40,7 @@ grant usage on schema public to {{ROLE_IDENT}};
40
40
  -- Grant access to the schema where pg_stat_statements is installed.
41
41
  -- Some providers (e.g., Supabase) install extensions in a separate 'extensions' schema
42
42
  -- rather than pg_catalog. This DO block detects the schema and grants USAGE if needed.
43
- do $$
43
+ do {{DO_QUOTE}}
44
44
  declare
45
45
  ext_schema text;
46
46
  begin
@@ -51,16 +51,16 @@ begin
51
51
 
52
52
  -- Only grant if extension exists and is in a non-standard schema
53
53
  if ext_schema is not null and ext_schema not in ('pg_catalog', 'public') then
54
- execute format('grant usage on schema %I to {{ROLE_IDENT}}', ext_schema);
54
+ execute format('grant usage on schema %I to %I', ext_schema, {{ROLE_LITERAL}});
55
55
  end if;
56
- end $$;
56
+ end {{DO_QUOTE}};
57
57
 
58
58
  -- [SEARCH_PATH_BLOCK_START] Resolve built-ins from pg_catalog first; keep pg_temp last.
59
59
  -- Do not include the role-named schema: it may be writable by that role.
60
60
  -- public stays for pg_stat_statements. Residual risk: a function in public with
61
61
  -- an exact-type match (e.g. public.quote_ident(name)) still beats pg_catalog.
62
62
  -- The path for this database includes its pg_stat_statements schema if it is in a non-standard location.
63
- do $$
63
+ do {{DO_QUOTE}}
64
64
  declare
65
65
  ext_schema text;
66
66
  role_path constant text := 'pg_catalog, postgres_ai, public, pg_temp';
@@ -88,11 +88,9 @@ begin
88
88
  and setdatabase = 0
89
89
  and ('search_path=' || role_path) = any (setconfig)
90
90
  ) then
91
- execute format('alter user {{ROLE_IDENT}} set search_path = %s', role_path);
91
+ execute format('alter user %I set search_path = %s', {{ROLE_LITERAL}}, role_path);
92
92
  end if;
93
93
  -- This database's value: other databases keep their own pg_stat_statements schema.
94
- execute format('alter user {{ROLE_IDENT}} in database %I set search_path = %s', pg_catalog.current_database(), db_path);
95
- end $$;
94
+ execute format('alter user %I in database %I set search_path = %s', {{ROLE_LITERAL}}, pg_catalog.current_database(), db_path);
95
+ end {{DO_QUOTE}};
96
96
  -- [SEARCH_PATH_BLOCK_END]
97
-
98
-
@@ -1,5 +1,18 @@
1
1
  -- Helper functions for postgres_ai monitoring user (template-filled by cli/lib/init.ts)
2
2
 
3
+ -- Remove the retired helper from databases prepared by older CLI versions.
4
+ -- Only its owner or a superuser can drop it: anyone else gets a warning here. Releases
5
+ -- installed table_describe with the same owner, so replacing it below then fails.
6
+ do {{DO_QUOTE}}
7
+ begin
8
+ -- Runs as the admin: resolve names from pg_catalog only (CVE-2018-1058).
9
+ set local search_path = pg_catalog, pg_temp;
10
+ drop function if exists postgres_ai.explain_generic(text, text, text);
11
+ exception when insufficient_privilege then
12
+ raise warning 'postgres_ai: legacy SECURITY DEFINER helper was NOT removed: %', sqlerrm
13
+ using hint = 'Its owner or a superuser must drop it, then re-run prepare-db.';
14
+ end {{DO_QUOTE}};
15
+
3
16
  /*
4
17
  * table_describe
5
18
  *
@@ -14,7 +14,7 @@ drop view if exists postgres_ai.pg_statistic;
14
14
  -- permissions (04, 05). A non-superuser admin cannot revoke a grant that a
15
15
  -- superuser made. Pass 1 revokes. Pass 2 sends one "grant left" WARNING for
16
16
  -- each grant that stays. The CLI shows these WARNINGs and exits 1.
17
- do $$
17
+ do {{DO_QUOTE}}
18
18
  declare
19
19
  role_oid oid;
20
20
  stmt text;
@@ -80,7 +80,7 @@ begin
80
80
  end if;
81
81
  end loop;
82
82
  end loop;
83
- end $$;
83
+ end {{DO_QUOTE}};
84
84
 
85
85
  -- Note: USAGE on public is typically granted by default; we don't revoke it
86
86
  -- to avoid breaking other applications that may rely on it.
@@ -5,7 +5,7 @@
5
5
  set local search_path = pg_catalog, pg_temp;
6
6
 
7
7
  -- Use a DO block to handle the case where the role doesn't exist
8
- do $$ begin
8
+ do {{DO_QUOTE}} begin
9
9
  -- Reassign owned objects to current user before dropping
10
10
  -- This handles any objects that might have been created by the role
11
11
  begin
@@ -27,4 +27,4 @@ do $$ begin
27
27
  exception when undefined_object then
28
28
  null; -- Role doesn't exist, that's fine
29
29
  end;
30
- end $$;
30
+ end {{DO_QUOTE}};