@rebasepro/server-postgres 0.29.0 → 0.29.1

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 (109) hide show
  1. package/dist/{BranchService-JiYJ_n9E.js → BranchService-BIIBF5ZL.js} +3 -3
  2. package/dist/{BranchService-JiYJ_n9E.js.map → BranchService-BIIBF5ZL.js.map} +1 -1
  3. package/dist/PostgresBackendDriver.d.ts +27 -9
  4. package/dist/PostgresBootstrapper.d.ts +14 -0
  5. package/dist/{backup-cli-D_aKXPyX.js → backup-cli-QcOpmRpQ.js} +3 -3
  6. package/dist/{backup-cli-D_aKXPyX.js.map → backup-cli-QcOpmRpQ.js.map} +1 -1
  7. package/dist/{boot-ddl-D4W9o9xE.js → boot-ddl-BSNpEUOS.js} +2 -2
  8. package/dist/{boot-ddl-D4W9o9xE.js.map → boot-ddl-BSNpEUOS.js.map} +1 -1
  9. package/dist/{cli-console-DPdZCWTi.js → cli-console-DTsm96lW.js} +5 -5
  10. package/dist/{cli-console-DPdZCWTi.js.map → cli-console-DTsm96lW.js.map} +1 -1
  11. package/dist/{cli-errors-D8s4z_3g.js → cli-errors-DwqFRIWz.js} +49 -6
  12. package/dist/{cli-errors-D8s4z_3g.js.map → cli-errors-DwqFRIWz.js.map} +1 -1
  13. package/dist/cli.js +81 -41
  14. package/dist/cli.js.map +1 -1
  15. package/dist/database-preflight-D5JtPt8i.js +151 -0
  16. package/dist/database-preflight-D5JtPt8i.js.map +1 -0
  17. package/dist/db-subcommands.d.ts +1 -1
  18. package/dist/{deferred-index-build-F2GWu009.js → deferred-index-build-B8feKnUj.js} +12 -8
  19. package/dist/deferred-index-build-B8feKnUj.js.map +1 -0
  20. package/dist/{doctor-_g2tHRtG.js → doctor-BaR11xUe.js} +6 -6
  21. package/dist/{doctor-_g2tHRtG.js.map → doctor-BaR11xUe.js.map} +1 -1
  22. package/dist/{ensure-collection-policies-DUpWJb5D.js → ensure-collection-policies-85HiG-k1.js} +8 -8
  23. package/dist/{ensure-collection-policies-DUpWJb5D.js.map → ensure-collection-policies-85HiG-k1.js.map} +1 -1
  24. package/dist/{ensure-collection-tables-BK--gDo6.js → ensure-collection-tables-DR_WcxLA.js} +15 -10
  25. package/dist/ensure-collection-tables-DR_WcxLA.js.map +1 -0
  26. package/dist/{ensure-tables-Bx1DYarz.js → ensure-tables-Dh5UP_Zs.js} +4 -4
  27. package/dist/{ensure-tables-Bx1DYarz.js.map → ensure-tables-Dh5UP_Zs.js.map} +1 -1
  28. package/dist/{enum-labels-kept-DyFE4Gaq.js → enum-labels-kept-DSU8lAnd.js} +3 -3
  29. package/dist/{enum-labels-kept-DyFE4Gaq.js.map → enum-labels-kept-DSU8lAnd.js.map} +1 -1
  30. package/dist/{generate-drizzle-schema-taNTu3xv.js → generate-drizzle-schema-5spbTyQ6.js} +2 -2
  31. package/dist/{generate-drizzle-schema-taNTu3xv.js.map → generate-drizzle-schema-5spbTyQ6.js.map} +1 -1
  32. package/dist/{generate-drizzle-schema-logic-DpFA1UVd.js → generate-drizzle-schema-logic-C5FB7Fpo.js} +2 -2
  33. package/dist/{generate-drizzle-schema-logic-DpFA1UVd.js.map → generate-drizzle-schema-logic-C5FB7Fpo.js.map} +1 -1
  34. package/dist/{generate-files-DbwU8Btx.js → generate-files-Bl3_D_oP.js} +3 -3
  35. package/dist/{generate-files-DbwU8Btx.js.map → generate-files-Bl3_D_oP.js.map} +1 -1
  36. package/dist/{generate-postgres-ddl-logic-ISVgsP34.js → generate-postgres-ddl-logic-BC3JA93M.js} +3 -3
  37. package/dist/{generate-postgres-ddl-logic-ISVgsP34.js.map → generate-postgres-ddl-logic-BC3JA93M.js.map} +1 -1
  38. package/dist/{generated-schema-diff-4lOC0g1_.js → generated-schema-diff-Jm93vyJB.js} +12 -4
  39. package/dist/generated-schema-diff-Jm93vyJB.js.map +1 -0
  40. package/dist/index.d.ts +2 -1
  41. package/dist/index.es.js +20 -12
  42. package/dist/index.es.js.map +1 -1
  43. package/dist/{migrate-baseline-BeepEphh.js → migrate-baseline-BfHmq3vN.js} +49 -4
  44. package/dist/{migrate-baseline-BeepEphh.js.map → migrate-baseline-BfHmq3vN.js.map} +1 -1
  45. package/dist/{migrate-policy-stamps-cYMJ_9Ha.js → migrate-policy-stamps-B4k1ggma.js} +6 -6
  46. package/dist/{migrate-policy-stamps-cYMJ_9Ha.js.map → migrate-policy-stamps-B4k1ggma.js.map} +1 -1
  47. package/dist/{open-rebase-CTNBmmH8.js → open-rebase-CiO_sjMT.js} +465 -80
  48. package/dist/open-rebase-CiO_sjMT.js.map +1 -0
  49. package/dist/open-rebase.d.ts +6 -1
  50. package/dist/{pg-error-utils-BLOVXK67.js → pg-error-utils-D1Nc0UML.js} +2 -2
  51. package/dist/{pg-error-utils-BLOVXK67.js.map → pg-error-utils-D1Nc0UML.js.map} +1 -1
  52. package/dist/{plan-schema-CMNWvqIa.js → plan-schema-BYxOzflz.js} +89 -9
  53. package/dist/plan-schema-BYxOzflz.js.map +1 -0
  54. package/dist/{policy-drift-IjD2AUD-.js → policy-drift-DKuTJHfc.js} +2 -2
  55. package/dist/{policy-drift-IjD2AUD-.js.map → policy-drift-DKuTJHfc.js.map} +1 -1
  56. package/dist/{push-index-prebuild-CIvajIrL.js → push-index-prebuild-bqXimSZz.js} +4 -4
  57. package/dist/{push-index-prebuild-CIvajIrL.js.map → push-index-prebuild-bqXimSZz.js.map} +1 -1
  58. package/dist/{push-kept-defaults-CLbsuSmo.js → push-kept-defaults-CN9R8cHf.js} +2 -2
  59. package/dist/{push-kept-defaults-CLbsuSmo.js.map → push-kept-defaults-CN9R8cHf.js.map} +1 -1
  60. package/dist/{push-legacy-renames-DeW_HTLJ.js → push-legacy-renames-CU_UYPbz.js} +4 -4
  61. package/dist/{push-legacy-renames-DeW_HTLJ.js.map → push-legacy-renames-CU_UYPbz.js.map} +1 -1
  62. package/dist/{push-policy-plan--oRXOj4X.js → push-policy-plan-JcyK94bc.js} +4 -4
  63. package/dist/{push-policy-plan--oRXOj4X.js.map → push-policy-plan-JcyK94bc.js.map} +1 -1
  64. package/dist/{render-ddl-CzVcbbR1.js → render-ddl-DCdVP-pQ.js} +27 -10
  65. package/dist/render-ddl-DCdVP-pQ.js.map +1 -0
  66. package/dist/request-role-cli-DSdRtvgH.js +260 -0
  67. package/dist/request-role-cli-DSdRtvgH.js.map +1 -0
  68. package/dist/request-role-cli.d.ts +86 -0
  69. package/dist/request-role-migration-D9BZ5Uba.js +150 -0
  70. package/dist/request-role-migration-D9BZ5Uba.js.map +1 -0
  71. package/dist/rls-enforcement-BO618rnr.js +992 -0
  72. package/dist/rls-enforcement-BO618rnr.js.map +1 -0
  73. package/dist/rls-settings-De5NoHHy.js +211 -0
  74. package/dist/rls-settings-De5NoHHy.js.map +1 -0
  75. package/dist/schema/doctor-cli.js +144 -6
  76. package/dist/schema/doctor-cli.js.map +1 -1
  77. package/dist/schema/doctor-database.d.ts +27 -0
  78. package/dist/schema/generate-drizzle-schema.js +1 -1
  79. package/dist/schema/generate-postgres-ddl.js +1 -1
  80. package/dist/schema/introspect-db.js +1 -1
  81. package/dist/schema/plan/diff-plan.d.ts +6 -1
  82. package/dist/schema/plan/render-ddl.d.ts +10 -3
  83. package/dist/schema/plan/tenant-keep-trigger.d.ts +9 -0
  84. package/dist/schema/plan/types.d.ts +15 -0
  85. package/dist/schema/plan/updated-at-trigger.d.ts +1 -1
  86. package/dist/schema/plan/view-names.d.ts +6 -0
  87. package/dist/schema/rls-bootstrap-sql.d.ts +23 -0
  88. package/dist/security/caller-sql-columns.d.ts +60 -0
  89. package/dist/security/caller-sql.d.ts +8 -0
  90. package/dist/security/database-preflight.d.ts +24 -0
  91. package/dist/security/request-role-migration.d.ts +36 -0
  92. package/dist/security/rls-enforcement.d.ts +191 -21
  93. package/dist/security/rls-settings.d.ts +177 -0
  94. package/dist/services/dataService.d.ts +2 -0
  95. package/dist/services/realtimeService.d.ts +3 -0
  96. package/dist/services/view-access.d.ts +2 -2
  97. package/dist/view-names-Dscp6--B.js +24 -0
  98. package/dist/view-names-Dscp6--B.js.map +1 -0
  99. package/dist/{websocket-D2y88dOa.js → websocket-B33YjKhs.js} +3 -3
  100. package/dist/{websocket-D2y88dOa.js.map → websocket-B33YjKhs.js.map} +1 -1
  101. package/package.json +7 -7
  102. package/dist/deferred-index-build-F2GWu009.js.map +0 -1
  103. package/dist/ensure-collection-tables-BK--gDo6.js.map +0 -1
  104. package/dist/generated-schema-diff-4lOC0g1_.js.map +0 -1
  105. package/dist/open-rebase-CTNBmmH8.js.map +0 -1
  106. package/dist/plan-schema-CMNWvqIa.js.map +0 -1
  107. package/dist/render-ddl-CzVcbbR1.js.map +0 -1
  108. package/dist/rls-enforcement-jZTv1yci.js +0 -534
  109. package/dist/rls-enforcement-jZTv1yci.js.map +0 -1
