@pgpmjs/core 7.32.8 → 7.34.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.
@@ -69,12 +69,12 @@ export class PgpmInit {
69
69
  * @param username - The username to create
70
70
  * @param password - The password for the user
71
71
  * @param roles - Role mapping from getConnEnvOptions().roles!
72
- * @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
72
+ * @param options - Role locking and explicit RLS bypass (off by default).
73
73
  */
74
- async bootstrapDbRoles(username, password, roles, useLocksForRoles = false) {
74
+ async bootstrapDbRoles(username, password, roles, options = {}) {
75
75
  try {
76
76
  log.info(`Bootstrapping PGPM database roles for user: ${username}...`);
77
- const sql = generateCreateUserSQL(username, password, roles, useLocksForRoles);
77
+ const sql = generateCreateUserSQL(username, password, roles, options);
78
78
  await this.pool.query(sql);
79
79
  log.success(`Successfully bootstrapped PGPM database roles for user: ${username}`);
80
80
  }
@@ -183,12 +183,12 @@ COMMIT;
183
183
  `;
184
184
  }
185
185
  /**
186
- * Generate SQL to create a user with password and grant base roles.
186
+ * Generate SQL to create or reconcile a login and grant base roles.
187
187
  * Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
188
188
  * @param roles - Role mapping from getConnEnvOptions().roles!
189
- * @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
189
+ * @param options - Role locking and explicit RLS bypass (off by default).
190
190
  */
191
- export function generateCreateUserSQL(username, password, roles, useLocksForRoles = false) {
191
+ export function generateCreateUserSQL(username, password, roles, { useLocksForRoles = false, bypassRls = false } = {}) {
192
192
  if (!roles) {
193
193
  throw new Error('generateCreateUserSQL: roles parameter is undefined. ' +
194
194
  'Ensure getConnEnvOptions().roles is defined.');
@@ -231,6 +231,8 @@ BEGIN
231
231
  END;
232
232
  END IF;
233
233
 
234
+ EXECUTE format('ALTER ROLE %I LOGIN INHERIT NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION ${bypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'} PASSWORD %L', v_username, v_password);
235
+
234
236
  -- Grant anonymous to user
235
237
  IF NOT EXISTS (
236
238
  SELECT 1 FROM pg_auth_members am
@@ -245,8 +247,7 @@ BEGIN
245
247
  -- 23505: Membership was granted concurrently; safe to ignore
246
248
  NULL;
247
249
  WHEN undefined_object THEN
248
- -- 42704: One of the roles doesn't exist; log notice and continue
249
- RAISE NOTICE 'Missing role when granting % to %', v_anonymous, v_username;
250
+ RAISE;
250
251
  WHEN insufficient_privilege THEN
251
252
  -- 42501: Must surface this error - caller lacks permission
252
253
  RAISE;
@@ -270,8 +271,7 @@ BEGIN
270
271
  -- 23505: Membership was granted concurrently; safe to ignore
271
272
  NULL;
272
273
  WHEN undefined_object THEN
273
- -- 42704: One of the roles doesn't exist; log notice and continue
274
- RAISE NOTICE 'Missing role when granting % to %', v_authenticated, v_username;
274
+ RAISE;
275
275
  WHEN insufficient_privilege THEN
276
276
  -- 42501: Must surface this error - caller lacks permission
277
277
  RAISE;
package/init/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { RoleMapping, TestUserCredentials } from '@pgpmjs/types';
2
2
  import { PgConfig } from 'pg-env';
3
+ import { CreateUserOptions } from '../roles';
3
4
  export declare class PgpmInit {
4
5
  private pool;
5
6
  private pgConfig;
@@ -30,9 +31,9 @@ export declare class PgpmInit {
30
31
  * @param username - The username to create
31
32
  * @param password - The password for the user
32
33
  * @param roles - Role mapping from getConnEnvOptions().roles!
33
- * @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
34
+ * @param options - Role locking and explicit RLS bypass (off by default).
34
35
  */
35
- bootstrapDbRoles(username: string, password: string, roles: RoleMapping, useLocksForRoles?: boolean): Promise<void>;
36
+ bootstrapDbRoles(username: string, password: string, roles: RoleMapping, options?: CreateUserOptions): Promise<void>;
36
37
  /**
37
38
  * Remove database roles and revoke grants.
38
39
  * Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
package/init/client.js CHANGED
@@ -72,12 +72,12 @@ class PgpmInit {
72
72
  * @param username - The username to create
73
73
  * @param password - The password for the user
74
74
  * @param roles - Role mapping from getConnEnvOptions().roles!
75
- * @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
75
+ * @param options - Role locking and explicit RLS bypass (off by default).
76
76
  */
77
- async bootstrapDbRoles(username, password, roles, useLocksForRoles = false) {
77
+ async bootstrapDbRoles(username, password, roles, options = {}) {
78
78
  try {
79
79
  log.info(`Bootstrapping PGPM database roles for user: ${username}...`);
80
- const sql = (0, roles_1.generateCreateUserSQL)(username, password, roles, useLocksForRoles);
80
+ const sql = (0, roles_1.generateCreateUserSQL)(username, password, roles, options);
81
81
  await this.pool.query(sql);
82
82
  log.success(`Successfully bootstrapped PGPM database roles for user: ${username}`);
83
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/core",
3
- "version": "7.32.8",
3
+ "version": "7.34.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PGPM Package and Migration Tools",
6
6
  "main": "index.js",
@@ -49,28 +49,28 @@
49
49
  "makage": "^0.8.0"
50
50
  },
51
51
  "dependencies": {
52
- "@pgpmjs/ast": "^0.15.7",
53
- "@pgpmjs/bundle": "^0.18.7",
54
- "@pgpmjs/diff": "^0.8.9",
55
- "@pgpmjs/env": "^2.47.0",
56
- "@pgpmjs/logger": "^2.26.0",
57
- "@pgpmjs/server-utils": "^3.29.7",
58
- "@pgpmjs/slice": "^0.19.9",
59
- "@pgpmjs/transform": "^0.28.9",
60
- "@pgpmjs/types": "^2.57.0",
52
+ "@pgpmjs/ast": "^0.16.0",
53
+ "@pgpmjs/bundle": "^0.19.0",
54
+ "@pgpmjs/diff": "^0.9.0",
55
+ "@pgpmjs/env": "^2.48.0",
56
+ "@pgpmjs/logger": "^2.27.0",
57
+ "@pgpmjs/server-utils": "^3.30.0",
58
+ "@pgpmjs/slice": "^0.20.0",
59
+ "@pgpmjs/transform": "^0.29.0",
60
+ "@pgpmjs/types": "^2.58.0",
61
61
  "cross-spawn": "^7.0.6",
62
- "csv-to-pg": "^4.14.3",
62
+ "csv-to-pg": "^4.15.0",
63
63
  "genomic": "^5.6.6",
64
64
  "git-changed": "^0.4.0",
65
65
  "glob": "^13.0.6",
66
66
  "parse-package-name": "^1.0.0",
67
67
  "pg": "^8.21.0",
68
- "pg-cache": "^3.29.7",
69
- "pg-env": "^1.32.0",
68
+ "pg-cache": "^3.30.0",
69
+ "pg-env": "^1.33.0",
70
70
  "pgsql-deparser": "^18.3.12",
71
71
  "pgsql-parser": "^18.2.12",
72
72
  "yaml": "^2.9.0",
73
73
  "yanse": "^0.2.2"
74
74
  },
75
- "gitHead": "850fc5e75a3a31e2db2fc28aa58377e886fe3c6a"
75
+ "gitHead": "487c4ec9ee997d7da80584a3d41d7120d4354c54"
76
76
  }
package/roles/index.d.ts CHANGED
@@ -20,13 +20,17 @@ export declare function generateCreateBaseRolesSQL(roles: RoleMapping): string;
20
20
  * @param statementTimeout - Baseline statement_timeout for the role (default '15s')
21
21
  */
22
22
  export declare function generateCreateClientRoleSQL(roles: RoleMapping, statementTimeout?: string): string;
23
+ export interface CreateUserOptions {
24
+ useLocksForRoles?: boolean;
25
+ bypassRls?: boolean;
26
+ }
23
27
  /**
24
- * Generate SQL to create a user with password and grant base roles.
28
+ * Generate SQL to create or reconcile a login and grant base roles.
25
29
  * Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
26
30
  * @param roles - Role mapping from getConnEnvOptions().roles!
27
- * @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
31
+ * @param options - Role locking and explicit RLS bypass (off by default).
28
32
  */
29
- export declare function generateCreateUserSQL(username: string, password: string, roles: RoleMapping, useLocksForRoles?: boolean): string;
33
+ export declare function generateCreateUserSQL(username: string, password: string, roles: RoleMapping, { useLocksForRoles, bypassRls }?: CreateUserOptions): string;
30
34
  /**
31
35
  * Generate SQL to create test users with grants to base roles.
32
36
  * Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
package/roles/index.js CHANGED
@@ -192,12 +192,12 @@ COMMIT;
192
192
  `;
193
193
  }
194
194
  /**
195
- * Generate SQL to create a user with password and grant base roles.
195
+ * Generate SQL to create or reconcile a login and grant base roles.
196
196
  * Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
197
197
  * @param roles - Role mapping from getConnEnvOptions().roles!
198
- * @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
198
+ * @param options - Role locking and explicit RLS bypass (off by default).
199
199
  */
200
- function generateCreateUserSQL(username, password, roles, useLocksForRoles = false) {
200
+ function generateCreateUserSQL(username, password, roles, { useLocksForRoles = false, bypassRls = false } = {}) {
201
201
  if (!roles) {
202
202
  throw new Error('generateCreateUserSQL: roles parameter is undefined. ' +
203
203
  'Ensure getConnEnvOptions().roles is defined.');
@@ -240,6 +240,8 @@ BEGIN
240
240
  END;
241
241
  END IF;
242
242
 
243
+ EXECUTE format('ALTER ROLE %I LOGIN INHERIT NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION ${bypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'} PASSWORD %L', v_username, v_password);
244
+
243
245
  -- Grant anonymous to user
244
246
  IF NOT EXISTS (
245
247
  SELECT 1 FROM pg_auth_members am
@@ -254,8 +256,7 @@ BEGIN
254
256
  -- 23505: Membership was granted concurrently; safe to ignore
255
257
  NULL;
256
258
  WHEN undefined_object THEN
257
- -- 42704: One of the roles doesn't exist; log notice and continue
258
- RAISE NOTICE 'Missing role when granting % to %', v_anonymous, v_username;
259
+ RAISE;
259
260
  WHEN insufficient_privilege THEN
260
261
  -- 42501: Must surface this error - caller lacks permission
261
262
  RAISE;
@@ -279,8 +280,7 @@ BEGIN
279
280
  -- 23505: Membership was granted concurrently; safe to ignore
280
281
  NULL;
281
282
  WHEN undefined_object THEN
282
- -- 42704: One of the roles doesn't exist; log notice and continue
283
- RAISE NOTICE 'Missing role when granting % to %', v_authenticated, v_username;
283
+ RAISE;
284
284
  WHEN insufficient_privilege THEN
285
285
  -- 42501: Must surface this error - caller lacks permission
286
286
  RAISE;