@rebasepro/server-postgres 0.25.0 → 0.26.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 (144) hide show
  1. package/dist/{BranchService-iXXZeVYD.js → BranchService-CWBnDhcv.js} +88 -12
  2. package/dist/BranchService-CWBnDhcv.js.map +1 -0
  3. package/dist/PostgresBackendDriver.d.ts +13 -0
  4. package/dist/PostgresBootstrapper.d.ts +7 -0
  5. package/dist/auth/services.d.ts +8 -1
  6. package/dist/auth/verify-auth-tables.d.ts +21 -0
  7. package/dist/backup/backup-cli.d.ts +40 -3
  8. package/dist/backup/backup-service.d.ts +11 -0
  9. package/dist/{backup-service-Bb39plam.js → backup-cli-PoRG-zEq.js} +777 -10
  10. package/dist/backup-cli-PoRG-zEq.js.map +1 -0
  11. package/dist/{boot-ddl-s_3Hkz94.js → boot-ddl-EsgqDkx0.js} +3 -3
  12. package/dist/{boot-ddl-s_3Hkz94.js.map → boot-ddl-EsgqDkx0.js.map} +1 -1
  13. package/dist/branch-argv.d.ts +15 -0
  14. package/dist/branch-diff-CxE4VlxT.js +1396 -0
  15. package/dist/branch-diff-CxE4VlxT.js.map +1 -0
  16. package/dist/branch-diff-report-DpvVf7hR.js +48 -0
  17. package/dist/branch-diff-report-DpvVf7hR.js.map +1 -0
  18. package/dist/branching/branch-diff-report.d.ts +7 -0
  19. package/dist/branching/branch-diff.d.ts +115 -0
  20. package/dist/{cli-console-DQ_K-sdM.js → cli-console-f0k6_TsJ.js} +41 -9
  21. package/dist/cli-console-f0k6_TsJ.js.map +1 -0
  22. package/dist/cli-console.d.ts +17 -1
  23. package/dist/{cli-errors-DwQnNATs.js → cli-errors-DsYyNYzd.js} +90 -11
  24. package/dist/cli-errors-DsYyNYzd.js.map +1 -0
  25. package/dist/cli-errors.d.ts +14 -0
  26. package/dist/cli-flags.d.ts +51 -0
  27. package/dist/{cli-prompt-egtNKkZl.js → cli-prompt-DXG0yk-h.js} +39 -4
  28. package/dist/{cli-prompt-egtNKkZl.js.map → cli-prompt-DXG0yk-h.js.map} +1 -1
  29. package/dist/cli.js +121 -271
  30. package/dist/cli.js.map +1 -1
  31. package/dist/{collections-schema-version-T6cGvrDi.js → collections-schema-version-D7bDI0PJ.js} +13 -9
  32. package/dist/collections-schema-version-D7bDI0PJ.js.map +1 -0
  33. package/dist/{column-plan-helpers-D_V4oaZh.js → column-plan-helpers-IG6uFb1s.js} +2 -2
  34. package/dist/{column-plan-helpers-D_V4oaZh.js.map → column-plan-helpers-IG6uFb1s.js.map} +1 -1
  35. package/dist/{connection-C938nR3E.js → connection-czvI7TZL.js} +57 -10
  36. package/dist/connection-czvI7TZL.js.map +1 -0
  37. package/dist/{databasePoolManager-Yqdw14wY.js → databasePoolManager-3stMNFL-.js} +4 -6
  38. package/dist/databasePoolManager-3stMNFL-.js.map +1 -0
  39. package/dist/db-command-line.d.ts +14 -0
  40. package/dist/db-subcommands.d.ts +11 -0
  41. package/dist/{deferred-index-build-Cis_HoGn.js → deferred-index-build-CqaOv1Xx.js} +8 -8
  42. package/dist/{deferred-index-build-Cis_HoGn.js.map → deferred-index-build-CqaOv1Xx.js.map} +1 -1
  43. package/dist/{doctor-DvJH-IQG.js → doctor-DW_mlTzz.js} +186 -42
  44. package/dist/doctor-DW_mlTzz.js.map +1 -0
  45. package/dist/{ensure-collection-policies-CCqayoUz.js → ensure-collection-policies-DLWgabQ2.js} +13 -10
  46. package/dist/ensure-collection-policies-DLWgabQ2.js.map +1 -0
  47. package/dist/{ensure-collection-tables-DvvImXDe.js → ensure-collection-tables-CFIRq8ni.js} +9 -9
  48. package/dist/{ensure-collection-tables-DvvImXDe.js.map → ensure-collection-tables-CFIRq8ni.js.map} +1 -1
  49. package/dist/{ensure-tables-Dpgwx5sy.js → ensure-tables-4nA-tfwi.js} +5 -5
  50. package/dist/{ensure-tables-Dpgwx5sy.js.map → ensure-tables-4nA-tfwi.js.map} +1 -1
  51. package/dist/{enum-labels-kept-CUlUlRkO.js → enum-labels-kept-PcPW65xy.js} +3 -3
  52. package/dist/{enum-labels-kept-CUlUlRkO.js.map → enum-labels-kept-PcPW65xy.js.map} +1 -1
  53. package/dist/{generate-drizzle-schema-C3EAP9HE.js → generate-drizzle-schema-DC0BOUpn.js} +3 -3
  54. package/dist/{generate-drizzle-schema-C3EAP9HE.js.map → generate-drizzle-schema-DC0BOUpn.js.map} +1 -1
  55. package/dist/{generate-drizzle-schema-logic-DA3zM8zc.js → generate-drizzle-schema-logic-CPzCRD-8.js} +4 -4
  56. package/dist/{generate-drizzle-schema-logic-DA3zM8zc.js.map → generate-drizzle-schema-logic-CPzCRD-8.js.map} +1 -1
  57. package/dist/{generate-files-ClmOUHXj.js → generate-files-BP-4W_gm.js} +6 -6
  58. package/dist/{generate-files-ClmOUHXj.js.map → generate-files-BP-4W_gm.js.map} +1 -1
  59. package/dist/{generate-next-step-DCeS4LrJ.js → generate-next-step-DgK5BlBn.js} +2 -2
  60. package/dist/{generate-next-step-DCeS4LrJ.js.map → generate-next-step-DgK5BlBn.js.map} +1 -1
  61. package/dist/{generate-postgres-ddl-logic-4eUP4t8w.js → generate-postgres-ddl-logic-DPl1oH_z.js} +4 -4
  62. package/dist/{generate-postgres-ddl-logic-4eUP4t8w.js.map → generate-postgres-ddl-logic-DPl1oH_z.js.map} +1 -1
  63. package/dist/generated-schema-diff-eZCklRZQ.js +1025 -0
  64. package/dist/generated-schema-diff-eZCklRZQ.js.map +1 -0
  65. package/dist/{generated-schema-staleness-FlxM2i4i.js → generated-schema-staleness-BvNF3i-s.js} +2 -2
  66. package/dist/{generated-schema-staleness-FlxM2i4i.js.map → generated-schema-staleness-BvNF3i-s.js.map} +1 -1
  67. package/dist/history/HistoryService.d.ts +7 -0
  68. package/dist/index.d.ts +21 -0
  69. package/dist/index.es.js +288 -11
  70. package/dist/index.es.js.map +1 -1
  71. package/dist/{introspect-db-logic-CI5CU_n0.js → introspect-db-logic-DgQVzccW.js} +2 -2
  72. package/dist/{introspect-db-logic-CI5CU_n0.js.map → introspect-db-logic-DgQVzccW.js.map} +1 -1
  73. package/dist/{rls-bootstrap-sql-Bd-hJk08.js → migrate-baseline-B-2Ef4Mv.js} +718 -41
  74. package/dist/migrate-baseline-B-2Ef4Mv.js.map +1 -0
  75. package/dist/migrate-policy-stamps-BQtFHApx.js +89 -0
  76. package/dist/migrate-policy-stamps-BQtFHApx.js.map +1 -0
  77. package/dist/{open-rebase-BKA7Nyoe.js → open-rebase-C8jQ6s5a.js} +324 -1047
  78. package/dist/open-rebase-C8jQ6s5a.js.map +1 -0
  79. package/dist/open-rebase.d.ts +9 -1
  80. package/dist/{pg-error-utils-Bv5n2PLn.js → pg-error-utils-DhiUTlVx.js} +2 -2
  81. package/dist/{pg-error-utils-Bv5n2PLn.js.map → pg-error-utils-DhiUTlVx.js.map} +1 -1
  82. package/dist/{plan-schema-CXOucCw-.js → plan-schema-Czf3q4-Q.js} +4 -4
  83. package/dist/{plan-schema-CXOucCw-.js.map → plan-schema-Czf3q4-Q.js.map} +1 -1
  84. package/dist/{policy-drift-vm0BcvcE.js → policy-drift-X4A-xAzv.js} +3 -3
  85. package/dist/{policy-drift-vm0BcvcE.js.map → policy-drift-X4A-xAzv.js.map} +1 -1
  86. package/dist/pool-disconnects.d.ts +28 -0
  87. package/dist/{push-index-prebuild-DIequ4bV.js → push-index-prebuild-UTvB5pqH.js} +4 -4
  88. package/dist/{push-index-prebuild-DIequ4bV.js.map → push-index-prebuild-UTvB5pqH.js.map} +1 -1
  89. package/dist/push-kept-defaults-BGOlOqRQ.js +137 -0
  90. package/dist/push-kept-defaults-BGOlOqRQ.js.map +1 -0
  91. package/dist/{push-legacy-renames-BqJut4F3.js → push-legacy-renames-BwaKi8xF.js} +4 -4
  92. package/dist/{push-legacy-renames-BqJut4F3.js.map → push-legacy-renames-BwaKi8xF.js.map} +1 -1
  93. package/dist/{push-policy-plan-CvX8hiPb.js → push-policy-plan-DQ2tWceD.js} +5 -5
  94. package/dist/{push-policy-plan-CvX8hiPb.js.map → push-policy-plan-DQ2tWceD.js.map} +1 -1
  95. package/dist/{render-ddl-CQNwZdse.js → render-ddl-4v88y-Gv.js} +4 -4
  96. package/dist/{render-ddl-CQNwZdse.js.map → render-ddl-4v88y-Gv.js.map} +1 -1
  97. package/dist/{rls-enforcement-D7P4-ZYX.js → rls-enforcement-BOHuHVlc.js} +43 -4
  98. package/dist/rls-enforcement-BOHuHVlc.js.map +1 -0
  99. package/dist/schema/destructive-sql.d.ts +16 -0
  100. package/dist/schema/doctor-cli.js +5 -5
  101. package/dist/schema/doctor.d.ts +20 -2
  102. package/dist/schema/ensure-collection-policies.d.ts +4 -1
  103. package/dist/schema/generate-drizzle-schema.js +1 -1
  104. package/dist/schema/generate-postgres-ddl.js +2 -2
  105. package/dist/schema/generated-schema-diff.d.ts +21 -0
  106. package/dist/schema/introspect-db.js +5 -6
  107. package/dist/schema/introspect-db.js.map +1 -1
  108. package/dist/schema/migrate-policy-stamps.d.ts +23 -0
  109. package/dist/schema/migration-freshness.d.ts +69 -0
  110. package/dist/schema/push-kept-defaults.d.ts +57 -0
  111. package/dist/schema/push-policy-plan.d.ts +5 -0
  112. package/dist/schema/rls-bootstrap-sql.d.ts +47 -10
  113. package/dist/security/rls-enforcement.d.ts +18 -0
  114. package/dist/services/BranchService.d.ts +20 -2
  115. package/dist/services/FetchService.d.ts +12 -0
  116. package/dist/services/channel-presence.d.ts +3 -1
  117. package/dist/services/nested-path.d.ts +16 -0
  118. package/dist/services/pg-notify-listener.d.ts +2 -0
  119. package/dist/services/realtimeService.d.ts +18 -1
  120. package/dist/{source-Bv5KPeIx.js → source-fZb92pN8.js} +2 -2
  121. package/dist/{source-Bv5KPeIx.js.map → source-fZb92pN8.js.map} +1 -1
  122. package/dist/{vector-index-BFhyEaiz.js → vector-index-DsQ3V2d2.js} +2 -2
  123. package/dist/{vector-index-BFhyEaiz.js.map → vector-index-DsQ3V2d2.js.map} +1 -1
  124. package/dist/{websocket-MC0zTBar.js → websocket-CKYc3V4N.js} +56 -14
  125. package/dist/websocket-CKYc3V4N.js.map +1 -0
  126. package/package.json +7 -7
  127. package/dist/BranchService-iXXZeVYD.js.map +0 -1
  128. package/dist/backup-cli-B2CAn9fR.js +0 -647
  129. package/dist/backup-cli-B2CAn9fR.js.map +0 -1
  130. package/dist/backup-service-Bb39plam.js.map +0 -1
  131. package/dist/cli-console-DQ_K-sdM.js.map +0 -1
  132. package/dist/cli-errors-DwQnNATs.js.map +0 -1
  133. package/dist/cli-flags-D-b0qL9T.js +0 -206
  134. package/dist/cli-flags-D-b0qL9T.js.map +0 -1
  135. package/dist/collections-schema-version-T6cGvrDi.js.map +0 -1
  136. package/dist/connection-C938nR3E.js.map +0 -1
  137. package/dist/databasePoolManager-Yqdw14wY.js.map +0 -1
  138. package/dist/doctor-DvJH-IQG.js.map +0 -1
  139. package/dist/ensure-collection-policies-CCqayoUz.js.map +0 -1
  140. package/dist/open-rebase-BKA7Nyoe.js.map +0 -1
  141. package/dist/rls-bootstrap-sql-Bd-hJk08.js.map +0 -1
  142. package/dist/rls-enforcement-D7P4-ZYX.js.map +0 -1
  143. package/dist/rolldown-runtime-V7rFbMRe.js +0 -39
  144. package/dist/websocket-MC0zTBar.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 { 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-DwQnNATs.js";
5
- import { a as outWarn, i as outError, o as atlasExcludePattern, r as out, s as excludePatternParts, t as chalk } from "./source-Bv5KPeIx.js";
6
- import { t as nextStepAfterDbGenerate } from "./generate-next-step-DCeS4LrJ.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-D-b0qL9T.js";
3
+ import { n as require_arg, o as __toESM, t as promptConfirm } from "./cli-prompt-DXG0yk-h.js";
4
+ import { $ as forAtlas, 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 warnIfYesApprovedDestructive, 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, 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, tt as redactConnectionPasswords, v as describeBuildScriptRemedy, w as dropGeneratedColumns, x as detectProjectPackageManager, y as describeDevAddCommand, z as resolveLocalBin } from "./cli-errors-DsYyNYzd.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 { S as dropLegacyAuthSchema, T as execa, b as RLS_BOOTSTRAP_SQL, c as isDriverDbSubcommand, d as resolveBranchSwitches, f as unexpectedBranchArgs, g as collectionsPathIn, i as latestRecordedMigration, l as backupActionOf, m as assertKnownFlags, o as planBaseline, r as describeBaselinePlan, s as DRIVER_DB_SUBCOMMANDS, t as baselineVersionProblem, v as parseDriverLine, y as resolveDriverSwitches } from "./migrate-baseline-B-2Ef4Mv.js";
10
8
  import { formatRelativeTime } from "@rebasepro/utils";
11
9
  import path from "path";
12
10
  import fs from "fs";
@@ -892,102 +890,6 @@ var CommandStopped = class extends Error {
892
890
  }
893
891
  };