package/dist/cli.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { createRequire as __createRequire } from "module";
2
2
  __createRequire(import.meta.url);
3
3
  import { n as require_arg, o as __toESM, t as promptConfirm } from "./cli-prompt-DXG0yk-h.js";
4
- import { $ as isSyncedPlan, A as getTriggerExcludes, B as readViewsDdl, C as diagnoseMissingBin, D as getForeignIndexExcludes, E as ensureDevDatabaseExists, F as queryGeneratedColumnDependencies, G as GENERATED_SQL_DIR, H as withAppClient, I as queryUndeclarableConstraints, J as decidePushSafety, K as generatedSqlDir, L as readSearchDdl, M as getVectorExcludes, N as loadCollectionsForCli, O as getSearchExcludes, P as queryColumnTypes, Q as fromAlterTable, R as readTriggersDdl, S as detectProjectPackageManager, T as dropGeneratedColumns, U as workspaceMemberDir, V as resolveLocalBin, W as DESIRED_STATE_URL, X as detectDestructiveStatements, Y as destructiveOptInFlag, Z as extractPlanStatements, _ as atlasDevDatabaseUrl, a as diagnoseDbError, b as describeDevAddCommand, c as isEconnrefused, d as reportCommandFailure, et as warnIfYesApprovedDestructive, f as ExcludeIntrospectionError, g as applyViewsDdl, h as applyVectorDdl, i as diagnoseAtlasFailure, j as getUndeclaredConstraintExcludes, k as getTableExcludes, l as isSslNotEnabled, m as applyTriggersDdl, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as prepareGeneratedSqlDir, rt as redactConnectionPasswords, s as isAuthFailure, t as checkDatabaseConnectivity, tt as forAtlas, v as closeAppClients, w as dropDevDatabase, x as describeReinstallCommand, y as describeBuildScriptRemedy, z as readVectorDdl } from "./cli-errors-D8s4z_3g.js";
4
+ import { $ as fromAlterTable, A as getTableExcludes, B as readVectorDdl, C as detectProjectPackageManager, D as ensureDevDatabaseExists, E as dropGeneratedColumns, F as queryColumnTypes, G as DESIRED_STATE_URL, H as resolveLocalBin, I as queryGeneratedColumnDependencies, J as prepareGeneratedSqlDir, K as GENERATED_SQL_DIR, L as queryUndeclarableConstraints, M as getUndeclaredConstraintExcludes, N as getVectorExcludes, O as getForeignIndexExcludes, P as loadCollectionsForCli, Q as extractPlanStatements, R as readSearchDdl, S as describeReinstallCommand, T as dropDevDatabase, U as withAppClient, V as readViewsDdl, W as workspaceMemberDir, X as destructiveOptInFlag, Y as decidePushSafety, Z as detectDestructiveStatements, _ as atlasDevDatabaseUrl, a as diagnoseDbError, b as describeBuildScriptRemedy, c as isEconnrefused, d as reportCommandFailure, et as isSyncedPlan, f as ExcludeIntrospectionError, g as applyViewsDdl, h as applyVectorDdl, i as diagnoseAtlasFailure, it as redactConnectionPasswords, j as getTriggerExcludes, k as getSearchExcludes, l as isSslNotEnabled, m as applyTriggersDdl, nt as forAtlas, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as generatedSqlDir, s as isAuthFailure, t as checkDatabaseConnectivity, tt as warnIfYesApprovedDestructive, w as diagnoseMissingBin, x as describeDevAddCommand, y as closeAppClients, z as readTriggersDdl } from "./cli-errors-DwqFRIWz.js";
5
5
  import { a as outWarn, i as outError, o as atlasExcludePattern, r as out, s as excludePatternParts, t as chalk } from "./source-fZb92pN8.js";
