@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
@@ -17,6 +17,24 @@ export { resolvePgBinary };
17
17
  export declare function detectToolMajor(bin: string): Promise<number | null>;
18
18
  /** Query the server for its major version via `server_version_num`. */
19
19
  export declare function getServerVersionMajor(connectionString: string): Promise<number | null>;
20
+ /**
21
+ * Put back what a client tool left set on a database that is one session
22
+ * every connection shares, and do nothing on any other.
23
+ *
24
+ * The managed development database is PGlite: one session behind a socket
25
+ * server, so what `pg_dump` sets for itself — `search_path` emptied,
26
+ * `row_security` off, `PREPARE dumpEnumType …` — stays set for every client
27
+ * after it, a running `rebase dev` included. One `rebase db backup` there left
28
+ * every API request answering 500 "table does not exist", a restart did not
29
+ * help (the database outlives `rebase dev`), and the next backup failed on
30
+ * `prepared statement "dumpenumtype" already exists`.
31
+ *
32
+ * `RESET ALL` and `DEALLOCATE ALL`, not `DISCARD ALL`: that would also drop
33
+ * the `LISTEN` a running `rebase dev`'s realtime holds on the same session.
34
+ * Best effort: it runs after the tool, whose own outcome is what the caller
35
+ * reports.
36
+ */
37
+ export declare function resetSharedSession(connectionString: string): Promise<void>;
20
38
  export interface PreflightResult extends VersionCompatibility {
21
39
  bin: string;
22
40
  toolMajor: number | null;
@@ -114,8 +132,69 @@ export declare function restoreDump(opts: {
114
132
  inheritStdio?: boolean;
115
133
  env?: Record<string, string | undefined>;
116
134
  }): Promise<void>;
135
+ /**
136
+ * A `restore --clean` that stopped, and so was rolled back whole.
137
+ *
138
+ * `tool` is the one that stopped it: `pg_restore`, writing the dump's script,
139
+ * or `psql`, running it. `lockTimeout` when what `psql` stopped on was the
140
+ * wait for a lock — `CLEAN_LOCK_TIMEOUT` in `pg-tools.ts`.
141
+ */
142
+ export declare class CleanRestoreFailed extends Error {
143
+ readonly tool: "pg_restore" | "psql";
144
+ readonly exitCode: number | undefined;
145
+ readonly lockTimeout: boolean;
146
+ constructor(tool: "pg_restore" | "psql", exitCode: number | undefined, lockTimeout: boolean);
147
+ }
148
+ /**
149
+ * Restore a dump over what the database holds, as one transaction:
150
+ * {@link cleanRestorePrelude} first, then the dump as `pg_restore` writes it
151
+ * for `psql`, and the `COMMIT` only after the last of it.
152
+ *
153
+ * One unit, so it either replaces what the dump holds or changes nothing:
154
+ * `pg_restore --clean` runs each statement on its own, so the drops it starts
155
+ * with had all happened when a later one failed — and its plain `DROP SCHEMA
156
+ * rebase` fails on any table the backup lacks, which left a database with
157
+ * every table dropped and nothing restored. Here a failure anywhere —
158
+ * `pg_restore` cannot read the archive, a statement fails, the connection
159
+ * drops — ends the transaction without a `COMMIT`, and Postgres rolls it back.
160
+ *
161
+ * Throws {@link CleanRestoreFailed} when it did not commit.
162
+ */
163
+ export declare function restoreDumpReplacing(opts: {
164
+ connectionString: string;
165
+ inputFile: string;
166
+ objects: DumpObjects;
167
+ noOwner?: boolean;
168
+ inheritStdio?: boolean;
169
+ env?: Record<string, string | undefined>;
170
+ }): Promise<void>;
171
+ /**
172
+ * What `restore --clean` drops that the backup does not hold, so it can say
173
+ * so before it runs: what a schema the backup replaces whole holds that it has
174
+ * no copy of — tables, views, sequences, functions, procedures, aggregates,
175
+ * types and domains — and the views and foreign keys elsewhere that reference
176
+ * one of the relations it replaces. As `<kind> <name>`.
177
+ *
178
+ * A function is matched by its name, so an overload the backup lacks beside
179
+ * one it holds is not named. Sequences a column owns go with their table,
180
+ * and what an extension owns with the extension, so neither is named.
181
+ *
182
+ * None for a database that does not exist yet.
183
+ */
184
+ export declare function findCleanExtras(connectionString: string, objects: DumpObjects): Promise<string[]>;
117
185
  /** The schemas and tables a dump creates, from `pg_restore --list`. See {@link parseDumpObjects}. */
118
186
  export declare function readDumpObjects(inputFile: string, env?: Record<string, string | undefined>): Promise<DumpObjects>;
187
+ /**
188
+ * What `db restore` says of a file whose table of contents pg_restore cannot
189
+ * read: before anything is restored, so nothing has changed.
190
+ *
191
+ * `pgRestoreStderr` is what `pg_restore --list` printed. Its first error line
192
+ * is quoted, so the reader sees the tool's own words too.
193
+ */
194
+ export declare function describeUnreadableDump(file: string, pgRestoreStderr: string): {
195
+ message: string;
196
+ hint: string;
197
+ };
119
198
  /**
120
199
  * Which of a dump's schemas and tables the target database already holds,
121
200
  * as `schema <name>` / `table <schema>.<name>`: what a restore without
@@ -1,5 +1,5 @@
1
- export type PgTool = "pg_dump" | "pg_restore" | "pg_dumpall";
1
+ export type PgTool = "pg_dump" | "pg_restore" | "pg_dumpall" | "psql";
2
2
  /** The variable that points at `tool` when it is not on the PATH. */
3
3
  export declare function pgToolVariable(tool: PgTool): string;
4
- /** Locate `pg_dump` / `pg_restore` / `pg_dumpall`, honouring an env override. */
4
+ /** Locate `pg_dump` / `pg_restore` / `pg_dumpall` / `psql`, honouring an env override. */
5
5
  export declare function resolvePgBinary(tool: PgTool, env?: Record<string, string | undefined>): string | null;
@@ -168,6 +168,25 @@ export interface DumpObjects {
168
168
  schema: string;
169
169
  table: string;
170
170
  }[];
171
+ /**
172
+ * Every relation it creates — tables, views, materialized views, foreign
173
+ * tables and sequences — by schema and name: what `restore --clean` can
174
+ * tell apart from what the target holds besides.
175
+ */
176
+ relations: {
177
+ schema: string;
178
+ name: string;
179
+ }[];
180
+ /** Every function, procedure and aggregate it creates, by schema and name: an overloaded name once for each. */
181
+ routines: {
182
+ schema: string;
183
+ name: string;
184
+ }[];
185
+ /** Every type it creates — enum, composite, range — and every domain, by schema and name. */
186
+ types: {
187
+ schema: string;
188
+ name: string;
189
+ }[];
171
190
  }
