@rebasepro/cli 0.25.0-canary.ge06257e → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/bin/rebase.js +9 -5
  2. package/dist/{agent-setup-C83DXnlx.js → agent-setup-B5AKHOgt.js} +2 -2
  3. package/dist/{agent-setup-C83DXnlx.js.map → agent-setup-B5AKHOgt.js.map} +1 -1
  4. package/dist/{api-keys-Bc4FJKYp.js → api-keys-Tm7zvAPe.js} +27 -20
  5. package/dist/api-keys-Tm7zvAPe.js.map +1 -0
  6. package/dist/{apps-wG-ZTryA.js → apps-BsU_ILbP.js} +4 -4
  7. package/dist/{apps-wG-ZTryA.js.map → apps-BsU_ILbP.js.map} +1 -1
  8. package/dist/{args-CcBphFdj.js → args-BX0YD14a.js} +45 -16
  9. package/dist/args-BX0YD14a.js.map +1 -0
  10. package/dist/{atlas-dev-database-DeK3Sa4h.js → atlas-dev-database-OWtqnG7W.js} +2 -2
  11. package/dist/{atlas-dev-database-DeK3Sa4h.js.map → atlas-dev-database-OWtqnG7W.js.map} +1 -1
  12. package/dist/{auth-BL7bNQVu.js → auth-Vl2hFKXP.js} +77 -10
  13. package/dist/auth-Vl2hFKXP.js.map +1 -0
  14. package/dist/{branch-pointer-DTQNLFtb.js → branch-pointer-9DnwkFJJ.js} +1 -1
  15. package/dist/{build-h_7Re-67.js → build-BBgT8EJZ.js} +5 -5
  16. package/dist/{build-h_7Re-67.js.map → build-BBgT8EJZ.js.map} +1 -1
  17. package/dist/{bundle-CqURVN-K.js → bundle-DtCCCr4w.js} +4 -19
  18. package/dist/bundle-DtCCCr4w.js.map +1 -0
  19. package/dist/{cloud-DVV_5GPG.js → cloud-BpH0_bmV.js} +7 -7
  20. package/dist/{cloud-DVV_5GPG.js.map → cloud-BpH0_bmV.js.map} +1 -1
  21. package/dist/commands/api-keys.d.ts +4 -1
  22. package/dist/commands/auth.d.ts +3 -2
  23. package/dist/connection-banner-DbLJzWf4.js +128 -0
  24. package/dist/connection-banner-DbLJzWf4.js.map +1 -0
  25. package/dist/{console-Dw3HLdUs.js → console-CEGm0XNc.js} +4 -4
  26. package/dist/{console-Dw3HLdUs.js.map → console-CEGm0XNc.js.map} +1 -1
  27. package/dist/{context-BM-oOMNX.js → context-CyflUrKg.js} +2 -2
  28. package/dist/{context-BM-oOMNX.js.map → context-CyflUrKg.js.map} +1 -1
  29. package/dist/{daemon-entry-C6pxdily.js → daemon-entry-CbLRrgzy.js} +199 -3
  30. package/dist/daemon-entry-CbLRrgzy.js.map +1 -0
  31. package/dist/{db-Dkn9XhT-.js → db-CRNpA5mH.js} +171 -60
  32. package/dist/db-CRNpA5mH.js.map +1 -0
  33. package/dist/{derive-Dl0z2OWi.js → derive-CsoFGAnK.js} +28 -13
  34. package/dist/{derive-Dl0z2OWi.js.map → derive-CsoFGAnK.js.map} +1 -1
  35. package/dist/{dev-DAcZR4Pp.js → dev-C0pbMmhS.js} +6 -6
  36. package/dist/{dev-DAcZR4Pp.js.map → dev-C0pbMmhS.js.map} +1 -1
  37. package/dist/dev-db/connection-banner.d.ts +47 -0
  38. package/dist/dev-db/notification-proxy.d.ts +82 -1
  39. package/dist/{dev-preflight-CorMg7Ub.js → dev-preflight-unHpiYO1.js} +26 -3
  40. package/dist/dev-preflight-unHpiYO1.js.map +1 -0
  41. package/dist/{doctor-Ds_lzc9p.js → doctor-CATRdWm6.js} +4 -4
  42. package/dist/{doctor-Ds_lzc9p.js.map → doctor-CATRdWm6.js.map} +1 -1
  43. package/dist/{eject-CJHkfnat.js → eject-DuasTr-F.js} +2 -2
  44. package/dist/{eject-CJHkfnat.js.map → eject-DuasTr-F.js.map} +1 -1
  45. package/dist/{fold-static-BC9CYicw.js → fold-static-hDHtDfTq.js} +2 -2
  46. package/dist/{fold-static-BC9CYicw.js.map → fold-static-hDHtDfTq.js.map} +1 -1
  47. package/dist/{generate_sdk-kfkZmG-d.js → generate_sdk-Cvg5jjJF.js} +3 -3
  48. package/dist/{generate_sdk-kfkZmG-d.js.map → generate_sdk-Cvg5jjJF.js.map} +1 -1
  49. package/dist/index.es.js +34 -34
  50. package/dist/{init-CjoJoThg.js → init-BWAwHPtz.js} +8 -7
  51. package/dist/init-BWAwHPtz.js.map +1 -0
  52. package/dist/last-dev-database-c_dKz1S3.js +2 -0
  53. package/dist/{normalize-imports-BHxL2d05.js → normalize-imports-BoBVh5tU.js} +3 -3
  54. package/dist/{normalize-imports-BHxL2d05.js.map → normalize-imports-BoBVh5tU.js.map} +1 -1
  55. package/dist/precompress.d.ts +0 -7
  56. package/dist/{prepare-C1iaiTC4.js → prepare-DdnU70z8.js} +4 -4
  57. package/dist/prepare-DdnU70z8.js.map +1 -0
  58. package/dist/{pull-COpNJFzY.js → pull-C3PXduzl.js} +13 -40
  59. package/dist/pull-C3PXduzl.js.map +1 -0
  60. package/dist/resolve-CNQjsatH.js +2 -0
  61. package/dist/resources/derive.d.ts +9 -0
  62. package/dist/{resources-CLm6g0br.js → resources-BdNRDEAy.js} +3 -3
  63. package/dist/{resources-CLm6g0br.js.map → resources-BdNRDEAy.js.map} +1 -1
  64. package/dist/{schema-BKdh6UoE.js → schema-B0-p6T1O.js} +4 -4
  65. package/dist/{schema-BKdh6UoE.js.map → schema-B0-p6T1O.js.map} +1 -1
  66. package/dist/{skills-DEhYiPeO.js → skills-DfnTeyRz.js} +3 -3
  67. package/dist/{skills-DEhYiPeO.js.map → skills-DfnTeyRz.js.map} +1 -1
  68. package/dist/{start-BsPJedPQ.js → start-BmEZkS0n.js} +4 -4
  69. package/dist/{start-BsPJedPQ.js.map → start-BmEZkS0n.js.map} +1 -1
  70. package/dist/{status-D_B3tlDy.js → status-BJ26yZOo.js} +9 -9
  71. package/dist/{status-D_B3tlDy.js.map → status-BJ26yZOo.js.map} +1 -1
  72. package/dist/{storage-CtB8polS.js → storage-DKPUBTWG.js} +3 -3
  73. package/dist/{storage-CtB8polS.js.map → storage-DKPUBTWG.js.map} +1 -1
  74. package/dist/{telemetry-BYmPU-Ji.js → telemetry-m9czTNGR.js} +2 -2
  75. package/dist/{telemetry-BYmPU-Ji.js.map → telemetry-m9czTNGR.js.map} +1 -1
  76. package/dist/{upgrade-DbuKX9lv.js → upgrade-DjihWuZL.js} +5 -4
  77. package/dist/{upgrade-DbuKX9lv.js.map → upgrade-DjihWuZL.js.map} +1 -1
  78. package/dist/utils/args.d.ts +13 -0
  79. package/dist/utils/redact.d.ts +10 -0
  80. package/dist/utils/refusal.d.ts +18 -0
  81. package/package.json +7 -7
  82. package/templates/overlays/baas/README.md +2 -1
  83. package/templates/template/.env.example +6 -0
  84. package/templates/template/frontend/vite.config.ts +7 -73
  85. package/dist/api-keys-Bc4FJKYp.js.map +0 -1
  86. package/dist/args-CcBphFdj.js.map +0 -1
  87. package/dist/auth-BL7bNQVu.js.map +0 -1
  88. package/dist/bundle-CqURVN-K.js.map +0 -1
  89. package/dist/daemon-entry-C6pxdily.js.map +0 -1
  90. package/dist/db-Dkn9XhT-.js.map +0 -1
  91. package/dist/dev-preflight-CorMg7Ub.js.map +0 -1
  92. package/dist/init-CjoJoThg.js.map +0 -1
  93. package/dist/last-dev-database-BEBPfAMY.js +0 -2
  94. package/dist/prepare-C1iaiTC4.js.map +0 -1
  95. package/dist/pull-COpNJFzY.js.map +0 -1
  96. package/dist/resolve-b_p9bmdH.js +0 -2