6
6
  import { t as nextStepAfterDbGenerate } from "./generate-next-step-DgK5BlBn.js";
7
- import { D as execa, S as RLS_BOOTSTRAP_SQL, b as parseDriverLine, c as isDriverDbSubcommand, d as branchNameIn, f as branchSourceIn, g as assertKnownFlags, i as latestRecordedMigration, l as backupActionOf, m as unexpectedBranchArgs, o as planBaseline, p as resolveBranchSwitches, r as describeBaselinePlan, s as DRIVER_DB_SUBCOMMANDS, t as baselineVersionProblem, v as collectionsPathIn, w as dropLegacyAuthSchema, x as resolveDriverSwitches } from "./migrate-baseline-BeepEphh.js";
7
+ import { C as RLS_BOOTSTRAP_SQL, O as execa, S as REQUEST_ROLE_FUNCTION_SQL, T as dropLegacyAuthSchema, b as parseDriverLine, c as isDriverDbSubcommand, d as branchNameIn, f as branchSourceIn, g as assertKnownFlags, i as latestRecordedMigration, l as backupActionOf, m as unexpectedBranchArgs, o as planBaseline, p as resolveBranchSwitches, r as describeBaselinePlan, s as DRIVER_DB_SUBCOMMANDS, t as baselineVersionProblem, v as collectionsPathIn, x as resolveDriverSwitches } from "./migrate-baseline-BfHmq3vN.js";
8
+ import { declaredRlsPolicyShape } from "@rebasepro/types";
8
9
  import { formatRelativeTime } from "@rebasepro/utils";