894
892
  //#endregion
895
- //#region src/schema/migrate-baseline.ts
896
- /**
897
- * What `rebase db migrate --baseline <version>` does, given the history the
898
- * database already has.
899
- *
900
- * The flag promises to record `<version>` as applied and migrate from the next
901
- * one. Atlas's own `migrate apply --baseline` keeps that promise only on a
902
- * database with no revision history: once one row exists it ignores the flag
903
- * without a word, applies the migration anyway, and the CLI had already printed
904
- * "Recording … as already applied". That is the normal second time: a project
905
- * baselines once, then `rebase dev` adds a column at boot, `db generate` writes
906
- * the migration for it, and `db migrate` fails on `column … already exists
907
- * (42701)` however the baseline is spelled.
908
- *
909
- * So the history is read first. With none, Atlas's baseline does the work.
910
- * Behind `<version>`, `atlas migrate set` marks every migration up to it as
911
- * applied, which is what a baseline means. At or past it, there is nothing to
912
- * record, and the command says so instead of claiming it recorded something.
913
- */
914
- /**
915
- * Atlas's version order for the versions Rebase writes: numeric timestamps,
916
- * compared as numbers so a shorter one is not read as later; anything else as
917
- * text.
918
- */
919
- function compareMigrationVersions(a, b) {
920
- if (/^\d+$/.test(a) && /^\d+$/.test(b)) {
921
- const x = BigInt(a);
922
- const y = BigInt(b);
923
- return x === y ? 0 : x < y ? -1 : 1;
924
- }
925
- return a.localeCompare(b);
926
- }
927
- /**
928
- * The version Atlas records for a migration file: its numeric prefix
929
- * (`20260906101530_init.sql` → `20260906101530`), or the name without `.sql`.
930
- */
931
- function migrationVersionOf(file) {
932
- return /^(\d+)/.exec(file)?.[1] ?? file.replace(/\.sql$/, "");
933
- }
934
- /** How many versions a refused baseline names, newest last. */
935
- var VERSIONS_NAMED = 5;
936
- /**
937
- * Why `--baseline <version>` cannot run, or `null` when it names a migration
938
- * file in `drizzle/migrations`.
939
- *
940
- * Asked before anything else, the database included. A version no file has
941
- * was refused only by Atlas, after the command had said "Marking every
942
- * migration up to abc as applied…"; and one older than every file read
943
- * "Nothing to record" and migrated on, though it named nothing to baseline.
944
- *
945
- * @param files the migration files, sorted oldest first.
946
- * @returns the refusal, its first line the error and the rest the detail.
947
- */
948
- function baselineVersionProblem(version, files) {
949
- const versions = files.map(migrationVersionOf);
950
- if (versions.length === 0) return `--baseline ${version}: There are no migrations in drizzle/migrations to baseline. Nothing was run.\nRun \`rebase db generate\` to write the first one.`;
951
- if (versions.includes(version)) return null;
952
- const named = versions.slice(-5).join(", ");
953
- return `--baseline ${version} names no migration in drizzle/migrations. Nothing was run.\n${versions.length > VERSIONS_NAMED ? `The newest ${VERSIONS_NAMED} of the ${versions.length} versions there` : "The versions there"}: ${named}. A baseline is one of them: the newest migration the database already holds.`;
954
- }
955
- /** How to keep `--baseline <version>`'s promise, given the newest recorded version. */
956
- function planBaseline(version, latestRecorded) {
957
- if (latestRecorded === null) return { kind: "atlas-baseline" };
958
- if (compareMigrationVersions(version, latestRecorded) > 0) return {
959
- kind: "set",
960
- latest: latestRecorded
961
- };
962
- return {
963
- kind: "already-recorded",
964
- latest: latestRecorded
965
- };
966
- }
967
- /** What the command says before it migrates, for each plan. */
968
- function describeBaselinePlan(version, plan) {
969
- switch (plan.kind) {
970
- case "atlas-baseline": return `Recording ${version} as already applied, then migrating from the next one.`;
971
- case "set": return `This database already records migrations up to ${plan.latest}, and Atlas applies --baseline only to a database with none.\n Marking every migration up to ${version} as applied with \`atlas migrate set\`, then migrating from the next one.`;
972
- case "already-recorded": return `Nothing to record: this database already records migrations up to ${plan.latest}, which includes ${version}.\n Migrating from the next one.`;
973
- }
974
- }
975
- /**
976
- * The newest version Atlas has recorded on this database, or `null` when it
977
- * has recorded none (no revisions table yet included).
978
- *
979
- * The table is `rebase.atlas_schema_revisions`: the CLI passes
980
- * `--revisions-schema rebase` to every `migrate apply`.
981
- */
982
- async function latestRecordedMigration(databaseUrl) {
983
- return withAppClient(databaseUrl, async (client) => {
984
- if (!(await client.query("SELECT to_regclass('rebase.atlas_schema_revisions') IS NOT NULL AS present")).rows[0]?.present) return null;
985
- const versions = (await client.query("SELECT version FROM rebase.atlas_schema_revisions WHERE version NOT LIKE '.%'")).rows.map((row) => row.version);
986
- if (versions.length === 0) return null;
987
- return versions.reduce((latest, version) => compareMigrationVersions(version, latest) > 0 ? version : latest);
988
- });
989
- }
990
- //#endregion
991
893
  //#region src/cli-push.ts
