orchid-orm 1.64.7 → 1.64.9

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.
@@ -2165,34 +2165,43 @@ const processTableChange = async (adapter, structureToAstCtx, dbStructure, domai
2165
2165
  }
2166
2166
  };
2167
2167
 
2168
+ const defaults = {
2169
+ super: false,
2170
+ inherit: false,
2171
+ createRole: false,
2172
+ createDb: false,
2173
+ canLogin: false,
2174
+ replication: false,
2175
+ connLimit: -1,
2176
+ bypassRls: false
2177
+ };
2168
2178
  const processRoles = async (ast, dbStructure, { verifying, internal: { roles } }) => {
2169
2179
  if (!dbStructure.roles || !roles) return;
2170
- const codeRoles = roles.map(
2171
- (role) => ({
2172
- super: false,
2173
- inherit: false,
2174
- createRole: false,
2175
- createDb: false,
2176
- canLogin: false,
2177
- replication: false,
2178
- connLimit: -1,
2179
- bypassRls: false,
2180
- ...role
2181
- })
2182
- );
2180
+ const codeRoles = roles.map((role) => {
2181
+ const { defaultPrivileges: _, ...roleWithoutPrivileges } = role;
2182
+ return {
2183
+ ...defaults,
2184
+ ...roleWithoutPrivileges
2185
+ };
2186
+ });
2183
2187
  const found = /* @__PURE__ */ new Set();
2184
2188
  const dropRoles = [];
2185
2189
  for (const dbRole of dbStructure.roles) {
2190
+ const {
2191
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2192
+ defaultPrivileges: _,
2193
+ ...dbRoleWithoutPrivileges
2194
+ } = dbRole;
2186
2195
  const codeRole = codeRoles.find(
2187
2196
  (codeRole2) => dbRole.name === codeRole2.name
2188
2197
  );
2189
2198
  if (codeRole) {
2190
2199
  found.add(dbRole.name);
2191
- if (!pqb.deepCompare(dbRole, codeRole)) {
2200
+ if (!pqb.deepCompare(dbRoleWithoutPrivileges, codeRole)) {
2192
2201
  ast.push({
2193
2202
  type: "changeRole",
2194
2203
  name: dbRole.name,
2195
- from: dbRole,
2204
+ from: dbRoleWithoutPrivileges,
2196
2205
  to: codeRole
2197
2206
  });
2198
2207
  }
@@ -2249,6 +2258,349 @@ const makeRenameOrChangeAst = (dbRole, codeRole) => {
2249
2258
  }
2250
2259
  };
2251
2260
 
2261
+ const ALL_OBJECT_TYPES = [
2262
+ "TABLES",
2263
+ "SEQUENCES",
2264
+ "FUNCTIONS",
2265
+ "TYPES",
2266
+ "SCHEMAS",
2267
+ "LARGE_OBJECTS"
2268
+ ];
2269
+ const createAllObjectConfigs = (isGrantable, schema, supportedPrivileges) => {
2270
+ let types;
2271
+ if (schema) {
2272
+ types = ALL_OBJECT_TYPES.filter(
2273
+ (t) => t !== "SCHEMAS" && t !== "LARGE_OBJECTS"
2274
+ );
2275
+ } else {
2276
+ types = ALL_OBJECT_TYPES.filter((t) => {
2277
+ if (t === "LARGE_OBJECTS") {
2278
+ return supportedPrivileges.PRIVILEGES.LARGE_OBJECT !== void 0;
2279
+ }
2280
+ return true;
2281
+ });
2282
+ }
2283
+ return types.map((object) => ({
2284
+ object,
2285
+ privilegeConfigs: [{ privilege: "ALL", isGrantable }]
2286
+ }));
2287
+ };
2288
+ const objectTypeToKey = {
2289
+ TABLES: "tables",
2290
+ SEQUENCES: "sequences",
2291
+ FUNCTIONS: "functions",
2292
+ TYPES: "types",
2293
+ SCHEMAS: "schemas",
2294
+ LARGE_OBJECTS: "largeObjects"
2295
+ };
2296
+ const splitPrivilegeConfigs = (configs) => {
2297
+ const regular = [];
2298
+ const grantable = [];
2299
+ for (const p of configs) {
2300
+ if (p.isGrantable) {
2301
+ grantable.push(p.privilege);
2302
+ } else {
2303
+ regular.push(p.privilege);
2304
+ }
2305
+ }
2306
+ return { regular, grantable };
2307
+ };
2308
+ const createPrivilegeSetting = (regular, grantable) => {
2309
+ const setting = {};
2310
+ if (regular.length) setting.privileges = regular;
2311
+ if (grantable.length) setting.grantablePrivileges = grantable;
2312
+ return setting;
2313
+ };
2314
+ const collapsePrivileges = (privs, newPrivilegeConfigs, expectedPrivs, isGrantable) => {
2315
+ const hasAll = privs.some((p) => p.privilege === "ALL");
2316
+ const allPresent = hasAll || privs.length > 0 && privs.length === expectedPrivs.length && expectedPrivs.every((priv) => privs.some((p) => p.privilege === priv));
2317
+ if (allPresent) {
2318
+ newPrivilegeConfigs.push({ privilege: "ALL", isGrantable });
2319
+ } else if (privs.length > 0) {
2320
+ newPrivilegeConfigs.push(...privs);
2321
+ }
2322
+ };
2323
+ const collapsePrivilegesToAll = (privilege, objectTypeToAllPrivileges) => {
2324
+ const collapsedObjectConfigs = privilege.objectConfigs.map(
2325
+ (objConfig) => {
2326
+ const allPrivileges = objectTypeToAllPrivileges[objConfig.object];
2327
+ const expectedPrivs = allPrivileges.filter((p) => p !== "ALL");
2328
+ const regularPrivs = [];
2329
+ const grantablePrivs = [];
2330
+ for (const p of objConfig.privilegeConfigs) {
2331
+ if (p.isGrantable) {
2332
+ grantablePrivs.push(p);
2333
+ } else {
2334
+ regularPrivs.push(p);
2335
+ }
2336
+ }
2337
+ const newPrivilegeConfigs = [];
2338
+ collapsePrivileges(
2339
+ regularPrivs,
2340
+ newPrivilegeConfigs,
2341
+ expectedPrivs,
2342
+ false
2343
+ );
2344
+ collapsePrivileges(
2345
+ grantablePrivs,
2346
+ newPrivilegeConfigs,
2347
+ expectedPrivs,
2348
+ true
2349
+ );
2350
+ return {
2351
+ object: objConfig.object,
2352
+ privilegeConfigs: newPrivilegeConfigs
2353
+ };
2354
+ }
2355
+ );
2356
+ return {
2357
+ owner: privilege.owner,
2358
+ grantee: privilege.grantee,
2359
+ schema: privilege.schema,
2360
+ objectConfigs: collapsedObjectConfigs
2361
+ };
2362
+ };
2363
+ const privilegeConfigsMatch = (a, b, objectType, objectTypeToAllPrivileges) => {
2364
+ if (a.privilege === b.privilege && a.isGrantable === b.isGrantable) {
2365
+ return true;
2366
+ }
2367
+ const allPrivileges = objectTypeToAllPrivileges[objectType];
2368
+ const expectedPrivs = allPrivileges.filter((p) => p !== "ALL");
2369
+ if (a.privilege === "ALL" && a.isGrantable === b.isGrantable) {
2370
+ return expectedPrivs.includes(b.privilege);
2371
+ }
2372
+ if (b.privilege === "ALL" && a.isGrantable === b.isGrantable) {
2373
+ return expectedPrivs.includes(a.privilege);
2374
+ }
2375
+ return false;
2376
+ };
2377
+ const normalizeRoleName = (name) => {
2378
+ if (name.startsWith('"') && name.endsWith('"')) {
2379
+ return name.slice(1, -1);
2380
+ }
2381
+ return name;
2382
+ };
2383
+ const processPrivilegeConfig = (config, objectType) => {
2384
+ if (!config) return;
2385
+ const privilegeConfigs = [];
2386
+ if (config.privileges) {
2387
+ for (const p of config.privileges) {
2388
+ privilegeConfigs.push({ privilege: p, isGrantable: false });
2389
+ }
2390
+ }
2391
+ if (config.grantablePrivileges) {
2392
+ for (const p of config.grantablePrivileges) {
2393
+ privilegeConfigs.push({ privilege: p, isGrantable: true });
2394
+ }
2395
+ }
2396
+ if (privilegeConfigs.length) {
2397
+ return { object: objectType, privilegeConfigs };
2398
+ }
2399
+ return;
2400
+ };
2401
+ const hasAnyPrivilege = (obj) => {
2402
+ if (!obj) return false;
2403
+ for (const key of ALL_OBJECT_TYPES) {
2404
+ const setting = obj[objectTypeToKey[key]];
2405
+ if (setting?.privileges?.length || setting?.grantablePrivileges?.length) {
2406
+ return true;
2407
+ }
2408
+ }
2409
+ return false;
2410
+ };
2411
+ const processDefaultPrivileges = (ast, dbStructure, { internal: { roles } }) => {
2412
+ if (!dbStructure.defaultPrivileges || !roles) return;
2413
+ const supportedPrivileges = pqb.getSupportedDefaultPrivileges(
2414
+ dbStructure.version
2415
+ );
2416
+ const objectTypeToAllPrivileges = {};
2417
+ objectTypeToAllPrivileges.TABLES = supportedPrivileges.PRIVILEGES.TABLE;
2418
+ objectTypeToAllPrivileges.SEQUENCES = supportedPrivileges.PRIVILEGES.SEQUENCE;
2419
+ objectTypeToAllPrivileges.FUNCTIONS = supportedPrivileges.PRIVILEGES.FUNCTION;
2420
+ objectTypeToAllPrivileges.TYPES = supportedPrivileges.PRIVILEGES.TYPE;
2421
+ objectTypeToAllPrivileges.SCHEMAS = supportedPrivileges.PRIVILEGES.SCHEMA;
2422
+ if (supportedPrivileges.PRIVILEGES.LARGE_OBJECT) {
2423
+ objectTypeToAllPrivileges.LARGE_OBJECTS = supportedPrivileges.PRIVILEGES.LARGE_OBJECT;
2424
+ }
2425
+ const codePrivileges = /* @__PURE__ */ new Map();
2426
+ for (const role of roles) {
2427
+ if (!role.defaultPrivileges) continue;
2428
+ for (const privilege of role.defaultPrivileges) {
2429
+ const key = `${role.name}.${privilege.schema}`;
2430
+ const objectConfigs = [];
2431
+ if (privilege.allGrantable) {
2432
+ objectConfigs.push(
2433
+ ...createAllObjectConfigs(
2434
+ true,
2435
+ privilege.schema,
2436
+ supportedPrivileges
2437
+ )
2438
+ );
2439
+ } else if (privilege.all) {
2440
+ objectConfigs.push(
2441
+ ...createAllObjectConfigs(
2442
+ false,
2443
+ privilege.schema,
2444
+ supportedPrivileges
2445
+ )
2446
+ );
2447
+ }
2448
+ for (const objectType of ALL_OBJECT_TYPES) {
2449
+ if (privilege.schema && (objectType === "SCHEMAS" || objectType === "LARGE_OBJECTS")) {
2450
+ continue;
2451
+ }
2452
+ if (objectType === "LARGE_OBJECTS" && !supportedPrivileges.PRIVILEGES.LARGE_OBJECT) {
2453
+ continue;
2454
+ }
2455
+ const key2 = objectTypeToKey[objectType];
2456
+ if (key2 in privilege) {
2457
+ const config = privilege[key2];
2458
+ const processed = processPrivilegeConfig(config, objectType);
2459
+ if (processed) {
2460
+ const existingIndex = objectConfigs.findIndex(
2461
+ (o) => o.object === objectType
2462
+ );
2463
+ if (existingIndex >= 0) {
2464
+ objectConfigs[existingIndex] = processed;
2465
+ } else {
2466
+ objectConfigs.push(processed);
2467
+ }
2468
+ }
2469
+ }
2470
+ }
2471
+ if (objectConfigs.length) {
2472
+ codePrivileges.set(key, {
2473
+ owner: void 0,
2474
+ grantee: role.name,
2475
+ schema: privilege.schema,
2476
+ objectConfigs
2477
+ });
2478
+ }
2479
+ }
2480
+ }
2481
+ const found = /* @__PURE__ */ new Set();
2482
+ for (const dbPrivilege of dbStructure.defaultPrivileges) {
2483
+ const grantee = normalizeRoleName(dbPrivilege.grantee);
2484
+ if (grantee === "postgres") continue;
2485
+ const key = `${grantee}.${dbPrivilege.schema}`;
2486
+ const codePrivilege = codePrivileges.get(key);
2487
+ if (codePrivilege) {
2488
+ found.add(key);
2489
+ const grant = {};
2490
+ const revoke = {};
2491
+ for (const objectType of ALL_OBJECT_TYPES) {
2492
+ if (objectType === "LARGE_OBJECTS" && !supportedPrivileges.PRIVILEGES.LARGE_OBJECT) {
2493
+ continue;
2494
+ }
2495
+ const dbObj = dbPrivilege.objectConfigs.find(
2496
+ (o) => o.object === objectType
2497
+ );
2498
+ const codeObj = codePrivilege.objectConfigs.find(
2499
+ (o) => o.object === objectType
2500
+ );
2501
+ const dbPrivs = dbObj?.privilegeConfigs ?? [];
2502
+ const codePrivs = codeObj?.privilegeConfigs ?? [];
2503
+ const collapsedDbPrivilege = {
2504
+ owner: dbPrivilege.owner,
2505
+ grantee: dbPrivilege.grantee,
2506
+ schema: dbPrivilege.schema,
2507
+ objectConfigs: [{ object: objectType, privilegeConfigs: dbPrivs }]
2508
+ };
2509
+ const collapsedDbObj = collapsePrivilegesToAll(
2510
+ collapsedDbPrivilege,
2511
+ objectTypeToAllPrivileges
2512
+ ).objectConfigs[0];
2513
+ const collapsedDbPrivs = collapsedDbObj?.privilegeConfigs ?? [];
2514
+ const toGrant = codePrivs.filter(
2515
+ (cp) => !collapsedDbPrivs.some(
2516
+ (dp) => privilegeConfigsMatch(
2517
+ cp,
2518
+ dp,
2519
+ objectType,
2520
+ objectTypeToAllPrivileges
2521
+ )
2522
+ )
2523
+ );
2524
+ const toRevoke = dbPrivs.filter(
2525
+ (dp) => !codePrivs.some(
2526
+ (cp) => privilegeConfigsMatch(
2527
+ cp,
2528
+ dp,
2529
+ objectType,
2530
+ objectTypeToAllPrivileges
2531
+ )
2532
+ )
2533
+ );
2534
+ if (toGrant.length) {
2535
+ const { regular, grantable } = splitPrivilegeConfigs(toGrant);
2536
+ const setting = createPrivilegeSetting(regular, grantable);
2537
+ if (setting.privileges || setting.grantablePrivileges) {
2538
+ grant[objectTypeToKey[objectType]] = setting;
2539
+ }
2540
+ }
2541
+ if (toRevoke.length) {
2542
+ const { regular, grantable } = splitPrivilegeConfigs(toRevoke);
2543
+ const setting = createPrivilegeSetting(regular, grantable);
2544
+ if (setting.privileges || setting.grantablePrivileges) {
2545
+ revoke[objectTypeToKey[objectType]] = setting;
2546
+ }
2547
+ }
2548
+ }
2549
+ const hasGrant = hasAnyPrivilege(grant);
2550
+ const hasRevoke = hasAnyPrivilege(revoke);
2551
+ if (hasGrant || hasRevoke) {
2552
+ ast.push({
2553
+ type: "defaultPrivilege",
2554
+ grantee,
2555
+ schema: dbPrivilege.schema,
2556
+ grant: hasGrant ? grant : void 0,
2557
+ revoke: hasRevoke ? revoke : void 0
2558
+ });
2559
+ }
2560
+ } else {
2561
+ const revoke = {};
2562
+ for (const obj of dbPrivilege.objectConfigs) {
2563
+ const { regular, grantable } = splitPrivilegeConfigs(
2564
+ obj.privilegeConfigs
2565
+ );
2566
+ const setting = createPrivilegeSetting(regular, grantable);
2567
+ if (setting.privileges || setting.grantablePrivileges) {
2568
+ revoke[objectTypeToKey[obj.object]] = setting;
2569
+ }
2570
+ }
2571
+ if (hasAnyPrivilege(revoke)) {
2572
+ ast.push({
2573
+ type: "defaultPrivilege",
2574
+ grantee,
2575
+ schema: dbPrivilege.schema,
2576
+ revoke
2577
+ });
2578
+ }
2579
+ }
2580
+ }
2581
+ for (const [key, codePrivilege] of codePrivileges) {
2582
+ if (found.has(key)) continue;
2583
+ const grant = {};
2584
+ for (const obj of codePrivilege.objectConfigs) {
2585
+ const { regular, grantable } = splitPrivilegeConfigs(
2586
+ obj.privilegeConfigs
2587
+ );
2588
+ const setting = createPrivilegeSetting(regular, grantable);
2589
+ if (setting.privileges || setting.grantablePrivileges) {
2590
+ grant[objectTypeToKey[obj.object]] = setting;
2591
+ }
2592
+ }
2593
+ if (hasAnyPrivilege(grant)) {
2594
+ ast.push({
2595
+ type: "defaultPrivilege",
2596
+ grantee: codePrivilege.grantee,
2597
+ schema: codePrivilege.schema,
2598
+ grant
2599
+ });
2600
+ }
2601
+ }
2602
+ };
2603
+
2252
2604
  class PendingDbTypes {
2253
2605
  constructor() {
2254
2606
  this.set = /* @__PURE__ */ new Set();
@@ -2260,6 +2612,7 @@ class PendingDbTypes {
2260
2612
  const composeMigration = async (adapter, config, ast, dbStructure, params) => {
2261
2613
  const { structureToAstCtx, currentSchema } = params;
2262
2614
  await processRoles(ast, dbStructure, params);
2615
+ processDefaultPrivileges(ast, dbStructure, params);
2263
2616
  const domainsMap = rakeDb.makeDomainsMap(structureToAstCtx, dbStructure);
2264
2617
  await processSchemas(ast, dbStructure, params);
2265
2618
  processExtensions(ast, dbStructure, params);
@@ -2286,7 +2639,7 @@ const composeMigration = async (adapter, config, ast, dbStructure, params) => {
2286
2639
  };
2287
2640
 
2288
2641
  const rollbackErr = new Error("Rollback");
2289
- const verifyMigration = async (adapter, config, migrationCode, generateMigrationParams, roles) => {
2642
+ const verifyMigration = async (adapter, config, migrationCode, generateMigrationParams, roles, defaultPrivileges) => {
2290
2643
  const migrationFn = new Function("change", migrationCode);
2291
2644
  let code;
2292
2645
  try {
@@ -2303,7 +2656,8 @@ const verifyMigration = async (adapter, config, migrationCode, generateMigration
2303
2656
  await changeFn(db, true);
2304
2657
  }
2305
2658
  const dbStructure = await rakeDb.introspectDbSchema(trx, {
2306
- roles
2659
+ roles,
2660
+ loadDefaultPrivileges: defaultPrivileges?.loadDefaultPrivileges
2307
2661
  });
2308
2662
  generateMigrationParams.verifying = true;
2309
2663
  try {
@@ -2632,12 +2986,59 @@ const report = (ast, config, currentSchema) => {
2632
2986
  );
2633
2987
  break;
2634
2988
  case "renameRole":
2635
- code.push(
2636
- `${yellow("~ rename role")} ${a.from} ${yellow("=>")} ${a.to}`
2637
- );
2638
- break;
2639
2989
  case "changeRole": {
2640
- code.push(`${yellow("~ change role")} ${a.name}`);
2990
+ if (a.type === "renameRole") {
2991
+ code.push(
2992
+ `${yellow("~ rename role")} ${a.from} ${yellow("=>")} ${a.to}`
2993
+ );
2994
+ } else {
2995
+ code.push(`${yellow("~ change role")} ${a.name}`);
2996
+ }
2997
+ break;
2998
+ }
2999
+ case "defaultPrivilege": {
3000
+ const mapPrivilege = (p) => p === "ALL" ? "ALL PRIVILEGES" : p;
3001
+ const schema = a.schema ? ` in schema ${pqb.colors.pale(a.schema)}` : ` ${pqb.colors.pale("in all schemas")}`;
3002
+ const parts = [];
3003
+ if (a.grant) {
3004
+ for (const [objType, config2] of Object.entries(a.grant)) {
3005
+ if (!config2) continue;
3006
+ const type = objType.replace(/([A-Z])/g, " $1").toLowerCase();
3007
+ if (config2.privileges?.length) {
3008
+ parts.push(
3009
+ `${green("+ grant default privileges")} ${config2.privileges.map(mapPrivilege).join(", ")} on ${type} to ${a.grantee}${schema}`
3010
+ );
3011
+ }
3012
+ if (config2.grantablePrivileges?.length) {
3013
+ parts.push(
3014
+ `${green(
3015
+ "+ grant default privileges"
3016
+ )} ${config2.grantablePrivileges.map(mapPrivilege).join(", ")} on ${type} with grant option to ${a.grantee}${schema}`
3017
+ );
3018
+ }
3019
+ }
3020
+ }
3021
+ if (a.revoke) {
3022
+ for (const [objType, config2] of Object.entries(a.revoke)) {
3023
+ if (!config2) continue;
3024
+ const type = objType.replace(/([A-Z])/g, " $1").toLowerCase();
3025
+ if (config2.privileges?.length) {
3026
+ parts.push(
3027
+ `${red("- revoke default privileges")} ${config2.privileges.map(mapPrivilege).join(", ")} on ${type} from ${a.grantee}${schema}`
3028
+ );
3029
+ }
3030
+ if (config2.grantablePrivileges?.length) {
3031
+ parts.push(
3032
+ `${red(
3033
+ "- revoke default privileges"
3034
+ )} ${config2.grantablePrivileges.map(mapPrivilege).join(", ")} on ${type} with grant option from ${a.grantee}${schema}`
3035
+ );
3036
+ }
3037
+ }
3038
+ }
3039
+ if (parts.length) {
3040
+ code.push(parts.join("\n"));
3041
+ }
2641
3042
  break;
2642
3043
  }
2643
3044
  default:
@@ -2676,6 +3077,7 @@ const generate = async (adapters, config, args, afterPull) => {
2676
3077
  adapters,
2677
3078
  config,
2678
3079
  rolesDbStructureParam,
3080
+ internal.roles ? { loadDefaultPrivileges: true } : void 0,
2679
3081
  afterPull
2680
3082
  );
2681
3083
  const [adapter] = adapters;
@@ -2717,7 +3119,8 @@ const generate = async (adapters, config, args, afterPull) => {
2717
3119
  config,
2718
3120
  migrationCode,
2719
3121
  generateMigrationParams,
2720
- rolesDbStructureParam
3122
+ rolesDbStructureParam,
3123
+ internal.roles ? { loadDefaultPrivileges: true } : void 0
2721
3124
  );
2722
3125
  if (result !== void 0) {
2723
3126
  throw new Error(
@@ -2775,10 +3178,12 @@ const getDbFromConfig = async (config, dbPath) => {
2775
3178
  }
2776
3179
  return db;
2777
3180
  };
2778
- const migrateAndPullStructures = async (adapters, config, roles, afterPull) => {
3181
+ const migrateAndPullStructures = async (adapters, config, roles, defaultPrivileges, afterPull) => {
2779
3182
  if (afterPull) {
3183
+ const version = await rakeDb.getDbVersion(adapters[0]);
2780
3184
  return {
2781
3185
  dbStructure: {
3186
+ version,
2782
3187
  schemas: [],
2783
3188
  tables: [],
2784
3189
  views: [],
@@ -2799,7 +3204,8 @@ const migrateAndPullStructures = async (adapters, config, roles, afterPull) => {
2799
3204
  const dbStructures = await Promise.all(
2800
3205
  adapters.map(
2801
3206
  (adapter) => rakeDb.introspectDbSchema(adapter, {
2802
- roles
3207
+ roles,
3208
+ loadDefaultPrivileges: defaultPrivileges?.loadDefaultPrivileges
2803
3209
  })
2804
3210
  )
2805
3211
  );
@@ -2852,6 +3258,7 @@ const getActualItems = async (db, currentSchema, internal, columnTypes) => {
2852
3258
  tables: [],
2853
3259
  domains: []
2854
3260
  };
3261
+ codeItems.schemas.add(currentSchema);
2855
3262
  const domains = /* @__PURE__ */ new Map();
2856
3263
  for (const key in db) {
2857
3264
  if (key[0] === "$") continue;
@@ -2926,6 +3333,15 @@ const getActualItems = async (db, currentSchema, internal, columnTypes) => {
2926
3333
  codeItems.schemas.add(domain.schemaName);
2927
3334
  codeItems.domains.push(domain);
2928
3335
  }
3336
+ if (internal.roles) {
3337
+ for (const role of internal.roles) {
3338
+ if (role.defaultPrivileges) {
3339
+ for (const privilege of role.defaultPrivileges) {
3340
+ if (privilege.schema) codeItems.schemas.add(privilege.schema);
3341
+ }
3342
+ }
3343
+ }
3344
+ }
2929
3345
  return codeItems;
2930
3346
  };
2931
3347
  const processEnumColumn = (column, currentSchema, codeItems) => {