9
10
  import path from "path";
10
11
  import fs from "fs";
@@ -1121,6 +1122,12 @@ function planPrune(input, options = {}) {
1121
1122
  }
1122
1123
  //#endregion
1123
1124
  //#region src/cli.ts
1125
+ /**
1126
+ * The RLS helpers a migration or a push creates ahead of the policies — with
1127
+ * `rebase.is_request_role` for a project that declared
1128
+ * `rls.policyTarget: "requestRole"`, whose every permissive policy calls it.
1129
+ */
1130
+ var rlsBootstrapSql = () => declaredRlsPolicyShape().policyTarget === "requestRole" ? `${RLS_BOOTSTRAP_SQL}\n${REQUEST_ROLE_FUNCTION_SQL};\n` : RLS_BOOTSTRAP_SQL;
1124
1131
  var __cliDirname = path.dirname(fileURLToPath(import.meta.url));
1125
1132
  /**
1126
1133
  * A script this CLI spawns, and how to run it.
@@ -1207,7 +1214,7 @@ function generatesInProcess() {
1207
1214
  async function generateInProcess(what, label, run) {
1208
1215
  let generators;
1209
1216
  try {
1210
- generators = await import("./generate-files-DbwU8Btx.js").then((n) => n.t);
1217
+ generators = await import("./generate-files-Bl3_D_oP.js").then((n) => n.t);
1211
1218
  } catch (err) {
1212
1219
  outError(chalk.red(`✗ Failed to run ${what}: ${err instanceof Error ? err.message : String(err)}`));
1213
1220
  process.exit(1);
@@ -1254,7 +1261,7 @@ async function runPluginCommand(args) {
1254
1261
  else if (domain === "schema") await schemaCommand(subcommand, args);
1255
1262
  else if (domain === "doctor") await doctorPluginCommand(args);
1256
1263
  else if (domain === "console") {
1257
- const { consoleCommand } = await import("./cli-console-DPdZCWTi.js");
1264
+ const { consoleCommand } = await import("./cli-console-DTsm96lW.js");
1258
1265
  process.exitCode = await consoleCommand(args);
1259
1266
  } else {
1260
1267
  outError(chalk.red(`Unknown domain command: ${domain}`));
@@ -1420,8 +1427,18 @@ async function dbCommand(subcommand, rawArgs) {
1420
1427
  await branchCommand(rawArgs);
1421
1428
  return;
1422
1429
  }
1430
+ if (subcommand === "request-role") {
1431
+ const { requestRoleCommand } = await import("./request-role-cli-DSdRtvgH.js").then((n) => n.r);
1432
+ await requestRoleCommand(rawArgs);
1433
+ return;
1434
+ }
1435
+ if (subcommand === "provision") {
1436
+ const { provisionCommand } = await import("./request-role-cli-DSdRtvgH.js").then((n) => n.r);
1437
+ await provisionCommand(rawArgs);
1438
+ return;
1439
+ }
1423
1440
  if (subcommand === "backup" || subcommand === "restore" || subcommand === "backups") {
1424
- const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-D_aKXPyX.js").then((n) => n.t);
1441
+ const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-QcOpmRpQ.js").then((n) => n.t);
1425
1442
  if (subcommand === "backup" && backupActionOf(rawArgs) === "list") await backupsCommand(rawArgs);
1426
1443
  else if (subcommand === "backup") await backupCommand(rawArgs);
1427
1444
  else if (subcommand === "restore") await restoreCommand(rawArgs);
@@ -1468,7 +1485,7 @@ async function dbCommand(subcommand, rawArgs) {
1468
1485
  }
1469
1486
  const searchContent = readSearchDdl();
1470
1487
  if (searchContent) {
1471
- const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-ISVgsP34.js").then((n) => n.s);
1488
+ const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-BC3JA93M.js").then((n) => n.s);
1472
1489
  const migrationConflicts = findGeneratedColumnConflicts(parseColumnMutations(migrationContent), searchColumnDependencies(await loadCollectionsForCli(collectionsPath)));
1473
1490
  const preamble = migrationDropPreamble(migrationConflicts);
1474
1491
  if (preamble) {
@@ -1492,7 +1509,7 @@ async function dbCommand(subcommand, rawArgs) {
1492
1509
  const policiesFile = path.join(generatedSqlDir(), "policies.sql");
1493
1510
  if (fs.existsSync(policiesFile)) {
1494
1511
  const policiesContent = fs.readFileSync(policiesFile, "utf-8");
1495
- fs.appendFileSync(newestMigrationFile, "\n\n" + RLS_BOOTSTRAP_SQL + "\n" + policiesContent);
1512
+ fs.appendFileSync(newestMigrationFile, "\n\n" + rlsBootstrapSql() + "\n" + policiesContent);
1496
1513
  out(chalk.gray(` ✓ Appended RLS policies to migration file: ${path.basename(newestMigrationFile)}`));
1497
1514
  out(chalk.gray(" Re-hashing migration files..."));
1498
1515
  await runAtlas("migrate", [
@@ -1742,7 +1759,7 @@ async function dbCommand(subcommand, rawArgs) {
1742
1759
  if (databaseUrl) {
1743
1760
  await ensureRlsUserRole(databaseUrl);
1744
1761
  await retireLegacyAuthSchema(databaseUrl);
1745
- const { stampMigratedPolicies } = await import("./migrate-policy-stamps-cYMJ_9Ha.js");
1762
+ const { stampMigratedPolicies } = await import("./migrate-policy-stamps-B4k1ggma.js");
1746
1763
  await stampMigratedPolicies(databaseUrl, collectionsPath);
1747
1764
  }
1748
1765
  }
@@ -1770,8 +1787,8 @@ async function dbCommand(subcommand, rawArgs) {
1770
1787
  * no such column reads nothing.
1771
1788
  */