992
894
  /**
993
895
  * Apply a planned push.
@@ -1072,121 +974,6 @@ async function applyPoliciesFile(client, policiesSql, stamping) {
1072
974
  };
1073
975
  }
1074
976
  //#endregion
1075
- //#region src/branch-argv.ts
1076
- /**
1077
- * Argument shapes for `rebase db branch`, with no runtime dependencies.
1078
- *
1079
- * Its own module for the same reason `schema/atlas-argv.ts` is: `cli.ts` pulls
1080
- * in chalk, execa and the driver runtime, so a unit test that imports it cannot
1081
- * run. Argv parsing is the part most worth testing and the part least in need
1082
- * of any of that.
1083
- */
1084
- /**
1085
- * The flags each driver-side `db branch` action takes, besides the ones the CLI
1086
- * relays on every line (`--database-url`, `--docker`, `--debug`).
1087
- *
1088
- * `switch` is absent: the CLI answers it before the driver is ever spawned.
1089
- * An action not listed here is not checked, so the dispatch can say it does
1090
- * not exist in its own words.
1091
- */
1092
- var BRANCH_ACTION_FLAGS = {
1093
- create: {
1094
- "--from": String,
1095
- "--force": Boolean
1096
- },
1097
- list: {},
1098
- info: {},
1099
- delete: {
1100
- "--force": Boolean,
1101
- "--yes": Boolean,
1102
- "-y": "--yes"
1103
- },
1104
- prune: {
1105
- "--older-than": String,
1106
- "--include-dev-diff": Boolean,
1107
- "--yes": Boolean,
1108
- "-y": "--yes"
1109
- }
1110
- };
1111
- /**
1112
- * Refuse a flag `action` does not take, naming the one it was probably meant
1113
- * to be — the same sentence `db backup` and `db restore` say.
1114
- *
1115
- * Throws: the driver's entry turns a thrown error into one red line and exit 1,
1116
- * and this runs before anything connects.
1117
- */
1118
- function assertKnownBranchFlags(action, rest) {
1119
- const spec = BRANCH_ACTION_FLAGS[action];
1120
- if (!spec) return;
1121
- const full = {
1122
- ...RELAYED_FLAGS,
1123
- ...spec
1124
- };
1125
- try {
1126
- (0, import_arg.default)(full, { argv: [...rest] });
1127
- } catch (error) {
1128
- if (!(error instanceof Error) || !("code" in error) || error.code !== "ARG_UNKNOWN_OPTION") throw error;
1129
- const typed = (/option: (\S+)$/.exec(error.message)?.[1] ?? error.message).split("=")[0];
1130
- const suggestion = closestWord(typed, Object.keys(full).filter((flag) => flag.startsWith("--")));
1131
- const own = Object.keys(spec).filter((flag) => flag.startsWith("--"));
1132
- const takes = own.length > 0 ? `it takes ${own.join(", ")}` : "it takes no options of its own";
1133
- 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`.");
1134
- }
1135
- }
1136
- /**
1137
- * Words on a `db branch` command line that no argument accounts for.
1138
- *
1139
- * `rebase db branch create alpha beta` created a branch called `alpha` and
1140
- * threw `beta` away without a word. The shapes that produces are all quiet and
1141
- * all wrong: an unquoted name (`create my feature` → `my`), a flag written
1142
- * without its dashes (`create feat from main` → `feat`), a shell that split
1143
- * something you thought was one token. In each case the command succeeds and
1144
- * the branch is not the one asked for — and branch names are the thing you
1145
- * later type to switch, delete, or point a deploy at.
1146
- *
1147
- * A flag the action does not take is refused outright, by throwing — see
1148
- * {@link BRANCH_ACTION_FLAGS}. It was let through on the reasoning that a
1149
- * subcommand added later might take flags this file had never heard of; what
1150
- * that bought was every typo running without the flag it meant:
1151
- * `prune --older-then 1d --yes` pruned by no age, `create x --froce` ran
1152
- * without --force. A new action gets its line in the table. The value after a
1153
- * flag that takes one is skipped: it is that flag's argument, not a stray word.
1154
- *
1155
- * @param words The command's own arguments: action, name, then the rest.
1156
- */
1157
- function unexpectedBranchArgs(words) {
1158
- if (words[0]) assertKnownBranchFlags(words[0], words.slice(1));
1159
- const extras = [];
1160
- let seenName = false;
1161
- for (let index = 1; index < words.length; index += 1) {
1162
- const word = words[index];
1163
- if (word.startsWith("-")) {
1164
- if (TAKES_A_VALUE.has(word.split("=")[0])) index += 1;
1165
- continue;
1166
- }
1167
- if (!seenName) {
1168
- seenName = true;
1169
- continue;
1170
- }
1171
- extras.push(word);
1172
- }
1173
- return extras;
1174
- }
1175
- /**
1176
- * Branch-line flags whose next word belongs to them.
1177
- *
1178
- * `--from` was the only one listed, and `--database-url` is the one that bit:
1179
- * `rebase db branch list --database-url postgres://…` — which the CLI itself
1180
- * appends when the checkout is on a branch, so `rebase.branches` is read in the
1181
- * parent where it lives — answered `✗ Unexpected argument: postgres://…`. The
1182
- * `=` form carries its value in the same word and needs no skip.
1183
- */
1184
- var TAKES_A_VALUE = /* @__PURE__ */ new Set([
1185
- "--from",
1186
- "--older-than",
1187
- "--database-url"
1188
- ]);
1189
- //#endregion
1190
977
  //#region src/cli-collections-path.ts
1191
978
  /**
1192
979
  * `--collections <dir>`, checked once, before anything is written.
@@ -1263,14 +1050,6 @@ function assertCollectionsPathExists(typed) {
1263
1050
  throw new CollectionsPathMissing(typed, resolved);
1264
1051
  }
1265
1052
  //#endregion
1266
- //#region src/backup-argv.ts
1267
- /**
1268
- * @param rawArgs the driver's whole line, `["db", "backup", …]`.
1269
- */
1270
- function backupActionOf(rawArgs) {
1271
- return rawArgs[2] === "list" ? "list" : "create";
1272
- }
1273
- //#endregion
1274
1053
  //#region src/branch-prune.ts
1275
1054
  /**
1276
1055
  * The variable the CLI hands the driver the database its checkout is switched
@@ -1426,7 +1205,7 @@ function generatesInProcess() {
1426
1205
  async function generateInProcess(what, label, run) {
1427
1206
  let generators;
1428
1207
  try {
1429
- generators = await import("./generate-files-ClmOUHXj.js").then((n) => n.t);
1208
+ generators = await import("./generate-files-BP-4W_gm.js").then((n) => n.t);
1430
1209
  } catch (err) {
1431
1210
  outError(chalk.red(`✗ Failed to run ${what}: ${err instanceof Error ? err.message : String(err)}`));
1432
1211
  process.exit(1);
@@ -1466,13 +1245,14 @@ async function runPluginCommand(args) {
1466
1245
  const domain = args[0];
1467
1246
  const subcommand = args[1];
1468
1247
  assertKnownFlags(domain, subcommand, args);
1248
+ args = resolveDriverSwitches(domain, subcommand, args);
1469
1249
  assertCollectionsPathExists(collectionsPathIn(args));
1470
1250
  try {
1471
1251
  if (domain === "db") await scratchDatabase.around(() => dbCommand(subcommand, args));
1472
1252
  else if (domain === "schema") await schemaCommand(subcommand, args);
1473
1253
  else if (domain === "doctor") await doctorPluginCommand(args);
1474
1254
  else if (domain === "console") {
1475
- const { consoleCommand } = await import("./cli-console-DQ_K-sdM.js");
1255
+ const { consoleCommand } = await import("./cli-console-f0k6_TsJ.js");
1476
1256
  process.exitCode = await consoleCommand(args);
1477
1257
  } else {
1478
1258
  outError(chalk.red(`Unknown domain command: ${domain}`));
@@ -1623,17 +1403,8 @@ var DB_FLAGS = {
1623
1403
  "-y": "--yes"
1624
1404
  };
1625
1405
  async function dbCommand(subcommand, rawArgs) {
1626
- const VALID_ACTIONS = [
1627
- "push",
1628
- "generate",
1629
- "migrate",
1630
- "branch",
1631
- "backup",
1632
- "restore",
1633
- "backups"
1634
- ];
1635
- if (!subcommand || !VALID_ACTIONS.includes(subcommand)) {
1636
- outError(chalk.red(`Unknown db command. Valid: ${VALID_ACTIONS.join(", ")}`));
1406
+ if (!isDriverDbSubcommand(subcommand)) {
1407
+ outError(chalk.red(`Unknown db command. Valid: ${DRIVER_DB_SUBCOMMANDS.join(", ")}`));
1637
1408
  process.exit(1);
1638
1409
  }
1639
1410
  if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
@@ -1648,7 +1419,7 @@ async function dbCommand(subcommand, rawArgs) {
1648
1419
  return;
1649
1420
  }
1650
1421
  if (subcommand === "backup" || subcommand === "restore" || subcommand === "backups") {
1651
- const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-B2CAn9fR.js");
1422
+ const { backupCommand, restoreCommand, backupsCommand } = await import("./backup-cli-PoRG-zEq.js").then((n) => n.t);
1652
1423
  if (subcommand === "backup" && backupActionOf(rawArgs) === "list") await backupsCommand(rawArgs);
1653
1424
  else if (subcommand === "backup") await backupCommand(rawArgs);
1654
1425
  else if (subcommand === "restore") await restoreCommand(rawArgs);
@@ -1695,7 +1466,7 @@ async function dbCommand(subcommand, rawArgs) {
1695
1466
  }
1696
1467
  const searchContent = readSearchDdl();
1697
1468
  if (searchContent) {
1698
- const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-4eUP4t8w.js").then((n) => n.o);
1469
+ const { searchColumnDependencies } = await import("./generate-postgres-ddl-logic-DPl1oH_z.js").then((n) => n.o);
1699
1470
  const migrationConflicts = findGeneratedColumnConflicts(parseColumnMutations(migrationContent), searchColumnDependencies(await loadCollectionsForCli(collectionsPath)));
1700
1471
  const preamble = migrationDropPreamble(migrationConflicts);
1701
1472
  if (preamble) {
@@ -1769,6 +1540,7 @@ async function dbCommand(subcommand, rawArgs) {
1769
1540
  if (databaseUrl && !dryRun) await ensureAuthSchemaAndFunctions(databaseUrl);
1770
1541
  if (databaseUrl) await renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun);
1771
1542
  const prebuilt = databaseUrl ? await prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) : [];
1543
+ if (databaseUrl) await keepDatabaseOwnedDefaults(databaseUrl, collectionsPath);
1772
1544
  const plan = await runAtlas("schema", [
1773
1545
  "apply",
1774
1546
  "--to",
@@ -1833,6 +1605,7 @@ async function dbCommand(subcommand, rawArgs) {
1833
1605
  for (const line of destructiveLines(destructive)) outWarn(line);
1834
1606
  outWarn("");
1835
1607
  outWarn(chalk.yellow(" Applying them needs `rebase db push --allow-destructive`. Back up first: rebase db backup"));
1608
+ outWarn(chalk.gray(" (`--yes` still approves them in this release, with a deprecation warning; from the next it will not.)"));
1836
1609
  outWarn("");
1837
1610
  }
1838
1611
  out(chalk.gray(" The auth schema step was skipped, because it writes. A real push runs it first."));
@@ -1867,7 +1640,10 @@ async function dbCommand(subcommand, rawArgs) {
1867
1640
  out(chalk.gray(" Aborted. No changes were made."));
1868
1641
  throw new CommandStopped("The destructive push was declined.");
1869
1642
  }
1870
- } else outWarn(chalk.yellow(` Proceeding because ${optIn ?? "--allow-destructive"} was passed.`));
1643
+ } else {
1644
+ outWarn(chalk.yellow(` Proceeding because ${optIn ?? "--allow-destructive"} was passed.`));
1645
+ warnIfYesApprovedDestructive(optIn, destructive.length);
1646
+ }
1871
1647
  }
1872
1648
  if (policyPlan?.summary) {
1873
1649
  out(chalk.gray(policyPlan.summary));
@@ -1958,6 +1734,8 @@ async function dbCommand(subcommand, rawArgs) {
1958
1734
  if (databaseUrl) {
1959
1735
  await ensureRlsUserRole(databaseUrl);
1960
1736
  await retireLegacyAuthSchema(databaseUrl);
1737
+ const { stampMigratedPolicies } = await import("./migrate-policy-stamps-BQtFHApx.js");
1738
+ await stampMigratedPolicies(databaseUrl, collectionsPath);
1961
1739
  }
1962
1740
  }
1963
1741
  out("");
@@ -1975,12 +1753,43 @@ async function dbCommand(subcommand, rawArgs) {
1975
1753
  *
1976
1754
  * @returns `schema.index` of each one missing when this started.
1977
1755
  */
1756
+ /**
1757
+ * Appends to `schema.sql` the live DEFAULT of every column declared
1758
+ * `databaseDefault: true`, so Atlas plans no `DROP DEFAULT` for it.
1759
+ *
1760
+ * Fails CLOSED, like the exclude lists: without the catalogue the desired state
1761
+ * says "no DEFAULT", and the push would drop each of them. A project declaring
1762
+ * no such column reads nothing.
1763
+ */
1764
+ async function keepDatabaseOwnedDefaults(databaseUrl, collectionsPath) {
1765
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
1766
+ const { databaseOwnedDefaultColumns, readKeptDefaults, withKeptDefaults } = await import("./push-kept-defaults-BGOlOqRQ.js");
1767
+ const columns = databaseOwnedDefaultColumns(await loadCollections(path.resolve(process.cwd(), collectionsPath)));
1768
+ if (columns.length === 0) return;
1769
+ let kept;
1770
+ try {
1771
+ kept = await withAppClient(databaseUrl, (client) => readKeptDefaults({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, columns));
1772
+ } catch (err) {
1773
+ outError(chalk.red("\n✗ Aborting push: could not read the DEFAULTs of the columns declared `databaseDefault: true`."));
1774
+ outError(chalk.gray(` ${err instanceof Error ? err.message : String(err)}`));
1775
+ outError(chalk.gray(" Refusing to plan without them: the push would drop each of those DEFAULTs."));
1776
+ const hint = diagnoseDbError(err, databaseUrl);
1777
+ if (hint) outError(hint);
1778
+ throw new CommandStopped("Could not read the DEFAULTs to keep.");
1779
+ }
1780
+ if (kept.length === 0) return;
1781
+ const desiredSqlFile = path.join(generatedSqlDir(), "schema.sql");
1782
+ fs.writeFileSync(desiredSqlFile, withKeptDefaults(fs.readFileSync(desiredSqlFile, "utf-8"), kept));
1783
+ out(chalk.gray(` Keeping ${kept.length} DEFAULT(s) the database holds, for columns declared \`databaseDefault: true\`:`));
1784
+ for (const each of kept) out(chalk.gray(` ${each.table}.${each.column} DEFAULT ${each.expression}`));
1785
+ out("");
1786
+ }
1978
1787
  /** Renames relation columns that carry their pre-0.13 derived name, as boot does; a dry-run only names them. */
1979
1788
  async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
1980
1789
  let renames;
1981
1790
  try {
1982
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
1983
- const { legacyForeignKeyRenames } = await import("./push-legacy-renames-BqJut4F3.js");
1791
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
1792
+ const { legacyForeignKeyRenames } = await import("./push-legacy-renames-BwaKi8xF.js");
1984
1793
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
1985
1794
  renames = await withAppClient(databaseUrl, (client) => legacyForeignKeyRenames({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
1986
1795
  } catch {
@@ -1999,8 +1808,8 @@ async function renameLegacyForeignKeys(databaseUrl, collectionsPath, dryRun) {
1999
1808
  /** Names the enum labels the database keeps after the collections dropped them. See `schema/enum-labels-kept.ts`. */
2000
1809
  async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
2001
1810
  try {
2002
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2003
- const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-CUlUlRkO.js");
1811
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
1812
+ const { keptEnumLabels, formatKeptEnumLabelsNotice } = await import("./enum-labels-kept-PcPW65xy.js");
2004
1813
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2005
1814
  const kept = await withAppClient(databaseUrl, (client) => keptEnumLabels({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
2006
1815
  if (kept.length > 0) outWarn(chalk.yellow(formatKeptEnumLabelsNotice(kept)));
@@ -2009,8 +1818,8 @@ async function reportKeptEnumLabels(databaseUrl, collectionsPath) {
2009
1818
  async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
2010
1819
  let missing;
2011
1820
  try {
2012
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2013
- const { missingForeignKeyIndexes } = await import("./push-index-prebuild-DIequ4bV.js");
1821
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
1822
+ const { missingForeignKeyIndexes } = await import("./push-index-prebuild-UTvB5pqH.js");
2014
1823
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2015
1824
  missing = await withAppClient(databaseUrl, (client) => missingForeignKeyIndexes({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections));
2016
1825
  } catch {
@@ -2020,7 +1829,7 @@ async function prebuildForeignKeyIndexes(databaseUrl, collectionsPath, dryRun) {
2020
1829
  if (missing.length === 0 || dryRun) return names;
2021
1830
  out(chalk.gray(` Building ${missing.length} foreign-key index(es) on existing tables first — CONCURRENTLY, so writes go on:`));
2022
1831
  try {
2023
- const { buildDeferredIndexes } = await import("./deferred-index-build-Cis_HoGn.js").then((n) => n.r);
1832
+ const { buildDeferredIndexes } = await import("./deferred-index-build-CqaOv1Xx.js").then((n) => n.r);
2024
1833
  const outcome = await withAppClient(databaseUrl, (client) => buildDeferredIndexes(async () => ({
2025
1834
  dedicated: true,
2026
1835
  query: async (text) => ({ rows: (await client.query(text)).rows }),
@@ -2068,9 +1877,9 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
2068
1877
  let unsecured;
2069
1878
  let userRole;
2070
1879
  try {
2071
- const { lockCollectionTables } = await import("./ensure-collection-policies-CCqayoUz.js");
2072
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2073
- userRole = (await import("./rls-enforcement-D7P4-ZYX.js").then((n) => n.c)).REBASE_USER_ROLE;
1880
+ const { lockCollectionTables } = await import("./ensure-collection-policies-DLWgabQ2.js");
1881
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
1882
+ userRole = (await import("./rls-enforcement-BOHuHVlc.js").then((n) => n.l)).REBASE_USER_ROLE;
2074
1883
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2075
1884
  ({unsecured} = await withAppClient(databaseUrl, (client) => lockCollectionTables({ query: async (text) => ({ rows: (await client.query(text)).rows }) }, collections)));
2076
1885
  } catch (err) {
@@ -2105,8 +1914,8 @@ async function lockManagedTables(databaseUrl, collectionsPath) {
2105
1914
  async function ensureAuthTables(databaseUrl, collectionsPath) {
2106
1915
  try {
2107
1916
  const { drizzle } = await import("drizzle-orm/node-postgres");
2108
- const { ensureAuthTablesExist } = await import("./ensure-tables-Dpgwx5sy.js").then((n) => n.n);
2109
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
1917
+ const { ensureAuthTablesExist } = await import("./ensure-tables-4nA-tfwi.js").then((n) => n.n);
1918
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
2110
1919
  const authCollection = (await loadCollections(path.resolve(process.cwd(), collectionsPath))).find((c) => {
2111
1920
  const a = c.auth;
2112
1921
  return a === true || typeof a === "object" && a !== null && a.enabled === true;
@@ -2126,7 +1935,7 @@ async function ensureRlsUserRole(databaseUrl) {
2126
1935
  const schemas = ["public", "rebase"];
2127
1936
  let rls;
2128
1937
  try {
2129
- rls = await import("./rls-enforcement-D7P4-ZYX.js").then((n) => n.c);
1938
+ rls = await import("./rls-enforcement-BOHuHVlc.js").then((n) => n.l);
2130
1939
  } catch (err) {
2131
1940
  outError(chalk.red(`\n ✗ Could not load the RLS provisioning module: ${err instanceof Error ? err.message : String(err)}`));
2132
1941
  return;
@@ -2186,10 +1995,10 @@ async function applyPolicies(databaseUrl, collectionsPath) {
2186
1995
  */
2187
1996
  async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
2188
1997
  try {
2189
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2190
- const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-4eUP4t8w.js").then((n) => n.o);
2191
- const { policyStampSql } = await import("./ensure-collection-policies-CCqayoUz.js");
2192
- const { pinSearchPath } = await import("./connection-C938nR3E.js").then((n) => n.n);
1998
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
1999
+ const { planCollectionPolicies } = await import("./generate-postgres-ddl-logic-DPl1oH_z.js").then((n) => n.o);
2000
+ const { policyStampSql } = await import("./ensure-collection-policies-DLWgabQ2.js");
2001
+ const { pinSearchPath } = await import("./connection-czvI7TZL.js").then((n) => n.n);
2193
2002
  return {
2194
2003
  statements: stampableTables(planCollectionPolicies(await loadCollections(path.resolve(process.cwd(), collectionsPath))), policiesSql).map((plan) => policyStampSql(plan)).filter((statement) => statement !== void 0),
2195
2004
  searchPath: pinSearchPath(databaseUrl) === databaseUrl ? void 0 : "public"
@@ -2206,9 +2015,9 @@ async function policyStamping(databaseUrl, collectionsPath, policiesSql) {
2206
2015
  */
2207
2016
  async function readPolicyPushPlan(databaseUrl, collectionsPath) {
2208
2017
  try {
2209
- const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-CvX8hiPb.js");
2210
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2211
- const { pinSearchPath } = await import("./connection-C938nR3E.js").then((n) => n.n);
2018
+ const { formatPolicyPushPlan, planPolicyPush, summarizePolicyPushPlan } = await import("./push-policy-plan-DQ2tWceD.js");
2019
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
2020
+ const { pinSearchPath } = await import("./connection-czvI7TZL.js").then((n) => n.n);
2212
2021
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2213
2022
  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" }));
2214
2023
  return {
@@ -2235,8 +2044,8 @@ async function readPolicyPushPlan(databaseUrl, collectionsPath) {
2235
2044
  */
2236
2045
  async function reconcilePolicies(databaseUrl, collectionsPath) {
2237
2046
  try {
2238
- const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-vm0BcvcE.js").then((n) => n.s);
2239
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2047
+ const { checkPolicyDrift, dropOrphanedPolicies, formatPolicyDrift, hasDrift } = await import("./policy-drift-X4A-xAzv.js").then((n) => n.s);
2048
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
2240
2049
  const collections = await loadCollections(path.resolve(process.cwd(), collectionsPath));
2241
2050
  await withAppClient(databaseUrl, async (client) => {
2242
2051
  const drift = await checkPolicyDrift(client, collections);
@@ -2279,6 +2088,8 @@ var BRANCH_FLAGS = {
2279
2088
  "--older-than": String,
2280
2089
  "--include-dev-diff": Boolean,
2281
2090
  "--from": String,
2091
+ "--json": Boolean,
2092
+ "--sample-limit": Number,
2282
2093
  "--yes": Boolean,
2283
2094
  "-y": "--yes"
2284
2095
  };
@@ -2294,13 +2105,14 @@ async function branchCommand(rawArgs) {
2294
2105
  return;
2295
2106
  }
2296
2107
  const extras = unexpectedBranchArgs(rawArgs.slice(2));
2108
+ rawArgs = resolveBranchSwitches(rawArgs);
2297
2109
  if (extras.length > 0) {
2298
2110
  outError("");
2299
- outError(chalk.red(` ✗ Unexpected argument${extras.length > 1 ? "s" : ""}: ${extras.join(" ")}`));
2111
+ outError(chalk.red(` ✗ Unexpected argument${extras.length > 1 ? "s" : ""}: ${redactConnectionPasswords(extras.join(" "))}`));
2300
2112
  outError("");
2301
2113
  outError(chalk.gray(` ${chalk.bold("rebase db branch")} takes one name. A branch name may contain letters,`));
2302
2114
  outError(chalk.gray(" digits, underscores and hyphens — no spaces."));
2303
- if (rawArgs[3]) outError(chalk.gray(` Did you mean: ${chalk.cyan(`rebase db branch ${branchAction} ${[rawArgs[3], ...extras].join("-")}`)}`));
2115
+ if (rawArgs[3]) outError(chalk.gray(` Did you mean: ${chalk.cyan(redactConnectionPasswords(`rebase db branch ${branchAction} ${[rawArgs[3], ...extras].join("-")}`))}`));
2304
2116
  outError("");
2305
2117
  process.exit(1);
2306
2118
  }
@@ -2318,8 +2130,8 @@ async function branchCommand(rawArgs) {
2318
2130
  outError(chalk.red("✗ DATABASE_URL is not set. Make sure your .env file is configured."));
2319
2131
  process.exit(1);
2320
2132
  }
2321
- const { DatabasePoolManager } = await import("./databasePoolManager-Yqdw14wY.js").then((n) => n.n);
2322
- const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-iXXZeVYD.js").then((n) => n.n);
2133
+ const { DatabasePoolManager } = await import("./databasePoolManager-3stMNFL-.js").then((n) => n.n);
2134
+ const { BranchService, reopenClosedDatabases, reopenedDatabasesNotice } = await import("./BranchService-CWBnDhcv.js").then((n) => n.n);
2323
2135
  const { drizzle } = await import("drizzle-orm/node-postgres");
2324
2136
  const { Pool } = await import("pg");
2325
2137
  const healed = await reopenClosedDatabases(databaseUrl, [branchAction === "create" ? createSource(rawArgs) : void 0, process.env[ACTIVE_BRANCH_DATABASE_ENV]]);
@@ -2417,6 +2229,41 @@ async function branchCommand(rawArgs) {
2417
2229
  out("");
2418
2230
  break;
2419
2231
  }
2232
+ case "diff": {
2233
+ const name = rawArgs[3];
2234
+ if (!name || name.startsWith("-")) {
2235
+ outError(chalk.red("✗ Branch name is required."));
2236
+ out(chalk.gray(" Usage: rebase db branch diff <name> [--json] [--sample-limit <n>]"));
2237
+ process.exit(1);
2238
+ }
2239
+ const parsed = (0, import_arg.default)(BRANCH_FLAGS, {
2240
+ argv: rawArgs.slice(4),
2241
+ permissive: true
2242
+ });
2243
+ const { diffDatabaseBranch } = await import("./branch-diff-CxE4VlxT.js").then((n) => n.r);
2244
+ const { branchDiffReport } = await import("./branch-diff-report-DpvVf7hR.js");
2245
+ const admin = {
2246
+ executeSql: async (text, options) => (await poolManager.getPool(options?.database ?? poolManager.defaultDatabaseName).query(text, options?.params)).rows,
2247
+ createBranch: (branchName, options) => branchService.createBranch(branchName, options),
2248
+ deleteBranch: (branchName) => branchService.deleteBranch(branchName),
2249
+ listBranches: () => branchService.listBranches(),
2250
+ getBranchInfo: async (branchName) => await branchService.hasBranchRegistry() ? branchService.getBranchInfo(branchName) : void 0
2251
+ };
2252
+ let diff;
2253
+ try {
2254
+ diff = await diffDatabaseBranch(admin, name, { sampleLimit: parsed["--sample-limit"] });
2255
+ } catch (error) {
2256
+ outError(chalk.red(` ✗ ${error instanceof Error ? error.message : String(error)}`));
2257
+ process.exit(1);
2258
+ }
2259
+ if (parsed["--json"] === true) out(JSON.stringify(diff, null, 2));
2260
+ else {
2261
+ out("");
2262
+ for (const line of branchDiffReport(diff)) out(` ${line}`);
2263
+ out("");
2264
+ }
2265
+ break;
2266
+ }
2420
2267
  case "prune": {
2421
2268
  const parsed = (0, import_arg.default)(BRANCH_FLAGS, {
2422
2269
  argv: rawArgs.slice(3),
@@ -2522,6 +2369,7 @@ ${chalk.green.bold("Commands")}
2522
2369
  ${chalk.blue.bold("switch")} [<name>|--off] Point this checkout at a branch
2523
2370
  ${chalk.blue.bold("delete")} <name> Delete a branch
2524
2371
  ${chalk.blue.bold("info")} <name> Show branch details
2372
+ ${chalk.blue.bold("diff")} <name> [--json] What the branch changed: schema, policies, rows
2525
2373
  ${chalk.blue.bold("prune")} [--older-than <14|14d|2w>] Remove branches nothing is using
2526
2374
 
2527
2375
  ${chalk.green.bold("Why prune")}
@@ -2535,6 +2383,8 @@ ${chalk.green.bold("Options")}
2535
2383
  Postgres refuses to copy or drop a database
2536
2384
  anything else is connected to — usually your
2537
2385
  own \`rebase dev\`.
2386
+ ${chalk.blue.bold("--json")} diff: print the whole diff as JSON, with up
2387
+ to --sample-limit rows a table (default 100).
2538
2388
  ${chalk.blue.bold("--include-dev-diff")} Also prune the Atlas scratch databases
2539
2389
  \`db push\` leaves behind.
2540
2390
  ${chalk.blue.bold("--yes, -y")} Skip prune's confirmation prompt. Dropping a
@@ -2828,9 +2678,9 @@ async function schemaStaleCommand(rawArgs) {
2828
2678
  const schemaFile = path.resolve(process.cwd(), outputPath);
2829
2679
  const fix = Boolean(argsList["--fix"]);
2830
2680
  const generatedExists = fs.existsSync(schemaFile);
2831
- const { loadCollections } = await import("./doctor-DvJH-IQG.js").then((n) => n.t);
2832
- const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-FlxM2i4i.js").then((n) => n.r);
2833
- const { generateSchema } = await import("./generate-drizzle-schema-logic-DA3zM8zc.js").then((n) => n.n);
2681
+ const { loadCollections } = await import("./doctor-DW_mlTzz.js").then((n) => n.t);
2682
+ const { findLegacyForeignKeyNames, compareGeneratedDeclarations, staleVerdict } = await import("./generated-schema-staleness-BvNF3i-s.js").then((n) => n.r);
2683
+ const { generateSchema } = await import("./generate-drizzle-schema-logic-CPzCRD-8.js").then((n) => n.n);
2834
2684
  const { relationalCollections } = await import("@rebasepro/common");
2835
2685
  let stale = [];
2836
2686
  let differences = [];