@rebasepro/server-postgres 0.25.0-canary.ge06257e → 0.25.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 (126) hide show
  1. package/dist/{BranchService-DNg4txyf.js → BranchService-ClklxyAQ.js} +283 -20
  2. package/dist/BranchService-ClklxyAQ.js.map +1 -0
  3. package/dist/backup/backup-cli.d.ts +70 -1
  4. package/dist/backup/backup-service.d.ts +79 -0
  5. package/dist/backup/pg-binary.d.ts +2 -2
  6. package/dist/backup/pg-tools.d.ts +60 -1
  7. package/dist/backup-cli-gijeXe0u.js +1961 -0
  8. package/dist/backup-cli-gijeXe0u.js.map +1 -0
  9. package/dist/{boot-ddl-Dnvpmm_T.js → boot-ddl-DYH95Qeg.js} +3 -3
  10. package/dist/{boot-ddl-Dnvpmm_T.js.map → boot-ddl-DYH95Qeg.js.map} +1 -1
  11. package/dist/branch-argv.d.ts +15 -0
  12. package/dist/branch-prune.d.ts +18 -0
  13. package/dist/{cli-console-C_ISGwJo.js → cli-console-CQrQ0lAY.js} +19 -13
  14. package/dist/cli-console-CQrQ0lAY.js.map +1 -0
  15. package/dist/cli-console.d.ts +4 -3
  16. package/dist/{cli-errors-mx4sSjB8.js → cli-errors-DiA0XFIS.js} +110 -14
  17. package/dist/{cli-errors-mx4sSjB8.js.map → cli-errors-DiA0XFIS.js.map} +1 -1
  18. package/dist/cli-errors.d.ts +26 -1
  19. package/dist/cli-flags.d.ts +51 -0
  20. package/dist/{cli-prompt-egtNKkZl.js → cli-prompt-DXG0yk-h.js} +39 -4
  21. package/dist/{cli-prompt-egtNKkZl.js.map → cli-prompt-DXG0yk-h.js.map} +1 -1
  22. package/dist/cli.js +120 -184
  23. package/dist/cli.js.map +1 -1
  24. package/dist/collections/validate-relations.d.ts +8 -2
  25. package/dist/{column-plan-helpers-D_V4oaZh.js → column-plan-helpers-IG6uFb1s.js} +2 -2
  26. package/dist/{column-plan-helpers-D_V4oaZh.js.map → column-plan-helpers-IG6uFb1s.js.map} +1 -1
  27. package/dist/{connection-C938nR3E.js → connection-czvI7TZL.js} +57 -10
  28. package/dist/connection-czvI7TZL.js.map +1 -0
  29. package/dist/{databasePoolManager-Yqdw14wY.js → databasePoolManager-3stMNFL-.js} +4 -6
  30. package/dist/databasePoolManager-3stMNFL-.js.map +1 -0
  31. package/dist/db-command-line.d.ts +14 -0
  32. package/dist/{rls-bootstrap-sql-Bd-hJk08.js → db-subcommands-BPoHCxJR.js} +455 -3
  33. package/dist/db-subcommands-BPoHCxJR.js.map +1 -0
  34. package/dist/db-subcommands.d.ts +11 -0
  35. package/dist/{deferred-index-build-Ca6OqKyR.js → deferred-index-build-BE0I6sYU.js} +8 -8
  36. package/dist/{deferred-index-build-Ca6OqKyR.js.map → deferred-index-build-BE0I6sYU.js.map} +1 -1
  37. package/dist/{doctor-CJyuhV1n.js → doctor-BT--1kq3.js} +107 -11
  38. package/dist/doctor-BT--1kq3.js.map +1 -0
  39. package/dist/{ensure-collection-policies-C1ux3V_z.js → ensure-collection-policies-BnGOURpG.js} +60 -11
  40. package/dist/ensure-collection-policies-BnGOURpG.js.map +1 -0
  41. package/dist/{ensure-collection-tables-Do-Bvb64.js → ensure-collection-tables-Cet4650m.js} +9 -9
  42. package/dist/{ensure-collection-tables-Do-Bvb64.js.map → ensure-collection-tables-Cet4650m.js.map} +1 -1
  43. package/dist/{ensure-tables-Dl_Eh9ow.js → ensure-tables-l_OgFQjN.js} +5 -5
  44. package/dist/{ensure-tables-Dl_Eh9ow.js.map → ensure-tables-l_OgFQjN.js.map} +1 -1
  45. package/dist/{enum-labels-kept-D9eTIWCz.js → enum-labels-kept-nheku1pB.js} +3 -3
  46. package/dist/{enum-labels-kept-D9eTIWCz.js.map → enum-labels-kept-nheku1pB.js.map} +1 -1
  47. package/dist/{generate-drizzle-schema-Bf8canaR.js → generate-drizzle-schema-DC0BOUpn.js} +3 -3
  48. package/dist/{generate-drizzle-schema-Bf8canaR.js.map → generate-drizzle-schema-DC0BOUpn.js.map} +1 -1
  49. package/dist/{generate-drizzle-schema-logic-BaT0H7Gq.js → generate-drizzle-schema-logic-CPzCRD-8.js} +4 -4
  50. package/dist/{generate-drizzle-schema-logic-BaT0H7Gq.js.map → generate-drizzle-schema-logic-CPzCRD-8.js.map} +1 -1
  51. package/dist/{generate-files-D50Pxw1G.js → generate-files-BP-4W_gm.js} +6 -6
  52. package/dist/{generate-files-D50Pxw1G.js.map → generate-files-BP-4W_gm.js.map} +1 -1
  53. package/dist/{generate-next-step-DCd7yiJ2.js → generate-next-step-DgK5BlBn.js} +22 -14
  54. package/dist/{generate-next-step-DCd7yiJ2.js.map → generate-next-step-DgK5BlBn.js.map} +1 -1
  55. package/dist/{generate-postgres-ddl-logic-B4k9djAV.js → generate-postgres-ddl-logic-DPl1oH_z.js} +4 -4
  56. package/dist/{generate-postgres-ddl-logic-B4k9djAV.js.map → generate-postgres-ddl-logic-DPl1oH_z.js.map} +1 -1
  57. package/dist/generated-schema-diff-eZCklRZQ.js +1025 -0
  58. package/dist/generated-schema-diff-eZCklRZQ.js.map +1 -0
  59. package/dist/{generated-schema-staleness-FlxM2i4i.js → generated-schema-staleness-BvNF3i-s.js} +2 -2
  60. package/dist/{generated-schema-staleness-FlxM2i4i.js.map → generated-schema-staleness-BvNF3i-s.js.map} +1 -1
  61. package/dist/index.d.ts +1 -0
  62. package/dist/index.es.js +70 -11
  63. package/dist/index.es.js.map +1 -1
  64. package/dist/{introspect-db-logic-j2vYhmdP.js → introspect-db-logic-DgQVzccW.js} +2 -2
  65. package/dist/{introspect-db-logic-j2vYhmdP.js.map → introspect-db-logic-DgQVzccW.js.map} +1 -1
  66. package/dist/migrate-policy-stamps-3eqfhes6.js +89 -0
  67. package/dist/migrate-policy-stamps-3eqfhes6.js.map +1 -0
  68. package/dist/{open-rebase-D8rytTP0.js → open-rebase-EmqVmS14.js} +78 -1027
  69. package/dist/open-rebase-EmqVmS14.js.map +1 -0
  70. package/dist/{pg-error-utils-CdsGYMTm.js → pg-error-utils-CFEnm2m9.js} +11 -4
  71. package/dist/pg-error-utils-CFEnm2m9.js.map +1 -0
  72. package/dist/{plan-schema-CsNgK0qi.js → plan-schema-Czf3q4-Q.js} +4 -4
  73. package/dist/{plan-schema-CsNgK0qi.js.map → plan-schema-Czf3q4-Q.js.map} +1 -1
  74. package/dist/{policy-drift-CY5P1ZRu.js → policy-drift-X4A-xAzv.js} +3 -3
  75. package/dist/{policy-drift-CY5P1ZRu.js.map → policy-drift-X4A-xAzv.js.map} +1 -1
  76. package/dist/pool-disconnects.d.ts +28 -0
  77. package/dist/{push-index-prebuild-BDFcfRPo.js → push-index-prebuild-COd7i6wm.js} +4 -4
  78. package/dist/{push-index-prebuild-BDFcfRPo.js.map → push-index-prebuild-COd7i6wm.js.map} +1 -1
  79. package/dist/{push-legacy-renames-D4bvMWAb.js → push-legacy-renames-CLgYYwPE.js} +4 -4
  80. package/dist/{push-legacy-renames-D4bvMWAb.js.map → push-legacy-renames-CLgYYwPE.js.map} +1 -1
  81. package/dist/{push-policy-plan-DTXE6aVa.js → push-policy-plan-D2gpQsdv.js} +23 -7
  82. package/dist/push-policy-plan-D2gpQsdv.js.map +1 -0
  83. package/dist/{render-ddl-CrfEe__B.js → render-ddl-4v88y-Gv.js} +4 -4
  84. package/dist/{render-ddl-CrfEe__B.js.map → render-ddl-4v88y-Gv.js.map} +1 -1
  85. package/dist/{rls-enforcement-D7P4-ZYX.js → rls-enforcement-DDyNoOSy.js} +2 -2
  86. package/dist/{rls-enforcement-D7P4-ZYX.js.map → rls-enforcement-DDyNoOSy.js.map} +1 -1
  87. package/dist/schema/atlas-argv.d.ts +3 -1
  88. package/dist/schema/doctor-cli.js +5 -5
  89. package/dist/schema/doctor.d.ts +20 -2
  90. package/dist/schema/ensure-collection-policies.d.ts +28 -1
  91. package/dist/schema/generate-drizzle-schema.js +1 -1
  92. package/dist/schema/generate-next-step.d.ts +20 -8
  93. package/dist/schema/generate-postgres-ddl.js +2 -2
  94. package/dist/schema/generated-schema-diff.d.ts +21 -0
  95. package/dist/schema/introspect-db.js +6 -6
  96. package/dist/schema/introspect-db.js.map +1 -1
  97. package/dist/schema/migrate-policy-stamps.d.ts +23 -0
  98. package/dist/schema/push-policy-plan.d.ts +10 -2
  99. package/dist/services/BranchService.d.ts +85 -0
  100. package/dist/services/pg-notify-listener.d.ts +2 -0
  101. package/dist/{source-DB6xJv3p.js → source-fZb92pN8.js} +46 -3
  102. package/dist/source-fZb92pN8.js.map +1 -0
  103. package/dist/{vector-index-BFhyEaiz.js → vector-index-DsQ3V2d2.js} +2 -2
  104. package/dist/{vector-index-BFhyEaiz.js.map → vector-index-DsQ3V2d2.js.map} +1 -1
  105. package/dist/{websocket-DMeXOoyv.js → websocket-BKZwsjmf.js} +18 -5
  106. package/dist/websocket-BKZwsjmf.js.map +1 -0
  107. package/package.json +7 -7
  108. package/dist/BranchService-DNg4txyf.js.map +0 -1
  109. package/dist/backup-cli-HCEkPcQj.js +0 -556
  110. package/dist/backup-cli-HCEkPcQj.js.map +0 -1
  111. package/dist/backup-service-D-UpT7DH.js +0 -857
  112. package/dist/backup-service-D-UpT7DH.js.map +0 -1
  113. package/dist/cli-console-C_ISGwJo.js.map +0 -1
  114. package/dist/cli-flags-DUozBFyK.js +0 -205
  115. package/dist/cli-flags-DUozBFyK.js.map +0 -1
  116. package/dist/connection-C938nR3E.js.map +0 -1
  117. package/dist/databasePoolManager-Yqdw14wY.js.map +0 -1
  118. package/dist/doctor-CJyuhV1n.js.map +0 -1
  119. package/dist/ensure-collection-policies-C1ux3V_z.js.map +0 -1
  120. package/dist/open-rebase-D8rytTP0.js.map +0 -1
  121. package/dist/pg-error-utils-CdsGYMTm.js.map +0 -1
  122. package/dist/push-policy-plan-DTXE6aVa.js.map +0 -1
  123. package/dist/rls-bootstrap-sql-Bd-hJk08.js.map +0 -1
  124. package/dist/rolldown-runtime-V7rFbMRe.js +0 -39
  125. package/dist/source-DB6xJv3p.js.map +0 -1
  126. package/dist/websocket-DMeXOoyv.js.map +0 -1