@@ -1,8 +1,8 @@
1
1
  import { i as recordEvent } from "./telemetry-EMFRVRQi.js";
2
2
  import { _ as resolveTsxLoader, f as requireBackendDir, g as resolveTsx, h as resolvePluginCliScript, l as getActiveBackendPlugin, n as dependenciesNotInstalled, o as findEnvFile, p as requireProjectRoot } from "./project-Wp2zoyeN.js";
3
- import { a as unknownCommand, i as suggestCommand, n as parseCommandArgs, t as UsageError } from "./args-CcBphFdj.js";
3
+ import { a as unknownCommand, i as suggestCommand, n as parseCommandArgs, s as redactConnectionPasswords, t as UsageError } from "./args-BX0YD14a.js";
4
4
  import { r as refuseMissingCollectionsPath, t as COLLECTIONS_FLAG_HELP } from "./path-flags-BFgG9V6y.js";
5
- import { DEV_DATABASE_KIND_ENV, devDatabaseKind } from "./prepare-C1iaiTC4.js";
5
+ import { DEV_DATABASE_KIND_ENV, devDatabaseKind } from "./prepare-DdnU70z8.js";
6
6
  import chalk from "chalk";
7
7
  import fs from "fs";
8
8
  import os from "os";
@@ -116,9 +116,6 @@ function reportSpawnFailure(error) {
116
116
  //#endregion
117
117
  //#region src/commands/db.ts
118
118
  /**
119
- * CLI command: rebase db <action>
120
- */
121
- /**
122
119
  * The connection string a prepared database actually answers on.
123
120
  *
124
121
  * One function, because `db url` and `db pull` disagreed about it and the
@@ -244,6 +241,84 @@ function readFlagValue(rawArgs, flag) {
244
241
  }
245
242
  return null;
246
243
  }
244
+ /** `rebase db pull`'s flags. */
245
+ var PULL_FLAGS = {
246
+ "--from": String,
247
+ "--schema": [String],
248
+ "--anonymize": Boolean,
249
+ "--yes": Boolean,
250
+ "-y": "--yes",
251
+ "--docker": Boolean,
252
+ "--database-url": String
253
+ };
254
+ /** `rebase db url`'s flags. */
255
+ var URL_FLAGS = {
256
+ "--database-url": String,
257
+ "--docker": Boolean
258
+ };
259
+ /** `rebase db reset`'s flags. */
260
+ var RESET_FLAGS = {
261
+ "--yes": Boolean,
262
+ "-y": "--yes"
263
+ };
264
+ /** `rebase db stop` takes none. */
265
+ var STOP_FLAGS = {};
266
+ /** `rebase db pull`'s line, parsed strictly. */
267
+ function parsePullFlags(rawArgs) {
268
+ return parseCommandArgs({
269
+ spec: PULL_FLAGS,
270
+ rawArgs: [...rawArgs],
271
+ commandWords: 2,
272
+ command: "db pull",
273
+ maxPositionals: 0
274
+ }).flags;
275
+ }
276
+ /** `rebase db url`'s line, parsed strictly. */
277
+ function parseUrlFlags(rawArgs) {
278
+ return parseCommandArgs({
279
+ spec: URL_FLAGS,
280
+ rawArgs: [...rawArgs],
281
+ commandWords: 2,
282
+ command: "db url",
283
+ maxPositionals: 0
284
+ }).flags;
285
+ }
286
+ /** `rebase db reset`'s line, parsed strictly. */
287
+ function parseResetFlags(rawArgs) {
288
+ return parseCommandArgs({
289
+ spec: RESET_FLAGS,
290
+ rawArgs: [...rawArgs],
291
+ commandWords: 2,
292
+ command: "db reset",
293
+ maxPositionals: 0
294
+ }).flags;
295
+ }
296
+ /** `rebase db stop`'s line, parsed strictly. */
297
+ function parseStopFlags(rawArgs) {
298
+ return parseCommandArgs({
299
+ spec: STOP_FLAGS,
300
+ rawArgs: [...rawArgs],
301
+ commandWords: 2,
302
+ command: "db stop",
303
+ maxPositionals: 0
304
+ }).flags;
305
+ }
306
+ /**
307
+ * The `db` subcommands this CLI answers itself, each with its strict parse.
308
+ *
309
+ * The driver's `db` commands refuse a flag they do not take; these four never
310
+ * reach the driver, and read their flags out of argv by hand, so they accepted
311
+ * anything. On `pull` that cost personal data: `--anonymise` (or `--anonymiz`,
312
+ * or `--anon`) was dropped and the copy arrived as it was. An undeclared flag,
313
+ * or a word where none is taken, is now a `UsageError` naming the flag it was
314
+ * probably meant to be, raised before anything has run.
315
+ */
316
+ var OWN_SUBCOMMAND_PARSERS = {
317
+ pull: parsePullFlags,
318
+ url: parseUrlFlags,
319
+ reset: parseResetFlags,
320
+ stop: parseStopFlags
321
+ };
247
322
  /**
248
323
  * Run a database subcommand through the active driver's CLI, throwing on
249
324
  * failure instead of exiting.
@@ -313,7 +388,7 @@ var ATLAS_DEV_URL_ENV = "REBASE_ATLAS_DEV_URL";
313
388
  */
314
389
  var INVOCATION_CWD_ENV = "REBASE_INVOCATION_CWD";
315
390
  /** Loaded only when a command needs one: PGlite is 25 MB of WASM. */
316
- var startAtlasDevDatabase = async () => (await import("./atlas-dev-database-DeK3Sa4h.js")).startAtlasDevDatabase();
391
+ var startAtlasDevDatabase = async () => (await import("./atlas-dev-database-OWtqnG7W.js")).startAtlasDevDatabase();
317
392
  /**
318
393
  * The empty database an Atlas-backed subcommand plans against, on the managed
319
394
  * development database.
@@ -553,14 +628,14 @@ async function runDriverDbCommand(rawArgs, options = {}) {
553
628
  const env = { ...process.env };
554
629
  if (envFile) env.DOTENV_CONFIG_PATH = envFile;
555
630
  env[DEV_DATABASE_KIND_ENV] = devDatabaseKind(projectRoot) ?? "";
556
- const { resolveProjectDatabase } = await import("./prepare-C1iaiTC4.js");
631
+ const { resolveProjectDatabase } = await import("./prepare-DdnU70z8.js");
557
632
  const resolvedKind = resolveProjectDatabase(projectRoot, {
558
633
  flagUrl: readFlagValue(rawArgs, "--database-url"),
559
634
  flagDocker: rawArgs.includes("--docker")
560
635
  }).kind;
561
636
  refuseBranchOnManagedDatabase(rawArgs, resolvedKind);
562
637
  refuseRestoreOnManagedDatabase(rawArgs, resolvedKind);
563
- const { prepareDatabaseEnv, managedNotices } = await import("./prepare-C1iaiTC4.js");
638
+ const { prepareDatabaseEnv, managedNotices } = await import("./prepare-DdnU70z8.js");
564
639
  const prepared = await prepareDatabaseEnv(projectRoot, {
565
640
  flagUrl: readFlagValue(rawArgs, "--database-url"),
566
641
  flagDocker: rawArgs.includes("--docker"),
@@ -597,13 +672,13 @@ async function dbCommand(subcommand, rawArgs) {
597
672
  const action = argsFromCommand(rawArgs, "backups")[1];
598
673
  if (action !== void 0 && action !== "list") unknownCommand(action, ["list"], "db backups");
599
674
  }
675
+ OWN_SUBCOMMAND_PARSERS[subcommand]?.(rawArgs);
600
676
  const projectRoot = requireProjectRoot();
601
677
  recordEvent("cli.db", { subcommand: subcommand ?? "none" }, { projectRoot });
602
678
  if (subcommand === "stop" || subcommand === "reset") {
603
679
  await manageLocalDatabase(subcommand, projectRoot, rawArgs);
604
680
  return;
605
681
  }
606
- await ensureDockerDatabase(projectRoot, rawArgs);
607
682
  if (subcommand === "pull") {
608
683
  await pullIntoLocal(projectRoot, rawArgs);
609
684
  return;
@@ -612,6 +687,7 @@ async function dbCommand(subcommand, rawArgs) {
612
687
  await printDatabaseUrl(projectRoot, rawArgs);
613
688
  return;
614
689
  }
690
+ await ensureDockerDatabase(projectRoot, rawArgs);
615
691
  if (subcommand === "branch" && commandWords(rawArgs, "db")[2] === "switch") {
616
692
  await switchBranch(projectRoot, rawArgs);
617
693
  return;
@@ -620,6 +696,7 @@ async function dbCommand(subcommand, rawArgs) {
620
696
  if (subcommand === "branch") {
621
697
  const action = commandWords(rawArgs, "db")[2];
622
698
  if (action === "delete") await refuseDeletingActiveBranch(projectRoot, rawArgs);
699
+ if (action === "prune" || action === "list") await tellDriverTheActiveBranch(projectRoot);
623
700
  if (action && REGISTRY_ACTIONS.has(action)) driverArgs = await onParentDatabase(projectRoot, rawArgs, action);
624
701
  }
625
702
  refuseMissingCollectionsPath(driverArgs, process.cwd(), requireBackendDir(projectRoot));
@@ -654,21 +731,13 @@ async function dbCommand(subcommand, rawArgs) {
654
731
  * string for a database nobody is serving is not an answer.
655
732
  */
656
733
  async function printDatabaseUrl(projectRoot, rawArgs) {
657
- parseCommandArgs({
658
- spec: {
659
- "--database-url": String,
660
- "--docker": Boolean
661
- },
662
- rawArgs: [...rawArgs],
663
- commandWords: 2,
664
- command: "db url",
665
- maxPositionals: 0
666
- });
667
- const { prepareDatabaseEnv } = await import("./prepare-C1iaiTC4.js");
734
+ const flags = parseUrlFlags(rawArgs);
735
+ await ensureDockerDatabase(projectRoot, rawArgs);
736
+ const { prepareDatabaseEnv } = await import("./prepare-DdnU70z8.js");
668
737
  const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
669
738
  const url = databaseUrlOf(await prepareDatabaseEnv(projectRoot, {
670
- flagUrl: readFlagValue(rawArgs, "--database-url"),
671
- flagDocker: rawArgs.includes("--docker"),
739
+ flagUrl: flags["--database-url"] ?? null,
740
+ flagDocker: flags["--docker"] === true,
672
741
  quiet: true,
673
742
  onProgress: (message) => console.error(chalk.gray(` ${message}`))
674
743
  }), readEnvFile(projectRoot));
@@ -712,7 +781,7 @@ async function manageLocalDatabase(subcommand, projectRoot, rawArgs) {
712
781
  console.log(chalk.gray(nothingHere()));
713
782
  return;
714
783
  }
715
- if (!rawArgs.includes("--yes") && !rawArgs.includes("-y")) {
784
+ if (parseResetFlags(rawArgs)["--yes"] !== true) {
716
785
  if (!process.stdin.isTTY) {
717
786
  console.error(chalk.red("✗ `rebase db reset` deletes the local database and cannot prompt here."));
718
787
  console.error(chalk.yellow(" Re-run with --yes if that is what you intend."));
@@ -741,36 +810,40 @@ async function manageLocalDatabase(subcommand, projectRoot, rawArgs) {
741
810
  * and the wrong one here means overwriting production with a laptop.
742
811
  */
743
812
  async function pullIntoLocal(projectRoot, rawArgs) {
744
- const { describeRestoreFailure, describeTarget, dumpSource, findPgTool, restoreCopy } = await import("./pull-COpNJFzY.js");
745
- const { prepareDatabaseEnv } = await import("./prepare-C1iaiTC4.js");
813
+ const { describeRestoreFailure, describeTarget, dumpSource, findPgTool, restoreCopy } = await import("./pull-C3PXduzl.js");
814
+ const { prepareDatabaseEnv } = await import("./prepare-DdnU70z8.js");
746
815
  const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
747
- const source = readFlagValue(rawArgs, "--from");
816
+ const flags = parsePullFlags(rawArgs);
817
+ const schemas = flags["--schema"] ?? [];
818
+ const anonymize = flags["--anonymize"] === true;
819
+ const targetFlag = flags["--database-url"];
820
+ if (targetFlag !== void 0) {
821
+ console.error(chalk.red("✗ `rebase db pull` does not take --database-url."));
822
+ console.error("");
823
+ console.error(chalk.gray(" The target is always this project's local development database. There is"));
824
+ console.error(chalk.gray(" no flag that makes this write somewhere else, deliberately: a command that"));
825
+ console.error(chalk.gray(" can copy in both directions eventually copies in the wrong one."));
826
+ console.error("");
827
+ const shown = redactConnectionPasswords(targetFlag);
828
+ console.error(chalk.gray(` To read from another database, that is ${chalk.cyan("--from")}:`));
829
+ console.error(chalk.gray(` rebase db pull --from "${shown}"`));
830
+ if (shown !== targetFlag) console.error(chalk.gray(" with the password in place of ***."));
831
+ process.exit(1);
832
+ }
833
+ const source = flags["--from"];
748
834
  if (!source) {
749
835
  console.error(chalk.red("✗ `rebase db pull` needs a source: --from <connection-string>"));
750
836
  console.error(chalk.gray(" Example: rebase db pull --from \"$PRODUCTION_DATABASE_URL\""));
751
837
  process.exit(1);
752
838
  }
753
- const schemas = rawArgs.flatMap((arg, index) => arg === "--schema" && rawArgs[index + 1] ? [rawArgs[index + 1]] : []);
754
- const anonymize = rawArgs.includes("--anonymize");
755
839
  for (const tool of ["pg_dump", "pg_restore"]) if (!await findPgTool(tool)) {
756
840
  console.error(chalk.red(`✗ \`${tool}\` is not on PATH, and this command cannot run without it.`));
757
841
  console.error(chalk.gray(" Install the PostgreSQL client tools, e.g. `brew install libpq`."));
758
842
  process.exit(1);
759
843
  }
760
- const targetFlag = readFlagValue(rawArgs, "--database-url");
761
- if (targetFlag !== null) {
762
- console.error(chalk.red("✗ `rebase db pull` does not take --database-url."));
763
- console.error("");
764
- console.error(chalk.gray(" The target is always this project's local development database. There is"));
765
- console.error(chalk.gray(" no flag that makes this write somewhere else, deliberately: a command that"));
766
- console.error(chalk.gray(" can copy in both directions eventually copies in the wrong one."));
767
- console.error("");
768
- console.error(chalk.gray(` To read from another database, that is ${chalk.cyan("--from")}:`));
769
- console.error(chalk.gray(` rebase db pull --from ${targetFlag}`));
770
- process.exit(1);
771
- }
844
+ await ensureDockerDatabase(projectRoot, rawArgs);
772
845
  const prepared = await prepareDatabaseEnv(projectRoot, {
773
- flagDocker: rawArgs.includes("--docker"),
846
+ flagDocker: flags["--docker"] === true,
774
847
  onProgress: (message) => console.log(chalk.gray(` ${message}`))
775
848
  });
776
849
  const target = databaseUrlOf(prepared, readEnvFile(projectRoot)) ?? "";
@@ -792,7 +865,7 @@ async function pullIntoLocal(projectRoot, rawArgs) {
792
865
  console.log(` ${chalk.gray("Data")} ${anonymize ? "personal-looking columns will be overwritten after the copy" : chalk.yellow("copied as-is, including any personal data")}`);
793
866
  if (schemas.length > 0) console.log(` ${chalk.gray("Schemas")} ${schemas.join(", ")}`);
794
867
  console.log("");
795
- if (!rawArgs.includes("--yes") && !rawArgs.includes("-y")) {
868
+ if (flags["--yes"] !== true) {
796
869
  if (!process.stdin.isTTY) {
797
870
  console.error(chalk.red("✗ This replaces the local database and cannot prompt here."));
798
871
  console.error(chalk.yellow(" Re-run with --yes if that is what you intend."));
@@ -863,7 +936,7 @@ async function pullIntoLocal(projectRoot, rawArgs) {
863
936
  */
864
937
  async function restoreAppRole(target) {
865
938
  const { Client } = await import("pg");
866
- const { provisionableSchemas } = await import("./pull-COpNJFzY.js");
939
+ const { provisionableSchemas } = await import("./pull-C3PXduzl.js");
867
940
  const client = new Client({ connectionString: target });
868
941
  client.on("error", () => void 0);
869
942
  try {
@@ -898,7 +971,7 @@ async function restoreAppRole(target) {
898
971
  */
899
972
  async function anonymizeTarget(target, source, kind) {
900
973
  const { Client } = await import("pg");
901
- const { anonymizeCopy } = await import("./pull-COpNJFzY.js");
974
+ const { anonymizeCopy } = await import("./pull-C3PXduzl.js");
902
975
  const deleteIt = kind === "managed" ? `Delete it now: ${chalk.cyan("rebase db reset --yes")}` : kind === "docker" ? `Delete it now: ${chalk.cyan("docker compose down -v")}` : "Delete it now: drop the restored tables, or the database, before anything else reads it.";
903
976
  const holdsRealData = (reason) => [
904
977
  chalk.red(`✗ The copy could not be anonymized: ${reason}`),
@@ -945,8 +1018,8 @@ async function anonymizeTarget(target, source, kind) {
945
1018
  * own connection error follows, which is the same contract `dev` keeps.
946
1019
  */
947
1020
  async function ensureDockerDatabase(projectRoot, rawArgs) {
948
- const { ensureDevDatabase } = await import("./dev-preflight-CorMg7Ub.js").then((n) => n.n);
949
- const { resolveProjectDatabase } = await import("./prepare-C1iaiTC4.js");
1021
+ const { ensureDevDatabase } = await import("./dev-preflight-unHpiYO1.js").then((n) => n.n);
1022
+ const { resolveProjectDatabase } = await import("./prepare-DdnU70z8.js");
950
1023
  const resolved = resolveProjectDatabase(projectRoot, {
951
1024
  flagUrl: readFlagValue(rawArgs, "--database-url"),
952
1025
  flagDocker: rawArgs.includes("--docker")
@@ -960,7 +1033,7 @@ async function ensureDockerDatabase(projectRoot, rawArgs) {
960
1033
  disabled: false,
961
1034
  hasCollections: false,
962
1035
  pushSchema: async () => void 0,
963
- log: (message) => console.log(message)
1036
+ log: (message) => console.error(message)
964
1037
  });
965
1038
  }
966
1039
  /**
@@ -979,7 +1052,7 @@ async function ensureDockerDatabase(projectRoot, rawArgs) {
979
1052
  async function refuseDeletingActiveBranch(projectRoot, rawArgs) {
980
1053
  const [, , , name] = commandWords(rawArgs, "db");
981
1054
  if (!name) return;
982
- const { readActiveBranch } = await import("./branch-pointer-DTQNLFtb.js");
1055
+ const { readActiveBranch } = await import("./branch-pointer-9DnwkFJJ.js");
983
1056
  const active = readActiveBranch(projectRoot);
984
1057
  if (active?.name !== name) return;
985
1058
  const off = "rebase db branch switch --off";
@@ -997,6 +1070,29 @@ async function refuseDeletingActiveBranch(projectRoot, rawArgs) {
997
1070
  console.error("");
998
1071
  process.exit(1);
999
1072
  }
1073
+ /**
1074
+ * The variable that tells the driver which database this checkout is switched
1075
+ * to. Spelled the same in `packages/server-postgres/src/branch-prune.ts`.
1076
+ */
1077
+ var ACTIVE_BRANCH_DATABASE_ENV = "REBASE_ACTIVE_BRANCH_DATABASE";
1078
+ /**
1079
+ * Tell the driver which branch this checkout is on, for the two actions that
1080
+ * answer differently for it.
1081
+ *
1082
+ * - `prune` keeps it, as `delete` refuses it. `prune --older-than 0d --yes`
1083
+ * dropped it, and the checkout then pointed every command at a database
1084
+ * that no longer existed, with no word of `switch --off`.
1085
+ * - `list` marks it, where every branch had the same bullet.
1086
+ *
1087
+ * The pointer is the CLI's and the driver is a child process, so it is told
1088
+ * the database in its environment.
1089
+ */
1090
+ async function tellDriverTheActiveBranch(projectRoot) {
1091
+ const { readActiveBranch } = await import("./branch-pointer-9DnwkFJJ.js");
1092
+ const active = readActiveBranch(projectRoot);
1093
+ if (active) process.env[ACTIVE_BRANCH_DATABASE_ENV] = active.database;
1094
+ else delete process.env[ACTIVE_BRANCH_DATABASE_ENV];
1095
+ }
1000
1096
  /** The `branch` actions that read or write the registry — every one but `switch`. */
1001
1097
  var REGISTRY_ACTIONS = /* @__PURE__ */ new Set([
1002
1098
  "list",
@@ -1033,13 +1129,13 @@ var REGISTRY_ACTIONS = /* @__PURE__ */ new Set([
1033
1129
  */
1034
1130
  async function onParentDatabase(projectRoot, rawArgs, action) {
1035
1131
  if (readFlagValue(rawArgs, "--database-url") !== null) return rawArgs;
1036
- const { readActiveBranch } = await import("./branch-pointer-DTQNLFtb.js");
1132
+ const { readActiveBranch } = await import("./branch-pointer-9DnwkFJJ.js");
1037
1133
  const active = readActiveBranch(projectRoot);
1038
1134
  if (!active) return rawArgs;
1039
1135
  const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
1040
- const { resolveDevDatabase } = await import("./resolve-b_p9bmdH.js");
1041
- const { resolveComposeUrl } = await import("./prepare-C1iaiTC4.js");
1042
- const { readLastDevDocker } = await import("./last-dev-database-BEBPfAMY.js");
1136
+ const { resolveDevDatabase } = await import("./resolve-CNQjsatH.js");
1137
+ const { resolveComposeUrl } = await import("./prepare-DdnU70z8.js");
1138
+ const { readLastDevDocker } = await import("./last-dev-database-c_dKz1S3.js");
1043
1139
  const envFile = readEnvFile(projectRoot);
1044
1140
  const parent = resolveDevDatabase({
1045
1141
  flagDocker: rawArgs.includes("--docker"),
@@ -1084,10 +1180,15 @@ function assertSwitchFlags(rawArgs) {
1084
1180
  const flag = word.split("=")[0];
1085
1181
  if (SWITCH_FLAGS.includes(flag)) continue;
1086
1182
  const near = suggestCommand(flag.replace(/^-+/, ""), SWITCH_FLAGS.map((known) => known.slice(2)));
1087
- throw new UsageError(`\`rebase db branch switch\` has no option ${flag}` + (near ? ` — did you mean --${near}?` : " — it takes --off (or --main) and a branch name.") + " Nothing was changed.");
1183
+ throw new UsageError(`\`rebase db branch switch\` has no option ${flag}` + (near ? ` — did you mean --${near}?` : " — it takes --off (or --main) and a branch name.") + " Nothing was run. See `rebase db branch --help`.");
1088
1184
  }
1089
1185
  }
1090
1186
  /**
1187
+ * What `switch` cannot change: a `rebase dev` started before it connected to
1188
+ * the database it was given then, and serves it until it is restarted.
1189
+ */
1190
+ var RUNNING_DEV_KEEPS_ITS_DATABASE = "A `rebase dev` that is already running keeps the database it started on until you restart it.";
1191
+ /**
1091
1192
  * `rebase db branch switch <name>` — point this checkout at a branch.
1092
1193
  *
1093
1194
  * The step branching was missing. `create` copied the database in about a
@@ -1113,11 +1214,11 @@ function assertSwitchFlags(rawArgs) {
1113
1214
  */
1114
1215
  async function switchBranch(projectRoot, rawArgs) {
1115
1216
  assertSwitchFlags(rawArgs);
1116
- const { branchDatabaseName, clearActiveBranch, databaseNameOf, readActiveBranch, writeActiveBranch } = await import("./branch-pointer-DTQNLFtb.js");
1217
+ const { branchDatabaseName, clearActiveBranch, databaseNameOf, readActiveBranch, writeActiveBranch } = await import("./branch-pointer-9DnwkFJJ.js");
1117
1218
  const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
1118
- const { resolveDevDatabase } = await import("./resolve-b_p9bmdH.js");
1119
- const { resolveComposeUrl } = await import("./prepare-C1iaiTC4.js");
1120
- const { readLastDevDocker } = await import("./last-dev-database-BEBPfAMY.js");
1219
+ const { resolveDevDatabase } = await import("./resolve-CNQjsatH.js");
1220
+ const { resolveComposeUrl } = await import("./prepare-DdnU70z8.js");
1221
+ const { readLastDevDocker } = await import("./last-dev-database-c_dKz1S3.js");
1121
1222
  const goingOff = rawArgs.includes("--off") || rawArgs.includes("--main");
1122
1223
  const name = commandWords(rawArgs, "db")[3];
1123
1224
  const envFile = readEnvFile(projectRoot);
@@ -1150,6 +1251,7 @@ async function switchBranch(projectRoot, rawArgs) {
1150
1251
  clearActiveBranch(projectRoot);
1151
1252
  console.log("");
1152
1253
  console.log(active ? chalk.green(` ✓ Back on the main database${base ? ` (${databaseNameOf(base)})` : ""}.`) : chalk.gray(" Already on the main database."));
1254
+ if (active) console.log(chalk.gray(` ${RUNNING_DEV_KEEPS_ITS_DATABASE}`));
1153
1255
  console.log("");
1154
1256
  return;
1155
1257
  }
@@ -1161,6 +1263,9 @@ async function switchBranch(projectRoot, rawArgs) {
1161
1263
  process.exit(1);
1162
1264
  }
1163
1265
  const database = branchDatabaseName(name);
1266
+ const { reopenClosedDatabases, reopenedDatabasesNotice } = await import("@rebasepro/server-postgres");
1267
+ const healed = await reopenClosedDatabases(base, [readActiveBranch(projectRoot)?.database]);
1268
+ for (const line of reopenedDatabasesNotice(healed)) console.error(chalk.yellow(` ${line}`));
1164
1269
  const { Client } = await import("pg");
1165
1270
  const client = new Client({ connectionString: base });
1166
1271
  try {
@@ -1196,6 +1301,7 @@ async function switchBranch(projectRoot, rawArgs) {
1196
1301
  console.log(chalk.green(` ✓ Switched to branch "${name}".`));
1197
1302
  console.log(chalk.gray(` Database: ${database}`));
1198
1303
  console.log(chalk.gray(" Every rebase command in this checkout now uses it — dev, db push, migrate."));
1304
+ console.log(chalk.gray(` ${RUNNING_DEV_KEEPS_ITS_DATABASE}`));
1199
1305
  console.log(chalk.gray(` Back to the main database: ${chalk.cyan("rebase db branch switch --off")}`));
1200
1306
  console.log("");
1201
1307
  }
@@ -1283,7 +1389,12 @@ var DB_ACTION_HELP = {
1283
1389
  pull: {
1284
1390
  usage: "rebase db pull --from <url> [--schema <name>] [--anonymize] [--yes]",
1285
1391
  summary: "Copy another database into local development. One-directional by design — it can never push.",
1286
- notes: ["The target is not selectable: --database-url is refused, so this can never write to a remote database."]
1392
+ notes: [
1393
+ "--anonymize overwrites personal-looking columns after the copy. A misspelt flag is refused, never ignored.",
1394
+ "--schema <name> copies only that schema; repeat it for more.",
1395
+ "--docker pulls into Postgres in Docker rather than the database `rebase dev` would pick.",
1396
+ "The target is not selectable: --database-url is refused, so this can never write to a remote database."
1397
+ ]
1287
1398
  },
1288
1399
  stop: {
1289
1400
  usage: "rebase db stop",
@@ -1379,6 +1490,6 @@ function dbExamples(kind) {
1379
1490
  `;
1380
1491
  }
1381
1492
  //#endregion
1382
- export { DB_SUBCOMMANDS, absolutizeLocalPathArgs, dbCommand, ensureDockerDatabase, argsFromCommand as n, resolveDriverCli, runDriverDbCommand, runDriverSchemaCommand, spawnDriverCli, reportSpawnFailure as t };
1493
+ export { DB_SUBCOMMANDS, absolutizeLocalPathArgs, databaseUrlOf, dbCommand, ensureDockerDatabase, argsFromCommand as n, resolveDriverCli, runDriverDbCommand, runDriverSchemaCommand, spawnDriverCli, reportSpawnFailure as t };
1383
1494
 
1384
- //# sourceMappingURL=db-Dkn9XhT-.js.map
1495
+ //# sourceMappingURL=db-CRNpA5mH.js.map