172
191
  /**
173
192
  * The schemas and tables in `pg_restore --list` output: the objects a
@@ -176,9 +195,49 @@ export interface DumpObjects {
176
195
  * A TOC line ends in the object's owner, after its namespace and its name;
177
196
  * a schema's namespace is `-`. The name is what lies between the two, so a
178
197
  * name with a space in it (`Odd Name`) reads whole. `TABLE DATA` and every
179
- * other kind of entry are not objects of their own here.
198
+ * other kind of entry are not objects of their own here. Its relations,
199
+ * functions and types are read too, for what `restore --clean` would drop
200
+ * that the dump does not hold (`findCleanExtras`).
180
201
  */
181
202
  export declare function parseDumpObjects(list: string): DumpObjects;
203
+ /**
204
+ * How long `restore --clean` waits for a lock before it gives up.
205
+ *
206
+ * A `rebase dev` serving from the database holds connections, and one inside a
207
+ * transaction would otherwise make the restore wait without a word. The dump's
208
+ * own script sets `lock_timeout = 0` after this, for the objects it creates.
209
+ */
210
+ export declare const CLEAN_LOCK_TIMEOUT = "15s";
211
+ /**
212
+ * What `restore --clean` runs first, in the transaction the restore runs in:
213
+ * every schema the dump creates, dropped with `CASCADE`, and every table it
214
+ * creates in a schema it does not (`public`), the same.
215
+ *
216
+ * `CASCADE`, which `pg_restore --clean` never uses: a table the backup lacks
217
+ * in one of its schemas — `rebase.atlas_schema_revisions` from `rebase db
218
+ * migrate`, a table a newer runtime added — is exactly what stopped its plain
219
+ * `DROP SCHEMA rebase`, and a table that references one of the backup's is what
220
+ * stops a plain `DROP TABLE`. The dump's script follows, with its own `DROP …
221
+ * IF EXISTS` for everything else it creates.
222
+ */
223
+ export declare function cleanRestorePrelude(objects: DumpObjects): string[];
224
+ /**
225
+ * `pg_restore` writing the dump as a SQL script on stdout, with the `DROP …
226
+ * IF EXISTS` that `--clean` adds, for `psql` to run. See {@link buildPsqlScriptArgs}.
227
+ */
228
+ export declare function buildPgRestoreScriptArgs(opts: {
229
+ inputFile: string;
230
+ noOwner?: boolean;
231
+ }): string[];
232
+ /**
233
+ * `psql` running a script read from stdin, stopping at its first error.
234
+ *
235
+ * `-X`, so no `.psqlrc` changes what runs; `-q`, so it prints errors and
236
+ * warnings, not a command tag per statement. The transaction is the script's
237
+ * own: `restore --clean` writes the `BEGIN`, and the `COMMIT` only once
238
+ * `pg_restore` has written the whole dump.
239
+ */
240
+ export declare function buildPsqlScriptArgs(connectionString: string): string[];
182
241
  /**
183
242
  * Assemble the `pg_dumpall --globals-only` argument vector. Roles (and other
184
243
  * cluster-wide objects) live outside any single database, so a per-database