package/dist/cli.js CHANGED
@@ -1,12 +1,10 @@
1
1
  import { createRequire as __createRequire } from "module";
2
2
  __createRequire(import.meta.url);
3
- import { i as __toESM } from "./rolldown-runtime-V7rFbMRe.js";
4
- import { $ as redactConnectionPasswords, A as getVectorExcludes, B as workspaceMemberDir, C as dropGeneratedColumns, D as getTableExcludes, E as getSearchExcludes, F as readSearchDdl, G as decidePushSafety, H as GENERATED_SQL_DIR, I as readTriggersDdl, J as extractPlanStatements, K as destructiveOptInFlag, L as readVectorDdl, M as queryColumnTypes, N as queryGeneratedColumnDependencies, O as getTriggerExcludes, P as queryUndeclarableConstraints, R as resolveLocalBin, S as dropDevDatabase, T as getForeignIndexExcludes, U as generatedSqlDir, V as DESIRED_STATE_URL, W as prepareGeneratedSqlDir, X as isSyncedPlan, Y as fromAlterTable, Z as forAtlas, _ as describeBuildScriptRemedy, a as formatForeignGeneratedColumnBanner, b as detectProjectPackageManager, c as isSslNotEnabled, d as ExcludeIntrospectionError, f as applySearchDdl, g as closeAppClients, h as atlasDevDatabaseUrl, i as diagnoseDbError, j as loadCollectionsForCli, k as getUndeclaredConstraintExcludes, m as applyVectorDdl, o as isAuthFailure, p as applyTriggersDdl, q as detectDestructiveStatements, r as diagnoseAtlasFailure, s as isEconnrefused, t as checkDatabaseConnectivity, u as reportCommandFailure, v as describeDevAddCommand, w as ensureDevDatabaseExists, x as diagnoseMissingBin, y as describeReinstallCommand, z as withAppClient } from "./cli-errors-mx4sSjB8.js";
5
- import { a as outWarn, i as outError, o as atlasExcludePattern, r as out, s as excludePatternParts, t as chalk } from "./source-DB6xJv3p.js";
6
- import { t as nextStepAfterDbGenerate } from "./generate-next-step-DCd7yiJ2.js";
7
- import { o as execa, r as dropLegacyAuthSchema, t as RLS_BOOTSTRAP_SQL } from "./rls-bootstrap-sql-Bd-hJk08.js";
8
- import { n as require_arg, t as promptConfirm } from "./cli-prompt-egtNKkZl.js";
9
- import { i as collectionsPathIn, n as assertKnownFlags, o as parseDriverLine, r as closestWord, t as RELAYED_FLAGS } from "./cli-flags-DUozBFyK.js";
3
+ import { n as require_arg, o as __toESM, t as promptConfirm } from "./cli-prompt-DXG0yk-h.js";
4
+ import { A as getUndeclaredConstraintExcludes, B as withAppClient, C as dropDevDatabase, D as getSearchExcludes, E as getForeignIndexExcludes, F as queryUndeclarableConstraints, G as prepareGeneratedSqlDir, H as DESIRED_STATE_URL, I as readSearchDdl, J as detectDestructiveStatements, K as decidePushSafety, L as readTriggersDdl, M as loadCollectionsForCli, N as queryColumnTypes, O as getTableExcludes, P as queryGeneratedColumnDependencies, Q as forAtlas, R as readVectorDdl, S as diagnoseMissingBin, T as ensureDevDatabaseExists, U as GENERATED_SQL_DIR, V as workspaceMemberDir, W as generatedSqlDir, X as fromAlterTable, Y as extractPlanStatements, Z as isSyncedPlan, _ as closeAppClients, a as diagnoseDbError, b as describeReinstallCommand, c as isEconnrefused, d as reportCommandFailure, et as redactConnectionPasswords, f as ExcludeIntrospectionError, g as atlasDevDatabaseUrl, h as applyVectorDdl, i as diagnoseAtlasFailure, j as getVectorExcludes, k as getTriggerExcludes, l as isSslNotEnabled, m as applyTriggersDdl, o as formatForeignGeneratedColumnBanner, p as applySearchDdl, q as destructiveOptInFlag, s as isAuthFailure, t as checkDatabaseConnectivity, v as describeBuildScriptRemedy, w as dropGeneratedColumns, x as detectProjectPackageManager, y as describeDevAddCommand, z as resolveLocalBin } from "./cli-errors-DiA0XFIS.js";
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
+ import { t as nextStepAfterDbGenerate } from "./generate-next-step-DgK5BlBn.js";
7
+ import { a as resolveBranchSwitches, c as assertKnownFlags, f as parseDriverLine, g as dropLegacyAuthSchema, m as RLS_BOOTSTRAP_SQL, n as isDriverDbSubcommand, o as unexpectedBranchArgs, p as resolveDriverSwitches, r as backupActionOf, t as DRIVER_DB_SUBCOMMANDS, u as collectionsPathIn, y as execa } from "./db-subcommands-BPoHCxJR.js";
10
8
  import { formatRelativeTime } from "@rebasepro/utils";