1772
1789
  async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
1773
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
1774
- const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-CLbsuSmo.js");
1790
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
1791
+ const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-CN9R8cHf.js");
1775
1792
  const columns = databaseOwnedDefaultColumns(await loadCollections(path.resolve(process.cwd(), collectionsPath)));
1776
1793
  if (columns.length === 0) return;
1777
1794
  let kept;
@@ -1796,8 +1813,8 @@ async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
1796
1813
  async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
1797
1814
  let renames;
1798
1815
  try {
1799
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
1800
- const { legacyForeignKeyRenames } = await import("./push-legacy-renames-DeW_HTLJ.js");
1816
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
1817
+ const { legacyForeignKeyRenames } = await import("./push-legacy-renames-CU_UYPbz.js");
1801
1818
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1802
1819
  renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1803
1820
  } catch {
@@ -1816,8 +1833,8 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
1816
1833
  /** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
1817
1834
  async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
1818
1835
  try {
1819
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
1820
- const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-DyFE4Gaq.js");
1836
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
1837
+ const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-DSU8lAnd.js");
1821
1838
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1822
1839
  const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1823
1840
  if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
@@ -1826,8 +1843,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
1826
1843
  async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
1827
1844
  let missing;
1828
1845
  try {
1829
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
1830
- const { missingForeignKeyIndexes } = await import("./push-index-prebuild-CIvajIrL.js");
1846
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
1847
+ const { missingForeignKeyIndexes } = await import("./push-index-prebuild-bqXimSZz.js");
1831
1848
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1832
1849
  missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1833
1850
  } catch {
@@ -1837,7 +1854,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
1837
1854
  if (missing.length === 0 || dryRun) return names;
1838
1855
  out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
1839
1856
  try {
1840
- const { buildDeferredIndexes } = await import("./deferred-index-build-F2GWu009.js").then((n) => n.r);
1857
+ const { buildDeferredIndexes } = await import("./deferred-index-build-B8feKnUj.js").then((n) => n.r);
1841
1858
  const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
1842
1859
  dedicated: true,
1843
1860
  query: async (text) => ({ rows: (await client.query(text)).rows }),
@@ -1853,7 +1870,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
1853
1870
  async function ensureAuthSchemaAndFunctions(databaseUrl) {
1854
1871
  try {
1855
1872
  await withAppClient(databaseUrl, async (client) => {
1856
- await client.query(RLS_BOOTSTRAP_SQL);
1873
+ await client.query(rlsBootstrapSql());
1857
1874
  });
1858
1875
  } catch (err) {
1859
1876
  if (isEconnrefused(err) || isAuthFailure(err) || isSslNotEnabled(err)) {
@@ -1885,11 +1902,19 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
1885
1902
  let unsecured;
1886
1903
  let userRole;
1887
1904
  try {
1888
- const { lockCollectionTables } = await import("./ensure-collection-policies-DUpWJb5D.js");
1889
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
1890
- userRole = (await import("./rls-enforcement-jZTv1yci.js").then((n) => n.u)).REBASE_USER_ROLE;
1905
+ const { lockCollectionTables } = await import("./ensure-collection-policies-85HiG-k1.js");
1906
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
1907
+ const { readRecordedRequestRoles } = await import("./rls-enforcement-BO618rnr.js").then((n) => n.v);
1908
+ const { cliRlsSettings } = await import("./rls-settings-De5NoHHy.js").then((n) => n.a);
1891
1909
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1892
- ({unsecured} = await withAppClient(databaseUrl, (client) => lockCollectionTables({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections)));
1910
+ ({unsecured, userRole} = await withAppClient(databaseUrl, async (client) => {
1911
+ const runSql = async (text) => (await client.query(text)).rows;
1912
+ const roles = cliRlsSettings(await readRecordedRequestRoles(runSql)).roles;
1913
+ return {
1914
+ unsecured: (await lockCollectionTables({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections)).unsecured,
1915
+ userRole: roles.join(", ")
1916
+ };
1917
+ }));
1893
1918
  } catch (err) {
1894
1919
  outError(chalk.red(`\n ✗ The schema was applied, but row-level security could not be switched on for its tables: ${err instanceof Error ? err.message : String(err)}`));
1895
1920
  outError(chalk.gray(" A table this push created may be readable and writable by every authenticated request\n until it is. Re-run `rebase db push` — it locks every collection table before anything else."));
@@ -1922,8 +1947,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
1922
1947
  async function ensureAuthTables(databaseUrl, collectionsPath) {
1923
1948
  try {
1924
1949
  const { drizzle } = await import("drizzle-orm/node-postgres");
1925
- const { ensureAuthTablesExist } = await import("./ensure-tables-Bx1DYarz.js").then((n) => n.n);
1926
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
1950
+ const { ensureAuthTablesExist } = await import("./ensure-tables-Dh5UP_Zs.js").then((n) => n.n);
1951
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
1927
1952
  const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
1928
1953
  const a = c.auth;
1929
1954
  return a === true || typeof a === "object" && a !== null && a.enabled === true;
@@ -1943,22 +1968,35 @@ async function ensureRlsUserRole(databaseUrl) {
1943
1968
  const schemas = ["public", "rebase"];
1944
1969
  let rls;
1945
1970
  try {
1946
- rls = await import("./rls-enforcement-jZTv1yci.js").then((n) => n.u);
1971
+ rls = await import("./rls-enforcement-BO618rnr.js").then((n) => n.v);
1947
1972
  } catch (err) {
1948
1973
  outError(chalk.red(`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`));
1949
1974
  return;
1950
1975
  }
1976
+ let connectionRole;
1977
+ let settings;
1951
1978
  try {
1952
1979
  await withAppClient(databaseUrl, async (client) => {
1953
1980
  const runSql = async (text) => (await client.query(text)).rows;
1954
- if ((await rls.detectConnectionPosture(runSql)).privileged) {
1955
- await rls.ensureAppRole(runSql, schemas);
1956
- out(chalk.gray(` ✓ RLS role "${rls.REBASE_USER_ROLE}" provisioned/refreshed.`));
1981
+ const posture = await rls.detectConnectionPosture(runSql);
1982
+ connectionRole = posture.role;
1983
+ if (posture.privileged) {
1984
+ const recorded = await rls.readRecordedRequestRoles(runSql);
1985
+ settings = (await import("./rls-settings-De5NoHHy.js").then((n) => n.a)).cliRlsSettings(recorded);
1986
+ rls.assertRecordedRequestRoles(settings.roles, recorded, await rls.roleHoldsTableGrants(runSql, schemas));
1987
+ if (recorded ? recorded.join(",") !== settings.roles.join(",") : settings.roles.join(",") !== rls.REBASE_USER_ROLE) await rls.recordRequestRoles(runSql, settings.roles);
1988
+ for (const role of settings.roles) await rls.ensureAppRole(runSql, schemas, {
1989
+ role,
1990
+ provisionRole: settings.provisionRole,
1991
+ grants: settings.grants
1992
+ });
1993
+ out(chalk.gray(` ✓ RLS role ${settings.roles.map((r) => `"${r}"`).join(", ")} provisioned/refreshed.`));
1957
1994
  }
1958
1995
  });
1959
1996
  } catch (err) {
1960
- outError(chalk.red(`\n ✗ The schema change was applied, but the "${rls.REBASE_USER_ROLE}" role could not be provisioned: ${err instanceof Error ? err.message : String(err)}`));
1961
- outError(chalk.gray(rls.appRoleSetupInstructions("your database user", schemas)));
1997
+ const setup = err instanceof rls.AppRoleSetupError;
1998
+ outError(chalk.red(`\n ✗ The schema change was applied, but the "${settings?.defaultRole ?? rls.REBASE_USER_ROLE}" role could not be provisioned: ${setup ? err.message.slice(0, -err.instructions.length).trimEnd() : err instanceof Error ? err.message : String(err)}`));
1999
+ outError(chalk.gray(setup ? err.instructions : rls.appRoleSetupInstructions(connectionRole, schemas, settings?.defaultRole, settings?.grants)));
1962
2000
  }
1963
2001
  }
1964
2002
  /**
@@ -2003,9 +2041,9 @@ async function applyPolicies(databaseUrl, collectionsPath) {
2003
2041
  */
2004
2042
  async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
2005
2043
  try {
2006
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
2007
- const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-ISVgsP34.js").then((n) => n.s);
2008
- const { policyStampSql } = await import("./ensure-collection-policies-DUpWJb5D.js");
2044
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
2045
+ const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-BC3JA93M.js").then((n) => n.s);
2046
+ const { policyStampSql } = await import("./ensure-collection-policies-85HiG-k1.js");
2009
2047
  const { pinSearchPath } = await import("./connection-COuS5Fm-.js").then((n) => n.r);
2010
2048
  return {
2011
2049
  statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
@@ -2023,8 +2061,8 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
2023
2061
  */
2024
2062
  async function readPolicyPushPlan(databaseUrl, collectionsPath) {
2025
2063
  try {
2026
- const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan--oRXOj4X.js");
2027
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
2064
+ const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-JcyK94bc.js");
2065
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
2028
2066
  const { pinSearchPath } = await import("./connection-COuS5Fm-.js").then((n) => n.r);
2029
2067
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2030
2068
  const plan = await withAppClient(databaseUrl, (client) => planPolicyPush({ query: async (text, values) => ({ rows: (await client.query(text, values)).rows }) }, collections, { searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public" }));
@@ -2052,8 +2090,8 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
2052
2090
  */
2053
2091
  async function reconcilePolicies(databaseUrl, collectionsPath) {
2054
2092
  try {
2055
- const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-IjD2AUD-.js").then((n) => n.s);
2056
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
2093
+ const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-DKuTJHfc.js").then((n) => n.s);
2094
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
2057
2095
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2058
2096
  await withAppClient(databaseUrl, async (client) => {
2059
2097
  const drift = await checkPolicyDrift(client, collections);
@@ -2139,7 +2177,7 @@ async function branchCommand(rawArgs) {
2139
2177
  process.exit(1);
2140
2178
  }
2141
2179
  const { DatabasePoolManager } = await import("./databasePoolManager-7hXVurmG.js").then((n) => n.n);
2142
- const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-JiYJ_n9E.js").then((n) => n.n);
2180
+ const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-BIIBF5ZL.js").then((n) => n.n);
2143
2181
  const { drizzle } = await import("drizzle-orm/node-postgres");
2144
2182
  const { Pool } = await import("pg");
2145
2183
  const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
@@ -2686,9 +2724,9 @@ async function schemaStaleCommand(rawArgs) {
2686
2724
  const schemaFile = path.resolve(process.cwd(), outputPath);
2687
2725
  const fix = Boolean(argsList["--fix"]);
2688
2726
  const generatedExists = fs.existsSync(schemaFile);
2689
- const { loadCollections } = await import("./doctor-_g2tHRtG.js").then((n) => n.t);
2727
+ const { loadCollections } = await import("./doctor-BaR11xUe.js").then((n) => n.t);
2690
2728
  const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-BvNF3i-s.js").then((n) => n.r);
2691
- const { generateSchema } = await import("./generate-drizzle-schema-logic-DpFA1UVd.js").then((n) => n.n);
2729
+ const { generateSchema } = await import("./generate-drizzle-schema-logic-C5FB7Fpo.js").then((n) => n.n);
2692
2730
  const { relationalCollections } = await import("@rebasepro/common");
2693
2731
  let stale = [];
2694
2732
  let differences = [];
@@ -2849,6 +2887,7 @@ async function doctorPluginCommand(rawArgs) {
2849
2887
  "--schema": String,
2850
2888
  "--sdk": String,
2851
2889
  "--policies": Boolean,
2890
+ "--database": Boolean,
2852
2891
  "-c": "--collections",
2853
2892
  "-s": "--schema",
2854
2893
  "-k": "--sdk"
@@ -2870,7 +2909,8 @@ async function doctorPluginCommand(rawArgs) {
2870
2909
  `--collections=${collectionsPath}`,
2871
2910
  `--schema=${schemaPath}`,
2872
2911
  `--sdk=${sdkPath}`,
2873
- ...parsedArgs["--policies"] ? ["--policies"] : []
2912
+ ...parsedArgs["--policies"] ? ["--policies"] : [],
2913
+ ...parsedArgs["--database"] ? ["--database"] : []
2874
2914
  ];
2875
2915
  try {
2876
2916
  await execa(cmdParts[0], cmdParts.slice(1), {