11
9
  import path from "path";
12
10
  import fs from "fs";
@@ -656,7 +654,9 @@ function readsRevisions(domain, args) {
656
654
  * all of them, so it excludes no one; what it does cost there is a connection.
657
655
  * The managed database accepts four and a running `rebase dev` holds two, so
658
656
  * `migrate apply`'s third — its own, the lock's, the revisions table's — was
659
- * closed unanswered and Atlas said only `Error: EOF`.
657
+ * closed unanswered and Atlas said only `Error: EOF`. `migrate set`, which has
658
+ * no `--skip-lock`, is bound to the revisions schema instead, which spares it
659
+ * the revisions table's connection.
660
660
  */
661
661
  function buildAtlasArgs(invocation) {
662
662
  const { domain, args, url, devUrl, excludes = [], singleSession = false } = invocation;
@@ -666,6 +666,7 @@ function buildAtlasArgs(invocation) {
666
666
  else if (args.includes("clean") || args.includes("inspect")) argv.push("--url", url);
667
667
  } else if (domain === "migrate") {
668
668
  if (args.includes("diff")) argv.push("--dev-url", devUrl);
669
+ else if (args.includes("set") && singleSession) argv.push("--url", withSearchPath(url, "rebase"));
669
670
  else if (readsRevisions(domain, args)) {
670
671
  argv.push("--url", url, "--revisions-schema", "rebase");
671
672
  if (args.includes("apply") && !args.includes("--baseline")) argv.push("--allow-dirty");
@@ -676,6 +677,23 @@ function buildAtlasArgs(invocation) {
676
677
  return argv;
677
678
  }
678
679
  /**
680
+ * The URL with its `search_path` set to `schema`: an Atlas URL bound to that
681
+ * schema. Every other parameter is kept as written. A URL that does not
682
+ * parse is returned unchanged.
683
+ */
684
+ function withSearchPath(url, schema) {
685
+ let parsed;
686
+ try {
687
+ parsed = new URL(url);
688
+ } catch {
689
+ return url;
690
+ }
691
+ const params = Array.from(parsed.searchParams.entries()).filter(([key]) => key !== "search_path");
692
+ params.push(["search_path", schema]);
693
+ parsed.search = params.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&");
694
+ return parsed.toString();
695
+ }
696
+ /**
679
697
  * `atlas migrate apply`'s own arguments for `rebase db migrate`.
680
698
  *
681
699
  * `positionals` are what is left of the user's line once every flag the
@@ -1052,121 +1070,6 @@ async function applyPoliciesFile(client, policiesSql, stamping) {
1052
1070
  };
1053
1071
  }
1054
1072
  //#endregion
1055
- //#region src/branch-argv.ts
1056
- /**
1057
- * Argument shapes for `rebase db branch`, with no runtime dependencies.
1058
- *
1059
- * Its own module for the same reason `schema/atlas-argv.ts` is: `cli.ts` pulls
1060
- * in chalk, execa and the driver runtime, so a unit test that imports it cannot
1061
- * run. Argv parsing is the part most worth testing and the part least in need
1062
- * of any of that.
1063
- */
1064
- /**
1065
- * The flags each driver-side `db branch` action takes, besides the ones the CLI
1066
- * relays on every line (`--database-url`, `--docker`, `--debug`).
1067
- *
1068
- * `switch` is absent: the CLI answers it before the driver is ever spawned.
1069
- * An action not listed here is not checked, so the dispatch can say it does
1070
- * not exist in its own words.
1071
- */
1072
- var BRANCH_ACTION_FLAGS = {
1073
- create: {
1074
- "--from": String,
1075
- "--force": Boolean
1076
- },
1077
- list: {},
1078
- info: {},
1079
- delete: {
1080
- "--force": Boolean,
1081
- "--yes": Boolean,
1082
- "-y": "--yes"
1083
- },
1084
- prune: {
1085
- "--older-than": String,
1086
- "--include-dev-diff": Boolean,
1087
- "--yes": Boolean,
1088
- "-y": "--yes"
1089
- }
1090
- };
1091
- /**
1092
- * Refuse a flag `action` does not take, naming the one it was probably meant
1093
- * to be — the same sentence `db backup` and `db restore` say.
1094
- *
1095
- * Throws: the driver's entry turns a thrown error into one red line and exit 1,
1096
- * and this runs before anything connects.
1097
- */
1098
- function assertKnownBranchFlags(action, rest) {
1099
- const spec = BRANCH_ACTION_FLAGS[action];
1100
- if (!spec) return;
1101
- const full = {
1102
- ...RELAYED_FLAGS,
1103
- ...spec
1104
- };
1105
- try {
1106
- (0, import_arg.default)(full, { argv: [...rest] });
1107
- } catch (error) {
1108
- if (!(error instanceof Error) || !("code" in error) || error.code !== "ARG_UNKNOWN_OPTION") throw error;
1109
- const typed = (/option: (\S+)$/.exec(error.message)?.[1] ?? error.message).split("=")[0];
1110
- const suggestion = closestWord(typed, Object.keys(full).filter((flag) => flag.startsWith("--")));
1111
- const own = Object.keys(spec).filter((flag) => flag.startsWith("--"));
1112
- const takes = own.length > 0 ? `it takes ${own.join(", ")}` : "it takes no options of its own";
1113
- throw new Error(`\`rebase db branch ${action}\` has no option ${typed}` + (suggestion ? ` — did you mean ${suggestion}?` : ` — ${takes}.`) + " Nothing was run. See `rebase db branch --help`.");
1114
- }
1115
- }
1116
- /**
1117
- * Words on a `db branch` command line that no argument accounts for.
1118
- *
1119
- * `rebase db branch create alpha beta` created a branch called `alpha` and
1120
- * threw `beta` away without a word. The shapes that produces are all quiet and
1121
- * all wrong: an unquoted name (`create my feature` → `my`), a flag written
1122
- * without its dashes (`create feat from main` → `feat`), a shell that split
1123
- * something you thought was one token. In each case the command succeeds and
1124
- * the branch is not the one asked for — and branch names are the thing you
1125
- * later type to switch, delete, or point a deploy at.
1126
- *
1127
- * A flag the action does not take is refused outright, by throwing — see
1128
- * {@link BRANCH_ACTION_FLAGS}. It was let through on the reasoning that a
1129
- * subcommand added later might take flags this file had never heard of; what
1130
- * that bought was every typo running without the flag it meant:
1131
- * `prune --older-then 1d --yes` pruned by no age, `create x --froce` ran
1132
- * without --force. A new action gets its line in the table. The value after a
1133
- * flag that takes one is skipped: it is that flag's argument, not a stray word.
1134
- *
1135
- * @param words The command's own arguments: action, name, then the rest.
1136
- */
1137
- function unexpectedBranchArgs(words) {
1138
- if (words[0]) assertKnownBranchFlags(words[0], words.slice(1));
1139
- const extras = [];
1140
- let seenName = false;
1141
- for (let index = 1; index < words.length; index += 1) {
1142
- const word = words[index];
1143
- if (word.startsWith("-")) {
1144
- if (TAKES_A_VALUE.has(word.split("=")[0])) index += 1;
1145
- continue;
1146
- }
1147
- if (!seenName) {
1148
- seenName = true;
1149
- continue;
1150
- }
1151
- extras.push(word);
1152
- }
1153
- return extras;
1154
- }
1155
- /**
1156
- * Branch-line flags whose next word belongs to them.
1157
- *
1158
- * `--from` was the only one listed, and `--database-url` is the one that bit:
1159
- * `rebase db branch list --database-url postgres://…` — which the CLI itself
1160
- * appends when the checkout is on a branch, so `rebase.branches` is read in the
1161
- * parent where it lives — answered `✗ Unexpected argument: postgres://…`. The
1162
- * `=` form carries its value in the same word and needs no skip.
1163
- */
1164
- var TAKES_A_VALUE = /* @__PURE__ */ new Set([
1165
- "--from",
1166
- "--older-than",
1167
- "--database-url"
1168
- ]);
1169
- //#endregion
1170
1073
  //#region src/cli-collections-path.ts
1171
1074
  /**
1172
1075
  * `--collections <dir>`, checked once, before anything is written.
@@ -1243,15 +1146,14 @@ function assertCollectionsPathExists(typed) {
1243
1146
  throw new CollectionsPathMissing(typed, resolved);
1244
1147
  }
1245
1148
  //#endregion
1246
- //#region src/backup-argv.ts
1149
+ //#region src/branch-prune.ts
1247
1150
  /**
1248
- * @param rawArgs the driver's whole line, `["db", "backup", …]`.
1151
+ * The variable the CLI hands the driver the database its checkout is switched
1152
+ * to in. The pointer is the CLI's (`dev-db/branch-pointer.ts`); the driver is
1153
+ * a child process that cannot read it. Spelled the same in
1154
+ * `packages/cli/src/commands/db.ts`.
1249
1155
  */
1250
- function backupActionOf(rawArgs) {
1251
- return rawArgs[2] === "list" ? "list" : "create";
1252
- }
1253
- //#endregion
1254
- //#region src/branch-prune.ts
1156
+ var ACTIVE_BRANCH_DATABASE_ENV = "REBASE_ACTIVE_BRANCH_DATABASE";
1255
1157
  /** True when nothing at all needs doing. */
1256
1158
  function planIsEmpty(plan, includeDevDiff) {
1257
1159
  return plan.staleRows.length === 0 && plan.orphanDatabases.length === 0 && plan.expired.length === 0 && (!includeDevDiff || plan.devDiff.length === 0);
@@ -1284,14 +1186,31 @@ function planPrune(input, options = {}) {
1284
1186
  const now = options.now ?? /* @__PURE__ */ new Date();
1285
1187
  const present = new Set(input.databases);
1286
1188
  const registered = new Set(input.rows.map((row) => row.dbName));
1189
+ const isActive = (database) => options.activeDatabase != null && database === options.activeDatabase;
1190
+ let active = null;
1287
1191
  return {
1288
1192
  staleRows: input.rows.filter((row) => !present.has(row.dbName)),
1289
- orphanDatabases: input.databases.filter((name) => name.startsWith(input.branchPrefix) && !registered.has(name)).sort(),
1193
+ orphanDatabases: input.databases.filter((name) => name.startsWith(input.branchPrefix) && !registered.has(name)).filter((name) => {
1194
+ if (!isActive(name)) return true;
1195
+ active = {
1196
+ name,
1197
+ database: name
1198
+ };
1199
+ return false;
1200
+ }).sort(),
1290
1201
  expired: options.olderThanDays == null ? [] : input.rows.filter((row) => present.has(row.dbName)).map((branch) => ({
1291
1202
  branch,
1292
1203
  ageDays: ageInDays(branch.createdAt, now)
1293
- })).filter((entry) => entry.ageDays >= options.olderThanDays).sort((a, b) => b.ageDays - a.ageDays),
1294
- devDiff: input.databases.filter((name) => name.endsWith("_dev_diff")).sort()
1204
+ })).filter((entry) => entry.ageDays >= options.olderThanDays).filter((entry) => {
1205
+ if (!isActive(entry.branch.dbName)) return true;
1206
+ active = {
1207
+ name: entry.branch.name,
1208
+ database: entry.branch.dbName
1209
+ };
1210
+ return false;
1211
+ }).sort((a, b) => b.ageDays - a.ageDays),
1212
+ devDiff: input.databases.filter((name) => name.endsWith("_dev_diff")).sort(),
1213
+ active
1295
1214
  };
1296
1215
  }
1297
1216
  //#endregion
@@ -1382,7 +1301,7 @@ function generatesInProcess() {
1382
1301
  async function generateInProcess(what, label, run) {
1383
1302
  let generators;
1384
1303
  try {
1385
- generators = await import("./generate-files-D50Pxw1G.js").then((n) => n.t);
1304
+ generators = await import("./generate-files-BP-4W_gm.js").then((n) => n.t);
1386
1305
  } catch (err) {
1387
1306
  outError(chalk.red(`✗ Failed to run ${what}: ${err instanceof Error ? err.message : String(err)}`));
1388
1307
  process.exit(1);
@@ -1422,13 +1341,14 @@ async function runPluginCommand(args) {
1422
1341
  const domain = args[0];
1423
1342
  const subcommand = args[1];
1424
1343
  assertKnownFlags(domain, subcommand, args);
1344
+ args = resolveDriverSwitches(domain, subcommand, args);
1425
1345
  assertCollectionsPathExists(collectionsPathIn(args));
1426
1346
  try {
1427
1347
  if (domain === "db") await scratchDatabase.around(() => dbCommand(subcommand, args));
1428
1348
  else if (domain === "schema") await schemaCommand(subcommand, args);
1429
1349
  else if (domain === "doctor") await doctorPluginCommand(args);
1430
1350
  else if (domain === "console") {
1431
- const { consoleCommand } = await import("./cli-console-C_ISGwJo.js");
1351
+ const { consoleCommand } = await import("./cli-console-CQrQ0lAY.js");
1432
1352
  process.exitCode = await consoleCommand(args);
1433
1353
  } else {
1434
1354
  outError(chalk.red(`Unknown domain command: ${domain}`));
@@ -1579,17 +1499,8 @@ var DB_FLAGS = {
1579
1499
  "-y": "--yes"
1580
1500
  };
1581
1501
  async function dbCommand(subcommand, rawArgs) {
1582
- const VALID_ACTIONS = [
1583
- "push",
1584
- "generate",
1585
- "migrate",
1586
- "branch",
1587
- "backup",
1588
- "restore",
1589
- "backups"
1590
- ];
1591
- if (!subcommand || !VALID_ACTIONS.includes(subcommand)) {
1592
- outError(chalk.red(`Unknown db command. Valid: ${VALID_ACTIONS.join(", ")}`));
1502
+ if (!isDriverDbSubcommand(subcommand)) {
1503
+ outError(chalk.red(`Unknown db command. Valid: ${DRIVER_DB_SUBCOMMANDS.join(", ")}`));
1593
1504
  process.exit(1);
1594
1505
  }
1595
1506
  if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
@@ -1604,7 +1515,7 @@ async function dbCommand(subcommand, rawArgs) {
1604
1515
  return;
1605
1516
  }
1606
1517
  if (subcommand === "backup" || subcommand === "restore" || subcommand === "backups") {
1607
- const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-HCEkPcQj.js");
1518
+ const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-gijeXe0u.js").then((n) => n.t);
1608
1519
  if (subcommand === "backup" && backupActionOf(rawArgs) === "list") await backupsCommand(rawArgs);
1609
1520
  else if (subcommand === "backup") await backupCommand(rawArgs);
1610
1521
  else if (subcommand === "restore") await restoreCommand(rawArgs);
@@ -1651,7 +1562,7 @@ async function dbCommand(subcommand, rawArgs) {
1651
1562
  }
1652
1563
  const searchContent = readSearchDdl();
1653
1564
  if (searchContent) {
1654
- const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-B4k9djAV.js").then((n) => n.o);
1565
+ const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-DPl1oH_z.js").then((n) => n.o);
1655
1566
  const migrationConflicts = findGeneratedColumnConflicts(parseColumnMutations(migrationContent), searchColumnDependencies(await loadCollectionsForCli(collectionsPath)));
1656
1567
  const preamble = migrationDropPreamble(migrationConflicts);
1657
1568
  if (preamble) {
@@ -1699,9 +1610,14 @@ async function dbCommand(subcommand, rawArgs) {
1699
1610
  Search, vector, trigger and RLS DDL are applied by \`rebase db push\`, and at
1700
1611
  boot by the schema ensure. For a migration-only deployment, add
1701
1612
  ${GENERATED_SQL_DIR}/search.sql, vector.sql, triggers.sql and\n policies.sql to a migration by hand.`));
1613
+ const nextStep = nextStepAfterDbGenerate({
1614
+ newestVersion: latestMigrationVersion(),
1615
+ wrote: wroteNewMigration,
1616
+ first: migrationsBefore.length === 0
1617
+ });
1702
1618
  out("");
1703
- for (const line of nextStepAfterDbGenerate(latestMigrationVersion())) out(line);
1704
- out("");
1619
+ for (const line of nextStep) out(line);
1620
+ if (nextStep.length > 0) out("");
1705
1621
  } else {
1706
1622
  out("");
1707
1623
  out(chalk.bold(` 🗄️ Rebase DB ${subcommand.charAt(0).toUpperCase() + subcommand.slice(1)}`));
@@ -1909,6 +1825,8 @@ async function dbCommand(subcommand, rawArgs) {
1909
1825
  if (databaseUrl) {
1910
1826
  await ensureRlsUserRole(databaseUrl);
1911
1827
  await retireLegacyAuthSchema(databaseUrl);
1828
+ const { stampMigratedPolicies } = await import("./migrate-policy-stamps-3eqfhes6.js");
1829
+ await stampMigratedPolicies(databaseUrl, collectionsPath);
1912
1830
  }
1913
1831
  }
1914
1832
  out("");
@@ -1930,8 +1848,8 @@ async function dbCommand(subcommand, rawArgs) {
1930
1848
  async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
1931
1849
  let renames;
1932
1850
  try {
1933
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
1934
- const { legacyForeignKeyRenames } = await import("./push-legacy-renames-D4bvMWAb.js");
1851
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
1852
+ const { legacyForeignKeyRenames } = await import("./push-legacy-renames-CLgYYwPE.js");
1935
1853
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1936
1854
  renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1937
1855
  } catch {
@@ -1950,8 +1868,8 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
1950
1868
  /** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
1951
1869
  async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
1952
1870
  try {
1953
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
1954
- const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-D9eTIWCz.js");
1871
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
1872
+ const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-nheku1pB.js");
1955
1873
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1956
1874
  const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1957
1875
  if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
@@ -1960,8 +1878,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
1960
1878
  async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
1961
1879
  let missing;
1962
1880
  try {
1963
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
1964
- const { missingForeignKeyIndexes } = await import("./push-index-prebuild-BDFcfRPo.js");
1881
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
1882
+ const { missingForeignKeyIndexes } = await import("./push-index-prebuild-COd7i6wm.js");
1965
1883
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1966
1884
  missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1967
1885
  } catch {
@@ -1971,7 +1889,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
1971
1889
  if (missing.length === 0 || dryRun) return names;
1972
1890
  out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
1973
1891
  try {
1974
- const { buildDeferredIndexes } = await import("./deferred-index-build-Ca6OqKyR.js").then((n) => n.r);
1892
+ const { buildDeferredIndexes } = await import("./deferred-index-build-BE0I6sYU.js").then((n) => n.r);
1975
1893
  const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
1976
1894
  dedicated: true,
1977
1895
  query: async (text) => ({ rows: (await client.query(text)).rows }),
@@ -2019,9 +1937,9 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
2019
1937
  let unsecured;
2020
1938
  let userRole;
2021
1939
  try {
2022
- const { lockCollectionTables } = await import("./ensure-collection-policies-C1ux3V_z.js");
2023
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
2024
- userRole = (await import("./rls-enforcement-D7P4-ZYX.js").then((n) => n.c)).REBASE_USER_ROLE;
1940
+ const { lockCollectionTables } = await import("./ensure-collection-policies-BnGOURpG.js");
1941
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
1942
+ userRole = (await import("./rls-enforcement-DDyNoOSy.js").then((n) => n.c)).REBASE_USER_ROLE;
2025
1943
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2026
1944
  ({unsecured} = await withAppClient(databaseUrl, (client) => lockCollectionTables({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections)));
2027
1945
  } catch (err) {
@@ -2056,8 +1974,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
2056
1974
  async function ensureAuthTables(databaseUrl, collectionsPath) {
2057
1975
  try {
2058
1976
  const { drizzle } = await import("drizzle-orm/node-postgres");
2059
- const { ensureAuthTablesExist } = await import("./ensure-tables-Dl_Eh9ow.js").then((n) => n.n);
2060
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
1977
+ const { ensureAuthTablesExist } = await import("./ensure-tables-l_OgFQjN.js").then((n) => n.n);
1978
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
2061
1979
  const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
2062
1980
  const a = c.auth;
2063
1981
  return a === true || typeof a === "object" && a !== null && a.enabled === true;
@@ -2077,7 +1995,7 @@ async function ensureRlsUserRole(databaseUrl) {
2077
1995
  const schemas = ["public", "rebase"];
2078
1996
  let rls;
2079
1997
  try {
2080
- rls = await import("./rls-enforcement-D7P4-ZYX.js").then((n) => n.c);
1998
+ rls = await import("./rls-enforcement-DDyNoOSy.js").then((n) => n.c);
2081
1999
  } catch (err) {
2082
2000
  outError(chalk.red(`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`));
2083
2001
  return;
@@ -2137,10 +2055,10 @@ async function applyPolicies(databaseUrl, collectionsPath) {
2137
2055
  */
2138
2056
  async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
2139
2057
  try {
2140
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
2141
- const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-B4k9djAV.js").then((n) => n.o);
2142
- const { policyStampSql } = await import("./ensure-collection-policies-C1ux3V_z.js");
2143
- const { pinSearchPath } = await import("./connection-C938nR3E.js").then((n) => n.n);
2058
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
2059
+ const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-DPl1oH_z.js").then((n) => n.o);
2060
+ const { policyStampSql } = await import("./ensure-collection-policies-BnGOURpG.js");
2061
+ const { pinSearchPath } = await import("./connection-czvI7TZL.js").then((n) => n.n);
2144
2062
  return {
2145
2063
  statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
2146
2064
  searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public"
@@ -2157,9 +2075,9 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
2157
2075
  */
2158
2076
  async function readPolicyPushPlan(databaseUrl, collectionsPath) {
2159
2077
  try {
2160
- const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-DTXE6aVa.js");
2161
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
2162
- const { pinSearchPath } = await import("./connection-C938nR3E.js").then((n) => n.n);
2078
+ const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-D2gpQsdv.js");
2079
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
2080
+ const { pinSearchPath } = await import("./connection-czvI7TZL.js").then((n) => n.n);
2163
2081
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2164
2082
  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" }));
2165
2083
  return {
@@ -2186,8 +2104,8 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
2186
2104
  */
2187
2105
  async function reconcilePolicies(databaseUrl, collectionsPath) {
2188
2106
  try {
2189
- const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-CY5P1ZRu.js").then((n) => n.s);
2190
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
2107
+ const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-X4A-xAzv.js").then((n) => n.s);
2108
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
2191
2109
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2192
2110
  await withAppClient(databaseUrl, async (client) => {
2193
2111
  const drift = await checkPolicyDrift(client, collections);
@@ -2233,6 +2151,11 @@ var BRANCH_FLAGS = {
2233
2151
  "--yes": Boolean,
2234
2152
  "-y": "--yes"
2235
2153
  };
2154
+ /** The source `branch create --from <source>` names, if it names one. */
2155
+ function createSource(rawArgs) {
2156
+ const at = rawArgs.indexOf("--from");
2157
+ return at !== -1 && rawArgs[at + 1] ? rawArgs[at + 1] : void 0;
2158
+ }
2236
2159
  async function branchCommand(rawArgs) {
2237
2160
  const branchAction = rawArgs[2];
2238
2161
  if (!branchAction || branchAction === "--help") {
@@ -2240,13 +2163,14 @@ async function branchCommand(rawArgs) {
2240
2163
  return;
2241
2164
  }
2242
2165
  const extras = unexpectedBranchArgs(rawArgs.slice(2));
2166
+ rawArgs = resolveBranchSwitches(rawArgs);
2243
2167
  if (extras.length > 0) {
2244
2168
  outError("");
2245
- outError(chalk.red(` ✗ Unexpected argument${extras.length > 1 ? "s" : ""}: ${extras.join(" ")}`));
2169
+ outError(chalk.red(` ✗ Unexpected argument${extras.length > 1 ? "s" : ""}: ${redactConnectionPasswords(extras.join(" "))}`));
2246
2170
  outError("");
2247
2171
  outError(chalk.gray(` ${chalk.bold("rebase db branch")} takes one name. A branch name may contain letters,`));
2248
2172
  outError(chalk.gray(" digits, underscores and hyphens — no spaces."));
2249
- if (rawArgs[3]) outError(chalk.gray(` Did you mean: ${chalk.cyan(`rebase db branch ${branchAction} ${[rawArgs[3], ...extras].join("-")}`)}`));
2173
+ if (rawArgs[3]) outError(chalk.gray(` Did you mean: ${chalk.cyan(redactConnectionPasswords(`rebase db branch ${branchAction} ${[rawArgs[3], ...extras].join("-")}`))}`));
2250
2174
  outError("");
2251
2175
  process.exit(1);
2252
2176
  }
@@ -2264,10 +2188,12 @@ async function branchCommand(rawArgs) {
2264
2188
  outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
2265
2189
  process.exit(1);
2266
2190
  }
2267
- const { DatabasePoolManager } = await import("./databasePoolManager-Yqdw14wY.js").then((n) => n.n);
2268
- const { BranchService } = await import("./BranchService-DNg4txyf.js").then((n) => n.n);
2191
+ const { DatabasePoolManager } = await import("./databasePoolManager-3stMNFL-.js").then((n) => n.n);
2192
+ const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-ClklxyAQ.js").then((n) => n.n);
2269
2193
  const { drizzle } = await import("drizzle-orm/node-postgres");
2270
2194
  const { Pool } = await import("pg");
2195
+ const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
2196
+ for (const line of reopenedDatabasesNotice(healed)) outWarn(chalk.yellow(` ${line}`));
2271
2197
  await checkDatabaseConnectivity(databaseUrl);
2272
2198
  await closeAppClients();
2273
2199
  const pool = new Pool({
@@ -2287,9 +2213,7 @@ async function branchCommand(rawArgs) {
2287
2213
  out(chalk.gray(" Usage: rebase db branch create <name> [--from <source>]"));
2288
2214
  process.exit(1);
2289
2215
  }
2290
- let source;
2291
- const fromIdx = rawArgs.indexOf("--from");
2292
- if (fromIdx !== -1 && rawArgs[fromIdx + 1]) source = rawArgs[fromIdx + 1];
2216
+ const source = createSource(rawArgs);
2293
2217
  const force = rawArgs.includes("--force");
2294
2218
  out("");
2295
2219
  out(chalk.bold(" 🌿 Creating database branch..."));
@@ -2314,10 +2238,12 @@ async function branchCommand(rawArgs) {
2314
2238
  else {
2315
2239
  out(chalk.bold(` 🌿 ${branches.length} branch(es):`));
2316
2240
  out("");
2241
+ const current = process.env[ACTIVE_BRANCH_DATABASE_ENV]?.trim();
2317
2242
  for (const b of branches) {
2318
2243
  const size = b.sizeBytes != null ? chalk.gray(` (${formatBytes(b.sizeBytes)})`) : "";
2319
2244
  const age = chalk.gray(` — created ${timeAgo(b.createdAt)}`);
2320
- out(` ${chalk.green("●")} ${chalk.bold(b.name)}${size}${age}`);
2245
+ const here = current && b.database === current ? chalk.cyan(" (current — this checkout is on it)") : "";
2246
+ out(` ${chalk.green("●")} ${chalk.bold(b.name)}${here}${size}${age}`);
2321
2247
  out(chalk.gray(` from ${b.parentDatabase}`));
2322
2248
  }
2323
2249
  }
@@ -2379,9 +2305,18 @@ async function branchCommand(rawArgs) {
2379
2305
  rows,
2380
2306
  databases,
2381
2307
  branchPrefix: "rb_"
2382
- }, { olderThanDays });
2308
+ }, {
2309
+ olderThanDays,
2310
+ activeDatabase: process.env["REBASE_ACTIVE_BRANCH_DATABASE"]?.trim() || null
2311
+ });
2312
+ const keptActive = () => {
2313
+ if (!plan.active) return;
2314
+ out(` ${chalk.gray("○")} ${chalk.bold(plan.active.name)} ${chalk.gray("— this checkout is switched to it, so it is kept")}`);
2315
+ out(chalk.gray(` To prune it, leave it first: ${chalk.cyan("rebase db branch switch --off")}`));
2316
+ };
2383
2317
  out("");
2384
2318
  if (planIsEmpty(plan, includeDevDiff)) {
2319
+ keptActive();
2385
2320
  out(chalk.gray(" Nothing to prune."));
2386
2321
  if (!olderThanDays && rows.length > 0) out(chalk.gray(` ${rows.length} branch(es) are healthy — --older-than 14 also removes old ones.`));
2387
2322
  if (!includeDevDiff && plan.devDiff.length > 0) {
@@ -2396,6 +2331,7 @@ async function branchCommand(rawArgs) {
2396
2331
  for (const row of plan.staleRows) out(` ${chalk.yellow("○")} ${chalk.bold(row.name)} ${chalk.gray("— registered, but its database is gone; the entry will be removed")}`);
2397
2332
  for (const dbName of plan.orphanDatabases) out(` ${chalk.yellow("○")} ${chalk.bold(dbName)} ${chalk.gray("— a branch database with no entry; the database will be dropped")}`);
2398
2333
  for (const { branch, ageDays } of plan.expired) out(` ${chalk.red("●")} ${chalk.bold(branch.name)} ${chalk.gray(`— ${ageDays} days old; branch and database will be dropped`)}`);
2334
+ keptActive();
2399
2335
  if (includeDevDiff) for (const dbName of plan.devDiff) out(` ${chalk.red("●")} ${chalk.bold(dbName)} ${chalk.gray("— Atlas scratch database; will be dropped")}`);
2400
2336
  else if (plan.devDiff.length > 0) out(chalk.gray(` (${plan.devDiff.length} Atlas scratch database(s) not listed — --include-dev-diff)`));
2401
2337
  out("");
@@ -2762,9 +2698,9 @@ async function schemaStaleCommand(rawArgs) {
2762
2698
  const schemaFile = path.resolve(process.cwd(), outputPath);
2763
2699
  const fix = Boolean(argsList["--fix"]);
2764
2700
  const generatedExists = fs.existsSync(schemaFile);
2765
- const { loadCollections } = await import("./doctor-CJyuhV1n.js").then((n) => n.t);
2766
- const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-FlxM2i4i.js").then((n) => n.r);
2767
- const { generateSchema } = await import("./generate-drizzle-schema-logic-BaT0H7Gq.js").then((n) => n.n);
2701
+ const { loadCollections } = await import("./doctor-BT--1kq3.js").then((n) => n.t);
2702
+ const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-BvNF3i-s.js").then((n) => n.r);
2703
+ const { generateSchema } = await import("./generate-drizzle-schema-logic-CPzCRD-8.js").then((n) => n.n);
2768
2704
  const { relationalCollections } = await import("@rebasepro/common");
2769
2705
  let stale = [];
2770
2706
  let differences = [];