@rebasepro/cli 0.31.0-canary.g902a0ce → 0.32.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.
- package/dist/{agent-setup-DqAcoDcn.js → agent-setup-Cg_zBWoW.js} +3 -3
- package/dist/{agent-setup-DqAcoDcn.js.map → agent-setup-Cg_zBWoW.js.map} +1 -1
- package/dist/api-TbmW33D7.js +275 -0
- package/dist/api-TbmW33D7.js.map +1 -0
- package/dist/{api-keys-eIUjMqWn.js → api-keys-fPQ55DCm.js} +151 -158
- package/dist/api-keys-fPQ55DCm.js.map +1 -0
- package/dist/{apps-DExO4PEl.js → apps-DBTRoOeP.js} +18 -13
- package/dist/apps-DBTRoOeP.js.map +1 -0
- package/dist/{args-CaCcrYE1.js → args-DHyrshtI.js} +3 -132
- package/dist/args-DHyrshtI.js.map +1 -0
- package/dist/{atlas-dev-database-DOCKk6ht.js → atlas-dev-database-D6h65f2x.js} +3 -3
- package/dist/{atlas-dev-database-DOCKk6ht.js.map → atlas-dev-database-D6h65f2x.js.map} +1 -1
- package/dist/{auth-CyADghFQ.js → auth-BpyYLEFY.js} +93 -12
- package/dist/auth-BpyYLEFY.js.map +1 -0
- package/dist/auth-session-B6aT0Dyj.js +371 -0
- package/dist/auth-session-B6aT0Dyj.js.map +1 -0
- package/dist/{backend-guard-C0mVkXBw.js → backend-guard-Cf8eMK_f.js} +2 -2
- package/dist/{backend-guard-C0mVkXBw.js.map → backend-guard-Cf8eMK_f.js.map} +1 -1
- package/dist/{branch-pointer-DMPyvZoK.js → branch-pointer-BJOF2Ubv.js} +1 -1
- package/dist/{build-CA5R07tw.js → build-BfdT-AUR.js} +12 -10
- package/dist/{build-CA5R07tw.js.map → build-BfdT-AUR.js.map} +1 -1
- package/dist/{bundle-DgILeA5b.js → bundle-CIiKGrte.js} +78 -12
- package/dist/bundle-CIiKGrte.js.map +1 -0
- package/dist/bundle.d.ts +31 -1
- package/dist/{cloud-CYMk92iG.js → cloud-MqnyPnmX.js} +1540 -1531
- package/dist/cloud-MqnyPnmX.js.map +1 -0
- package/dist/{cms-directories-BK3vcswg.js → cms-directories-BaV-Is9a.js} +2 -2
- package/dist/{cms-directories-BK3vcswg.js.map → cms-directories-BaV-Is9a.js.map} +1 -1
- package/dist/codemod/collections-to-tables/backend.d.ts +0 -2
- package/dist/codemod/collections-to-tables/customization.d.ts +2 -1
- package/dist/codemod/collections-to-tables/modules.d.ts +32 -0
- package/dist/codemod/collections-to-tables/plan-context.d.ts +7 -1
- package/dist/{command-D5lhW_-B.js → command-D9g46gg9.js} +68 -42
- package/dist/command-D9g46gg9.js.map +1 -0
- package/dist/commands/api-keys.d.ts +89 -52
- package/dist/commands/api.d.ts +114 -0
- package/dist/commands/auth-session.d.ts +94 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/cloud/alerts.d.ts +29 -0
- package/dist/commands/cloud/context.d.ts +8 -0
- package/dist/commands/cloud/debug.d.ts +16 -1
- package/dist/commands/cloud/deploy-hooks.d.ts +19 -0
- package/dist/commands/cloud/deploy.d.ts +25 -0
- package/dist/commands/cloud/env.d.ts +1 -0
- package/dist/commands/cloud/index.d.ts +5 -0
- package/dist/commands/cloud/maintenance.d.ts +26 -1
- package/dist/commands/cloud/not-served.d.ts +27 -0
- package/dist/commands/cloud/orgs.d.ts +5 -0
- package/dist/commands/cloud/resources.d.ts +82 -2
- package/dist/commands/cloud/runtime-logs.d.ts +57 -0
- package/dist/commands/cloud/settings.d.ts +3 -0
- package/dist/commands/cron.d.ts +68 -0
- package/dist/commands/data.d.ts +197 -0
- package/dist/commands/functions.d.ts +38 -0
- package/dist/commands/logs.d.ts +22 -0
- package/dist/commands/rls.d.ts +31 -0
- package/dist/commands/schema-reconcile.d.ts +2 -1
- package/dist/commands/schema-show.d.ts +38 -0
- package/dist/commands/storage-objects.d.ts +88 -0
- package/dist/commands/storage.d.ts +18 -2
- package/dist/commands/users.d.ts +147 -0
- package/dist/{consent-BXLIrMl8.js → consent-UV6ObCME.js} +2 -2
- package/dist/{consent-BXLIrMl8.js.map → consent-UV6ObCME.js.map} +1 -1
- package/dist/{console-CMjhgMUE.js → console-BVoYOLAO.js} +6 -6
- package/dist/{console-CMjhgMUE.js.map → console-BVoYOLAO.js.map} +1 -1
- package/dist/{context--JwaHaZp.js → context-BOMEoKxn.js} +80 -9
- package/dist/{context--JwaHaZp.js.map → context-BOMEoKxn.js.map} +1 -1
- package/dist/cron-CpUsQ739.js +298 -0
- package/dist/cron-CpUsQ739.js.map +1 -0
- package/dist/cron-ZRXsla0v.js +259 -0
- package/dist/cron-ZRXsla0v.js.map +1 -0
- package/dist/{daemon-w30PsdwV.js → daemon-D5gdG7gx.js} +3 -3
- package/dist/{daemon-w30PsdwV.js.map → daemon-D5gdG7gx.js.map} +1 -1
- package/dist/{daemon-entry-zOC1revO.js → daemon-entry--ummUJnk.js} +2 -2
- package/dist/{daemon-entry-zOC1revO.js.map → daemon-entry--ummUJnk.js.map} +1 -1
- package/dist/data-BJ9AZFUC.js +947 -0
- package/dist/data-BJ9AZFUC.js.map +1 -0
- package/dist/{db-A7XDCIIO.js → db-D_iF4E-v.js} +60 -36
- package/dist/db-D_iF4E-v.js.map +1 -0
- package/dist/debug-nNbbxAeo.js +1114 -0
- package/dist/debug-nNbbxAeo.js.map +1 -0
- package/dist/{derive-C3ezmY-p.js → derive-Mky_u59_.js} +3 -3
- package/dist/{derive-C3ezmY-p.js.map → derive-Mky_u59_.js.map} +1 -1
- package/dist/{dev-tWwPyWkQ.js → dev-bj6dEeSQ.js} +13 -13
- package/dist/{dev-tWwPyWkQ.js.map → dev-bj6dEeSQ.js.map} +1 -1
- package/dist/dev-db/__fixtures__/unanswering-postgres.d.ts +11 -0
- package/dist/dev-db/attver.d.ts +38 -6
- package/dist/dev-db/local-timeouts.d.ts +25 -0
- package/dist/dev-db/pull.d.ts +49 -9
- package/dist/{dev-preflight-DjvcV6SK.js → dev-preflight-BMOf2N6r.js} +2 -2
- package/dist/{dev-preflight-DjvcV6SK.js.map → dev-preflight-BMOf2N6r.js.map} +1 -1
- package/dist/{dev-server-BLxCbQEP.js → dev-server-2XHSHM_q.js} +2 -2
- package/dist/{dev-server-BLxCbQEP.js.map → dev-server-2XHSHM_q.js.map} +1 -1
- package/dist/{doctor-BBM0dWvZ.js → doctor-2Jlau0Rm.js} +9 -8
- package/dist/{doctor-BBM0dWvZ.js.map → doctor-2Jlau0Rm.js.map} +1 -1
- package/dist/{eject-Bhzd6hgb.js → eject-DK_M9kor.js} +4 -4
- package/dist/{eject-Bhzd6hgb.js.map → eject-DK_M9kor.js.map} +1 -1
- package/dist/{fold-static-CKewnAPX.js → fold-static-2t3UUX4z.js} +10 -6
- package/dist/fold-static-2t3UUX4z.js.map +1 -0
- package/dist/fold-static.d.ts +7 -0
- package/dist/functions-B4JR6EZL.js +120 -0
- package/dist/functions-B4JR6EZL.js.map +1 -0
- package/dist/{generate-view-CTOluXvH.js → generate-view-BMaLQm8H.js} +5 -5
- package/dist/{generate-view-CTOluXvH.js.map → generate-view-BMaLQm8H.js.map} +1 -1
- package/dist/{generate_sdk-De-aLC1L.js → generate_sdk-ByD-gTsK.js} +7 -7
- package/dist/{generate_sdk-De-aLC1L.js.map → generate_sdk-ByD-gTsK.js.map} +1 -1
- package/dist/index.es.js +123 -47
- package/dist/index.es.js.map +1 -1
- package/dist/{init-Dtl-IcXf.js → init-DHCe5mJ5.js} +59 -11
- package/dist/init-DHCe5mJ5.js.map +1 -0
- package/dist/{invoked-command-CG_rIa_o.js → invoked-command-FBeIBS8o.js} +2 -2
- package/dist/{invoked-command-CG_rIa_o.js.map → invoked-command-FBeIBS8o.js.map} +1 -1
- package/dist/last-dev-database-CBVkEUEl.js +2 -0
- package/dist/local-timeouts-B1Kwligw.js +30 -0
- package/dist/local-timeouts-B1Kwligw.js.map +1 -0
- package/dist/logs-CIgfLBsu.js +192 -0
- package/dist/logs-CIgfLBsu.js.map +1 -0
- package/dist/{manifest-C3uLDrrJ.js → manifest-RjqxfCpb.js} +114 -5
- package/dist/manifest-RjqxfCpb.js.map +1 -0
- package/dist/{migrate-VrKoi3nB.js → migrate-Cx8-Y4TG.js} +5 -4
- package/dist/{migrate-VrKoi3nB.js.map → migrate-Cx8-Y4TG.js.map} +1 -1
- package/dist/{normalize-imports-DwxqEMYq.js → normalize-imports-P86NVfpo.js} +3 -3
- package/dist/{normalize-imports-DwxqEMYq.js.map → normalize-imports-P86NVfpo.js.map} +1 -1
- package/dist/{path-flags-7O5uPBcQ.js → path-flags-ekLdkbra.js} +3 -3
- package/dist/{path-flags-7O5uPBcQ.js.map → path-flags-ekLdkbra.js.map} +1 -1
- package/dist/{prepare-Ccxspoj-.js → prepare-BaJe0Zik.js} +4 -4
- package/dist/{prepare-Ccxspoj-.js.map → prepare-BaJe0Zik.js.map} +1 -1
- package/dist/{project-CLcF5i8c.js → project-DALmhb5R.js} +2 -2
- package/dist/{project-CLcF5i8c.js.map → project-DALmhb5R.js.map} +1 -1
- package/dist/project-command-Cl9EZzjr.js +662 -0
- package/dist/project-command-Cl9EZzjr.js.map +1 -0
- package/dist/{project-schema-CsSOG2gE.js → project-schema-Dm6Jk0Y_.js} +4 -2
- package/dist/{project-schema-CsSOG2gE.js.map → project-schema-Dm6Jk0Y_.js.map} +1 -1
- package/dist/{pull-D9WvpDYY.js → pull-CTIsST6T.js} +336 -55
- package/dist/pull-CTIsST6T.js.map +1 -0
- package/dist/resolve-C36px9tR.js +2 -0
- package/dist/{resources-Dpfs2y8P.js → resources-Db3USuPO.js} +5 -5
- package/dist/{resources-Dpfs2y8P.js.map → resources-Db3USuPO.js.map} +1 -1
- package/dist/rls-BxrQ0P50.js +133 -0
- package/dist/rls-BxrQ0P50.js.map +1 -0
- package/dist/{schema-DwFDI1iU.js → schema-_FzZEoB8.js} +54 -40
- package/dist/schema-_FzZEoB8.js.map +1 -0
- package/dist/{schema-dir-Cd1kvYbf.js → schema-dir-ChcYfWjP.js} +2 -2
- package/dist/{schema-dir-Cd1kvYbf.js.map → schema-dir-ChcYfWjP.js.map} +1 -1
- package/dist/schema-reconcile-DV14XY4o.js +2 -0
- package/dist/schema-show-h72UJ9zH.js +127 -0
- package/dist/schema-show-h72UJ9zH.js.map +1 -0
- package/dist/{skills-CXjA9TWw.js → skills-DQ2bZGkj.js} +6 -5
- package/dist/{skills-CXjA9TWw.js.map → skills-DQ2bZGkj.js.map} +1 -1
- package/dist/star-nudge.d.ts +28 -0
- package/dist/{start-Bwbtt2W5.js → start-Cjx4W0bJ.js} +7 -7
- package/dist/{start-Bwbtt2W5.js.map → start-Cjx4W0bJ.js.map} +1 -1
- package/dist/{status-DQ_PPz4C.js → status-CDBk25VO.js} +9 -9
- package/dist/{status-DQ_PPz4C.js.map → status-CDBk25VO.js.map} +1 -1
- package/dist/{storage-iTqj5-Av.js → storage-Clc8dLG8.js} +79 -36
- package/dist/storage-Clc8dLG8.js.map +1 -0
- package/dist/storage-objects-CfRKlTDe.js +279 -0
- package/dist/storage-objects-CfRKlTDe.js.map +1 -0
- package/dist/{telemetry-BP_1Cl9r.js → telemetry-DZU2-NCm.js} +5 -4
- package/dist/{telemetry-BP_1Cl9r.js.map → telemetry-DZU2-NCm.js.map} +1 -1
- package/dist/{telemetry-M3HjlyhZ.js → telemetry-EVtASbKb.js} +2 -2
- package/dist/{telemetry-M3HjlyhZ.js.map → telemetry-EVtASbKb.js.map} +1 -1
- package/dist/unknown-command-DnZ2uhGs.js +139 -0
- package/dist/unknown-command-DnZ2uhGs.js.map +1 -0
- package/dist/{upgrade-oZzJ13jM.js → upgrade-DhpUFb6p.js} +5 -5
- package/dist/{upgrade-oZzJ13jM.js.map → upgrade-DhpUFb6p.js.map} +1 -1
- package/dist/users-5PkqBY6R.js +561 -0
- package/dist/users-5PkqBY6R.js.map +1 -0
- package/dist/utils/project-command.d.ts +38 -0
- package/dist/utils/project-target.d.ts +193 -0
- package/dist/{verify-DkJqhYPI.js → verify-BdeqNb-V.js} +138 -12
- package/dist/verify-BdeqNb-V.js.map +1 -0
- package/dist/{version-Buyyo1ut.js → version-ONIeo7jl.js} +7 -2
- package/dist/{version-Buyyo1ut.js.map → version-ONIeo7jl.js.map} +1 -1
- package/package.json +10 -10
- package/dist/api-keys-eIUjMqWn.js.map +0 -1
- package/dist/apps-DExO4PEl.js.map +0 -1
- package/dist/args-CaCcrYE1.js.map +0 -1
- package/dist/auth-CyADghFQ.js.map +0 -1
- package/dist/bundle-DgILeA5b.js.map +0 -1
- package/dist/cloud-CYMk92iG.js.map +0 -1
- package/dist/command-D5lhW_-B.js.map +0 -1
- package/dist/db-A7XDCIIO.js.map +0 -1
- package/dist/fold-static-CKewnAPX.js.map +0 -1
- package/dist/init-Dtl-IcXf.js.map +0 -1
- package/dist/last-dev-database-Dc8cP01o.js +0 -2
- package/dist/manifest-C3uLDrrJ.js.map +0 -1
- package/dist/pull-D9WvpDYY.js.map +0 -1
- package/dist/resolve-BY7bSFRT.js +0 -2
- package/dist/schema-DwFDI1iU.js.map +0 -1
- package/dist/schema-reconcile-Tto54Qbv.js +0 -2
- package/dist/storage-iTqj5-Av.js.map +0 -1
- package/dist/verify-DkJqhYPI.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { r as PGLITE_EXTENSIONS } from "./constraints-CtiylsGf.js";
|
|
2
|
+
import { n as LOCAL_QUERY_TIMEOUT_MS, t as LOCAL_CONNECT_TIMEOUT_MS } from "./local-timeouts-B1Kwligw.js";
|
|
2
3
|
import { i as hostOf, n as connectionErrorText, t as banner } from "./connection-banner-DbLJzWf4.js";
|
|
3
4
|
import fs from "fs";
|
|
4
5
|
import { execa } from "execa";
|
|
@@ -28,24 +29,93 @@ import { execa } from "execa";
|
|
|
28
29
|
* overwritten with spaces — the whole statement when it is the only option,
|
|
29
30
|
* the key and its comma when there are others. Byte for byte the same length,
|
|
30
31
|
* because the TOC records the file offset of every data block after it.
|
|
32
|
+
*
|
|
33
|
+
* The definitions are edited as bytes, never decoded: pg_dump writes them in
|
|
34
|
+
* the database's encoding, which need not be UTF-8. Every encoding a server
|
|
35
|
+
* can store is ASCII-safe — a byte below 0x80 is always that ASCII character —
|
|
36
|
+
* so the ASCII statement is found by reading one character per byte, and the
|
|
37
|
+
* bytes around it are written back exactly as they were. The client-only
|
|
38
|
+
* encodings (SJIS, BIG5, GBK, UHC, GB18030, JOHAB, SHIFT_JIS_2004) are not
|
|
39
|
+
* ASCII-safe; a dump taken in one, through `PGCLIENTENCODING` or a
|
|
40
|
+
* `client_encoding` in the connection string, is left as it was.
|
|
41
|
+
*
|
|
42
|
+
* The same read of the TOC also answers which encoding a dump is written in
|
|
43
|
+
* ({@link archiveEncoding}). A pull into the managed database asks that before
|
|
44
|
+
* it empties anything.
|
|
31
45
|
*/
|
|
32
46
|
var ATTVER_ONLY = /^(ALTER (?:FOREIGN )?TABLE (?:ONLY )?.* ALTER COLUMN .* SET )\(pg_attver=\d+\);$/gm;
|
|
33
47
|
var ATTVER_FIRST = /(?<=^ALTER (?:FOREIGN )?TABLE (?:ONLY )?.* ALTER COLUMN .* SET \()pg_attver=\d+, (?=.*\);$)/gm;
|
|
34
48
|
var ATTVER_LATER = /(?<=^ALTER (?:FOREIGN )?TABLE (?:ONLY )?.* ALTER COLUMN .* SET \(.*), pg_attver=\d+(?=.*\);$)/gm;
|
|
35
49
|
function spaces(text) {
|
|
36
|
-
return " ".repeat(
|
|
50
|
+
return " ".repeat(text.length);
|
|
37
51
|
}
|
|
38
52
|
/**
|
|
39
|
-
* A TOC entry's definition
|
|
40
|
-
*
|
|
53
|
+
* A TOC entry's definition, as the bytes pg_dump wrote, without its
|
|
54
|
+
* `pg_attver` options: what was taken out is spaces, and every other byte is
|
|
55
|
+
* as it was. Matched one character per byte (`latin1`), which finds the ASCII
|
|
56
|
+
* statement in any ASCII-safe encoding without decoding anything else.
|
|
41
57
|
*/
|
|
42
58
|
function blankAttverOptions(definition) {
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
const text = definition.toString("latin1");
|
|
60
|
+
if (!text.includes("pg_attver=")) return definition;
|
|
61
|
+
const blanked = text.replace(ATTVER_ONLY, (statement) => spaces(statement)).replace(ATTVER_FIRST, (option) => spaces(option)).replace(ATTVER_LATER, (option) => spaces(option));
|
|
62
|
+
return blanked === text ? definition : Buffer.from(blanked, "latin1");
|
|
45
63
|
}
|
|
46
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* The entries whose definition can hold attribute options: pg_dump's
|
|
66
|
+
* `dumpTableSchema` writes `ALTER … ALTER COLUMN … SET (…)` for every relation
|
|
67
|
+
* but a view, under the entry it describes as one of these.
|
|
68
|
+
*/
|
|
69
|
+
var RELATION_ENTRIES = /* @__PURE__ */ new Set([
|
|
70
|
+
"TABLE",
|
|
71
|
+
"FOREIGN TABLE",
|
|
72
|
+
"MATERIALIZED VIEW"
|
|
73
|
+
]);
|
|
74
|
+
/**
|
|
75
|
+
* The encodings a server can store (`PG_SQL_ASCII` … `PG_KOI8U` in
|
|
76
|
+
* pg_wchar.h), named as `pg_encoding_to_char` names them in the ENCODING
|
|
77
|
+
* entry. Each is ASCII-safe; the client-only encodings after them are not.
|
|
78
|
+
*/
|
|
79
|
+
var ASCII_SAFE_ENCODINGS = /* @__PURE__ */ new Set([
|
|
80
|
+
"SQL_ASCII",
|
|
81
|
+
"EUC_JP",
|
|
82
|
+
"EUC_CN",
|
|
83
|
+
"EUC_KR",
|
|
84
|
+
"EUC_TW",
|
|
85
|
+
"EUC_JIS_2004",
|
|
86
|
+
"UTF8",
|
|
87
|
+
"MULE_INTERNAL",
|
|
88
|
+
"LATIN1",
|
|
89
|
+
"LATIN2",
|
|
90
|
+
"LATIN3",
|
|
91
|
+
"LATIN4",
|
|
92
|
+
"LATIN5",
|
|
93
|
+
"LATIN6",
|
|
94
|
+
"LATIN7",
|
|
95
|
+
"LATIN8",
|
|
96
|
+
"LATIN9",
|
|
97
|
+
"LATIN10",
|
|
98
|
+
"WIN1256",
|
|
99
|
+
"WIN1258",
|
|
100
|
+
"WIN866",
|
|
101
|
+
"WIN874",
|
|
102
|
+
"KOI8R",
|
|
103
|
+
"WIN1251",
|
|
104
|
+
"WIN1252",
|
|
105
|
+
"ISO_8859_5",
|
|
106
|
+
"ISO_8859_6",
|
|
107
|
+
"ISO_8859_7",
|
|
108
|
+
"ISO_8859_8",
|
|
109
|
+
"WIN1250",
|
|
110
|
+
"WIN1253",
|
|
111
|
+
"WIN1254",
|
|
112
|
+
"WIN1255",
|
|
113
|
+
"WIN1257",
|
|
114
|
+
"KOI8U"
|
|
115
|
+
]);
|
|
116
|
+
/** `K_VERS_1_12`…`K_VERS_MAX` (1.16 at any revision): the custom-format archives pg_dump 11 to 18 write. */
|
|
47
117
|
var OLDEST = archiveVersion(1, 12, 0);
|
|
48
|
-
var NEWEST = archiveVersion(1, 16,
|
|
118
|
+
var NEWEST = archiveVersion(1, 16, 255);
|
|
49
119
|
var V1_14 = archiveVersion(1, 14, 0);
|
|
50
120
|
var V1_15 = archiveVersion(1, 15, 0);
|
|
51
121
|
var V1_16 = archiveVersion(1, 16, 0);
|
|
@@ -90,15 +160,19 @@ var ArchiveReader = class {
|
|
|
90
160
|
for (let i = digits.length - 1; i >= 0; i--) value = value * 256 + (digits[i] ?? 0);
|
|
91
161
|
return negative ? -value : value;
|
|
92
162
|
}
|
|
93
|
-
/** `ReadStr`: a length, then that many bytes; a negative length is NULL. Returns
|
|
163
|
+
/** `ReadStr`: a length, then that many bytes; a negative length is NULL. Returns the bytes and where they are. */
|
|
94
164
|
str() {
|
|
95
165
|
const length = this.int();
|
|
96
166
|
if (length < 0) return null;
|
|
97
167
|
return {
|
|
98
168
|
at: this.position,
|
|
99
|
-
|
|
169
|
+
bytes: this.bytes(length)
|
|
100
170
|
};
|
|
101
171
|
}
|
|
172
|
+
/** `ReadStr` for a field that is ASCII in every dump: a tag, a description, a version. */
|
|
173
|
+
ascii() {
|
|
174
|
+
return this.str()?.bytes.toString("latin1") ?? null;
|
|
175
|
+
}
|
|
102
176
|
/** `ReadOffset`: a flag byte, then `offSize` bytes, least significant first. */
|
|
103
177
|
offset() {
|
|
104
178
|
const flag = this.byte();
|
|
@@ -111,33 +185,47 @@ var ArchiveReader = class {
|
|
|
111
185
|
};
|
|
112
186
|
}
|
|
113
187
|
};
|
|
114
|
-
|
|
115
|
-
|
|
188
|
+
var NOT_AN_ARCHIVE = "it is not a pg_dump custom-format archive this can read";
|
|
189
|
+
/** The edits that blank `pg_attver` in an archive's TOC, or why there are none to make safely. */
|
|
190
|
+
function planPatches(fd, size, blank) {
|
|
116
191
|
const reader = new ArchiveReader(fd, size);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
192
|
+
let serverVersion = null;
|
|
193
|
+
let dumpVersion = null;
|
|
194
|
+
let encoding = null;
|
|
195
|
+
const refuse = (reason) => ({
|
|
196
|
+
ok: false,
|
|
197
|
+
reason,
|
|
198
|
+
serverVersion,
|
|
199
|
+
dumpVersion,
|
|
200
|
+
encoding
|
|
201
|
+
});
|
|
202
|
+
if (reader.bytes(5).toString("latin1") !== "PGDMP") return refuse(NOT_AN_ARCHIVE);
|
|
203
|
+
const major = reader.byte();
|
|
204
|
+
const minor = reader.byte();
|
|
205
|
+
const revision = reader.byte();
|
|
206
|
+
const version = archiveVersion(major, minor, revision);
|
|
207
|
+
if (version < OLDEST || version > NEWEST) return refuse(`its archive format is version ${major}.${minor}.${revision}, which this version of Rebase does not read`);
|
|
120
208
|
reader.intSize = reader.byte();
|
|
121
209
|
reader.offSize = reader.byte();
|
|
122
|
-
if (reader.intSize < 1 || reader.intSize > 8 || reader.offSize < 1 || reader.offSize > 8) return
|
|
123
|
-
if (reader.byte() !== CUSTOM_FORMAT) return
|
|
210
|
+
if (reader.intSize < 1 || reader.intSize > 8 || reader.offSize < 1 || reader.offSize > 8) return refuse(NOT_AN_ARCHIVE);
|
|
211
|
+
if (reader.byte() !== CUSTOM_FORMAT) return refuse(NOT_AN_ARCHIVE);
|
|
124
212
|
if (version >= V1_15) reader.byte();
|
|
125
213
|
else reader.int();
|
|
126
214
|
for (let i = 0; i < 7; i++) reader.int();
|
|
127
215
|
reader.str();
|
|
128
|
-
reader.
|
|
129
|
-
reader.
|
|
216
|
+
serverVersion = reader.ascii();
|
|
217
|
+
dumpVersion = reader.ascii();
|
|
130
218
|
const patches = [];
|
|
131
219
|
let firstData = Number.POSITIVE_INFINITY;
|
|
132
220
|
const entries = reader.int();
|
|
133
|
-
if (entries < 0) return
|
|
221
|
+
if (entries < 0) return refuse(NOT_AN_ARCHIVE);
|
|
134
222
|
for (let i = 0; i < entries; i++) {
|
|
135
223
|
reader.int();
|
|
136
224
|
reader.int();
|
|
137
225
|
reader.str();
|
|
138
226
|
reader.str();
|
|
139
227
|
reader.str();
|
|
140
|
-
reader.
|
|
228
|
+
const desc = reader.ascii();
|
|
141
229
|
reader.int();
|
|
142
230
|
const definition = reader.str();
|
|
143
231
|
reader.str();
|
|
@@ -151,39 +239,93 @@ function planPatches(fd, size) {
|
|
|
151
239
|
while (reader.str() !== null);
|
|
152
240
|
const data = reader.offset();
|
|
153
241
|
if (data.set) firstData = Math.min(firstData, data.value);
|
|
154
|
-
if (definition)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
242
|
+
if (!definition) continue;
|
|
243
|
+
if (desc === "ENCODING") encoding = /client_encoding = '([^']*)'/.exec(definition.bytes.toString("latin1"))?.[1] ?? null;
|
|
244
|
+
else if (desc !== null && RELATION_ENTRIES.has(desc)) {
|
|
245
|
+
const blanked = blank(definition.bytes);
|
|
246
|
+
if (blanked.equals(definition.bytes)) continue;
|
|
247
|
+
if (blanked.length !== definition.bytes.length) return refuse(`taking pg_attver out of one of its entries would have changed that entry's length (${definition.bytes.length} bytes to ${blanked.length})`);
|
|
248
|
+
patches.push({
|
|
249
|
+
at: definition.at,
|
|
250
|
+
bytes: blanked
|
|
251
|
+
});
|
|
164
252
|
}
|
|
165
253
|
}
|
|
166
|
-
if (reader.position > firstData) return
|
|
167
|
-
return
|
|
254
|
+
if (reader.position > firstData) return refuse(NOT_AN_ARCHIVE);
|
|
255
|
+
if (patches.length > 0 && (encoding === null || !ASCII_SAFE_ENCODINGS.has(encoding))) return refuse(encoding === null ? "it does not say which encoding it is written in" : `it is written in the ${encoding} encoding, which this cannot edit safely; dump in the database's own encoding instead (unset PGCLIENTENCODING)`);
|
|
256
|
+
return {
|
|
257
|
+
ok: true,
|
|
258
|
+
patches,
|
|
259
|
+
serverVersion,
|
|
260
|
+
dumpVersion,
|
|
261
|
+
encoding
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** Reads every definition as it is: what {@link archiveEncoding} walks the TOC with. */
|
|
265
|
+
function unchanged(definition) {
|
|
266
|
+
return definition;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* The encoding a custom-format dump is written in, as its ENCODING entry
|
|
270
|
+
* names it (`LATIN1`, `UTF8`, …), or null when this cannot read the file as
|
|
271
|
+
* an archive.
|
|
272
|
+
*
|
|
273
|
+
* That entry is the `SET client_encoding` pg_restore starts every restore
|
|
274
|
+
* with: the source database's encoding, unless pg_dump ran with
|
|
275
|
+
* `PGCLIENTENCODING` naming another. The file is opened read-only and nothing
|
|
276
|
+
* in it changes.
|
|
277
|
+
*/
|
|
278
|
+
function archiveEncoding(dumpFile) {
|
|
279
|
+
const fd = fs.openSync(dumpFile, "r");
|
|
280
|
+
try {
|
|
281
|
+
return planPatches(fd, fs.fstatSync(fd).size, unchanged).encoding;
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (!(error instanceof RangeError)) throw error;
|
|
284
|
+
return null;
|
|
285
|
+
} finally {
|
|
286
|
+
fs.closeSync(fd);
|
|
287
|
+
}
|
|
168
288
|
}
|
|
169
289
|
/**
|
|
170
290
|
* Blank every `pg_attver` attribute option in a custom-format dump, in place.
|
|
171
|
-
*
|
|
172
|
-
* recognise,
|
|
291
|
+
*
|
|
292
|
+
* A file this does not recognise, or cannot edit safely, is left byte for
|
|
293
|
+
* byte as it was — pg_restore then reads it as it is — and the result says
|
|
294
|
+
* why. `blank` is the edit made to each table's definition: the pull always
|
|
295
|
+
* uses the default, {@link blankAttverOptions}; it is a parameter so that the
|
|
296
|
+
* guard against an edit that changes a definition's length can be tested.
|
|
173
297
|
*/
|
|
174
|
-
function stripAttverFromArchive(dumpFile) {
|
|
298
|
+
function stripAttverFromArchive(dumpFile, blank = blankAttverOptions) {
|
|
175
299
|
const fd = fs.openSync(dumpFile, "r+");
|
|
176
300
|
try {
|
|
177
|
-
let
|
|
301
|
+
let plan;
|
|
178
302
|
try {
|
|
179
|
-
|
|
303
|
+
plan = planPatches(fd, fs.fstatSync(fd).size, blank);
|
|
180
304
|
} catch (error) {
|
|
181
|
-
if (error instanceof RangeError)
|
|
182
|
-
|
|
305
|
+
if (!(error instanceof RangeError)) throw error;
|
|
306
|
+
plan = {
|
|
307
|
+
ok: false,
|
|
308
|
+
reason: NOT_AN_ARCHIVE,
|
|
309
|
+
serverVersion: null,
|
|
310
|
+
dumpVersion: null,
|
|
311
|
+
encoding: null
|
|
312
|
+
};
|
|
183
313
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
314
|
+
const versions = {
|
|
315
|
+
serverVersion: plan.serverVersion,
|
|
316
|
+
dumpVersion: plan.dumpVersion
|
|
317
|
+
};
|
|
318
|
+
if (!plan.ok) return {
|
|
319
|
+
entries: 0,
|
|
320
|
+
skipped: plan.reason,
|
|
321
|
+
...versions
|
|
322
|
+
};
|
|
323
|
+
for (const patch of plan.patches) fs.writeSync(fd, patch.bytes, 0, patch.bytes.length, patch.at);
|
|
324
|
+
return {
|
|
325
|
+
entries: plan.patches.length,
|
|
326
|
+
skipped: null,
|
|
327
|
+
...versions
|
|
328
|
+
};
|
|
187
329
|
} finally {
|
|
188
330
|
fs.closeSync(fd);
|
|
189
331
|
}
|
|
@@ -711,13 +853,19 @@ async function findPgTool(tool) {
|
|
|
711
853
|
function engineOf(version) {
|
|
712
854
|
return /\bPGlite\b/i.test(version) ? "pglite" : "postgres";
|
|
713
855
|
}
|
|
856
|
+
/** The major version `version()` names: 15 for `PostgreSQL 15.19 on aarch64-…`. Null when it names none. */
|
|
857
|
+
function majorVersionOf(version) {
|
|
858
|
+
const major = /\bPostgreSQL (\d+)/.exec(version)?.[1];
|
|
859
|
+
return major === void 0 ? null : Number(major);
|
|
860
|
+
}
|
|
714
861
|
var NOTHING_CHANGED = "Nothing was changed: the local database is as it was.";
|
|
715
862
|
/** What the target database runs on, or why it could not be asked. */
|
|
716
863
|
async function readTargetEngine(target) {
|
|
717
864
|
const { Client } = await import("pg");
|
|
718
865
|
const client = new Client({
|
|
719
866
|
connectionString: target,
|
|
720
|
-
connectionTimeoutMillis:
|
|
867
|
+
connectionTimeoutMillis: LOCAL_CONNECT_TIMEOUT_MS,
|
|
868
|
+
query_timeout: LOCAL_QUERY_TIMEOUT_MS
|
|
721
869
|
});
|
|
722
870
|
client.on("error", () => void 0);
|
|
723
871
|
try {
|
|
@@ -858,8 +1006,20 @@ function describeDumpFailure(source, run) {
|
|
|
858
1006
|
* advice names that, rather than "pull again", which sent people in a loop.
|
|
859
1007
|
* On the managed database an extension cannot be installed at all, so the
|
|
860
1008
|
* advice there is Postgres in Docker.
|
|
1009
|
+
*
|
|
1010
|
+
* One cause is named for what it is: a target refusing `pg_attver`, which
|
|
1011
|
+
* means the local pg_dump is older than the source server and the dump could
|
|
1012
|
+
* not be edited to drop the key (`attver`, what {@link stripAttverFromArchive}
|
|
1013
|
+
* said, tells why).
|
|
1014
|
+
*
|
|
1015
|
+
* One error is known to cost the copy nothing, and does not fail it: a target
|
|
1016
|
+
* older than PostgreSQL 17 (`targetMajor`, read from its `version()`) refusing
|
|
1017
|
+
* the `SET transaction_timeout` a pg_dump 17 or newer writes at the top of
|
|
1018
|
+
* every dump — see {@link onlyTransactionTimeoutRefused}. Only when it is the
|
|
1019
|
+
* one kind of error in the run; the copy is then complete, and the outcome
|
|
1020
|
+
* carries a notice saying why pg_restore's error was harmless.
|
|
861
1021
|
*/
|
|
862
|
-
function restoreOutcome(run, engine = "postgres") {
|
|
1022
|
+
function restoreOutcome(run, engine = "postgres", attver = null, targetMajor = null) {
|
|
863
1023
|
if (run.signal) return {
|
|
864
1024
|
started: true,
|
|
865
1025
|
failure: `pg_restore was stopped by ${run.signal} before it finished.`,
|
|
@@ -875,8 +1035,17 @@ function restoreOutcome(run, engine = "postgres") {
|
|
|
875
1035
|
failure: null,
|
|
876
1036
|
advice: null
|
|
877
1037
|
};
|
|
1038
|
+
if (run.exitCode === 1 && targetMajor !== null && targetMajor < TRANSACTION_TIMEOUT_SINCE) {
|
|
1039
|
+
const refused = onlyTransactionTimeoutRefused(run.stderr ?? "");
|
|
1040
|
+
if (refused !== null) return {
|
|
1041
|
+
started: true,
|
|
1042
|
+
failure: null,
|
|
1043
|
+
advice: null,
|
|
1044
|
+
notice: transactionTimeoutNotice(targetMajor, refused)
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
878
1047
|
const ignored = /errors ignored on restore: (\d+)/.exec(run.stderr ?? "");
|
|
879
|
-
const repeats = engine === "pglite" ? `Pulling again repeats these errors until what they name is fixed — most often an extension the source uses that the managed database does not have (it has ${PGLITE_EXTENSIONS.map((extension) => extension.name).join(", ")}). Pull into Postgres in Docker instead (\`rebase db pull --docker\`), or pull only the schemas that do not need it (--schema).` : "Pulling again repeats these errors until what they name is fixed — most often an extension the source uses that this Postgres does not have installed. Install it here, or pull only the schemas that do not need it (--schema).";
|
|
1048
|
+
const repeats = (run.stderr ?? "").includes("unrecognized parameter \"pg_attver\"") ? attverAdvice(attver) : engine === "pglite" ? `Pulling again repeats these errors until what they name is fixed — most often an extension the source uses that the managed database does not have (it has ${PGLITE_EXTENSIONS.map((extension) => extension.name).join(", ")}). Pull into Postgres in Docker instead (\`rebase db pull --docker\`), or pull only the schemas that do not need it (--schema).` : "Pulling again repeats these errors until what they name is fixed — most often an extension the source uses that this Postgres does not have installed. Install it here, or pull only the schemas that do not need it (--schema).";
|
|
880
1049
|
return {
|
|
881
1050
|
started: true,
|
|
882
1051
|
failure: ignored ? `pg_restore could not restore ${ignored[1]} object(s) — the errors are above.` : `pg_restore exited with code ${run.exitCode} — the errors are above.`,
|
|
@@ -884,6 +1053,61 @@ function restoreOutcome(run, engine = "postgres") {
|
|
|
884
1053
|
};
|
|
885
1054
|
}
|
|
886
1055
|
/**
|
|
1056
|
+
* What to do when the target refused the dump's `pg_attver` options: they are
|
|
1057
|
+
* there because the local pg_dump is older than the server it dumped from,
|
|
1058
|
+
* and a pg_dump at least as new leaves them out.
|
|
1059
|
+
*/
|
|
1060
|
+
function attverAdvice(attver) {
|
|
1061
|
+
return `${attver?.dumpVersion && attver.serverVersion ? `Your pg_dump (${attver.dumpVersion}) is older than the server it dumped from (${attver.serverVersion})` : "Your pg_dump is older than the server it dumped from"}: it wrote pg_attver column options, which this database refuses${attver?.skipped ? `, and Rebase could not take them out of this dump: ${attver.skipped}` : ""}. Upgrade the PostgreSQL client tools to ${attver?.serverVersion ? `at least ${attver.serverVersion}` : "at least the server's minor version"} (check with \`pg_dump --version\`), then pull again.`;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* The line a pull prints when it took `pg_attver` out of the dump: the copy is
|
|
1065
|
+
* whole, but the local pg_dump is older than the source server, which is what
|
|
1066
|
+
* to fix. Null when nothing was taken out.
|
|
1067
|
+
*/
|
|
1068
|
+
function attverNotice(attver) {
|
|
1069
|
+
if (attver.entries === 0) return null;
|
|
1070
|
+
const older = attver.dumpVersion && attver.serverVersion ? `Your pg_dump (${attver.dumpVersion}) is older than the server it dumped from (${attver.serverVersion})` : "Your pg_dump is older than the server it dumped from";
|
|
1071
|
+
const atLeast = attver.serverVersion ? `at least ${attver.serverVersion}` : "at least the server's minor version";
|
|
1072
|
+
return `${older}: its dump carried pg_attver column options this database would refuse, so they were taken out of ${attver.entries} table(s) before restoring. Upgrading the PostgreSQL client tools to ${atLeast} is the supported fix.`;
|
|
1073
|
+
}
|
|
1074
|
+
/** The PostgreSQL major that added `transaction_timeout`, and whose pg_dump began writing `SET transaction_timeout = 0;`. */
|
|
1075
|
+
var TRANSACTION_TIMEOUT_SINCE = 17;
|
|
1076
|
+
/** pg_restore's line for an error, whatever caused it. */
|
|
1077
|
+
var RESTORE_ERROR_LINE = /^pg_restore: error: /;
|
|
1078
|
+
/** What a server older than 17 answers `SET transaction_timeout`: pg_restore's line for it, word for word. */
|
|
1079
|
+
var TRANSACTION_TIMEOUT_REFUSED_LINE = /^pg_restore: error: could not execute query: ERROR: {2}unrecognized configuration parameter "transaction_timeout"$/;
|
|
1080
|
+
/** The statement pg_restore names after that error. */
|
|
1081
|
+
var TRANSACTION_TIMEOUT_COMMAND_LINE = /^Command was: SET transaction_timeout = \d+;$/;
|
|
1082
|
+
/**
|
|
1083
|
+
* How many errors pg_restore reported when every one of them was the target
|
|
1084
|
+
* refusing the dump's `SET transaction_timeout`, or null when any was
|
|
1085
|
+
* anything else.
|
|
1086
|
+
*
|
|
1087
|
+
* Strict on purpose, because whatever it accepts is reported as a complete
|
|
1088
|
+
* copy: its summary ("errors ignored on restore: N") must be there, and N must
|
|
1089
|
+
* be exactly the number of errors it printed, each of them that refusal and
|
|
1090
|
+
* each naming that statement. An error it cannot read is never called harmless.
|
|
1091
|
+
*/
|
|
1092
|
+
function onlyTransactionTimeoutRefused(stderr) {
|
|
1093
|
+
const ignored = /errors ignored on restore: (\d+)/.exec(stderr);
|
|
1094
|
+
if (!ignored) return null;
|
|
1095
|
+
const count = Number(ignored[1]);
|
|
1096
|
+
const lines = stderr.split(/\r?\n/).map((line) => line.trimEnd());
|
|
1097
|
+
const errors = lines.filter((line) => RESTORE_ERROR_LINE.test(line));
|
|
1098
|
+
const commands = lines.filter((line) => line.startsWith("Command was: "));
|
|
1099
|
+
if (count === 0 || errors.length !== count || commands.length !== count) return null;
|
|
1100
|
+
return errors.every((line) => TRANSACTION_TIMEOUT_REFUSED_LINE.test(line)) && commands.every((line) => TRANSACTION_TIMEOUT_COMMAND_LINE.test(line)) ? count : null;
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* The line a pull prints when the only errors pg_restore reported were the
|
|
1104
|
+
* target refusing `SET transaction_timeout`: pg_restore has already printed
|
|
1105
|
+
* them, and this says they cost nothing.
|
|
1106
|
+
*/
|
|
1107
|
+
function transactionTimeoutNotice(targetMajor, errors) {
|
|
1108
|
+
return `${errors === 1 ? "The error above is" : `The ${errors} errors above are`} the local PostgreSQL ${targetMajor} refusing the \`SET transaction_timeout = 0\` a pg_dump ${TRANSACTION_TIMEOUT_SINCE} or newer writes at the top of every dump: that setting does not exist before PostgreSQL ${TRANSACTION_TIMEOUT_SINCE}, nothing else failed, and the copy is complete.`;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
887
1111
|
* The local schemas a pull empties before it restores: every one of the local
|
|
888
1112
|
* database's own for a whole-database pull, and those it copies for a
|
|
889
1113
|
* `--schema` pull. `pg_catalog`, `information_schema` and the `pg_*` internals
|
|
@@ -915,6 +1139,47 @@ function clearStatements(schemas) {
|
|
|
915
1139
|
* a transaction would otherwise make the pull hang without a word.
|
|
916
1140
|
*/
|
|
917
1141
|
var CLEAR_LOCK_TIMEOUT = "15s";
|
|
1142
|
+
/**
|
|
1143
|
+
* How long one statement of {@link restoreCopy}'s may take before the pull
|
|
1144
|
+
* stops waiting on the database: twice the short bound, 30s. It has to stay
|
|
1145
|
+
* above {@link CLEAR_LOCK_TIMEOUT}, so that a lock the clear waits on is
|
|
1146
|
+
* reported as the lock it is (`55P03`, "stop `rebase dev`"). This bound is for
|
|
1147
|
+
* a database that answers nothing at all.
|
|
1148
|
+
*/
|
|
1149
|
+
var CLEAR_QUERY_TIMEOUT_MS = 2 * LOCAL_QUERY_TIMEOUT_MS;
|
|
1150
|
+
/**
|
|
1151
|
+
* The one encoding the managed database restores a dump in.
|
|
1152
|
+
*
|
|
1153
|
+
* pg_restore starts every restore with the dump's own `SET client_encoding`.
|
|
1154
|
+
* PGlite cannot convert. Sent `SET client_encoding = 'LATIN1'`, its daemon
|
|
1155
|
+
* closed the connection and then answered nobody, on that connection or any
|
|
1156
|
+
* later one, until `rebase db stop`. A pull from a LATIN1 database had
|
|
1157
|
+
* already emptied the local one by then. Every statement after the SET failed
|
|
1158
|
+
* on "no connection to the server".
|
|
1159
|
+
*/
|
|
1160
|
+
var MANAGED_ENCODING = "UTF8";
|
|
1161
|
+
/**
|
|
1162
|
+
* Why the local database cannot take a dump written in `encoding`, or null
|
|
1163
|
+
* when it can.
|
|
1164
|
+
*
|
|
1165
|
+
* Only the managed database refuses one. A Postgres target converts any
|
|
1166
|
+
* encoding to its own as pg_restore writes, which is how a LATIN1 source has
|
|
1167
|
+
* always pulled into Postgres in Docker. `encoding` is what
|
|
1168
|
+
* {@link archiveEncoding} read from the dump's ENCODING entry. Null means the
|
|
1169
|
+
* dump could not be read, and pg_restore is left to say what it makes of it,
|
|
1170
|
+
* as before. {@link restoreCopy} asks this before it empties anything, so the
|
|
1171
|
+
* outcome says the database is as it was.
|
|
1172
|
+
*/
|
|
1173
|
+
function encodingRefusal(engine, encoding) {
|
|
1174
|
+
if (engine !== "pglite" || encoding === null) return null;
|
|
1175
|
+
if (encoding.replace(/[-_]/g, "").toUpperCase() === MANAGED_ENCODING) return null;
|
|
1176
|
+
return {
|
|
1177
|
+
cleared: false,
|
|
1178
|
+
started: false,
|
|
1179
|
+
failure: `The managed development database cannot take this dump: pg_dump wrote it in the ${encoding} encoding (the source database's, unless PGCLIENTENCODING named another), and PGlite restores UTF8 only. The \`SET client_encoding = '${encoding}'\` a restore starts with leaves it answering nobody.`,
|
|
1180
|
+
advice: "Pull into Postgres in Docker instead, which converts it: `rebase db pull --docker` with the same --from. Or set DATABASE_URL in .env to a Postgres you run, and pull into that."
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
918
1183
|
/** Why emptying the local database failed, in the reader's terms, and what fixes it. */
|
|
919
1184
|
function clearFailure(error) {
|
|
920
1185
|
const code = typeof error === "object" && error !== null && "code" in error ? String(error.code) : "";
|
|
@@ -937,38 +1202,51 @@ function clearFailure(error) {
|
|
|
937
1202
|
* restored, and the database is as it was.
|
|
938
1203
|
*
|
|
939
1204
|
* On the managed database the dump must be one {@link dumpSource} took for it,
|
|
940
|
-
* with its rows as INSERTs
|
|
941
|
-
*
|
|
1205
|
+
* with its rows as INSERTs, and written in UTF8: a COPY, or any other
|
|
1206
|
+
* encoding, would leave the daemon answering nobody, so either is refused
|
|
1207
|
+
* before anything is emptied. And afterwards its one session —
|
|
942
1208
|
* every connection's — is given back its own settings: pg_restore leaves
|
|
943
1209
|
* `search_path` empty and `row_security` off behind it, which a running
|
|
944
1210
|
* `rebase dev` would otherwise query under.
|
|
945
1211
|
*/
|
|
946
1212
|
async function restoreCopy(plan, dumpFile) {
|
|
1213
|
+
const encoding = archiveEncoding(dumpFile);
|
|
947
1214
|
const { Client } = await import("pg");
|
|
948
|
-
const client = new Client({
|
|
1215
|
+
const client = new Client({
|
|
1216
|
+
connectionString: plan.target,
|
|
1217
|
+
connectionTimeoutMillis: LOCAL_CONNECT_TIMEOUT_MS,
|
|
1218
|
+
query_timeout: CLEAR_QUERY_TIMEOUT_MS
|
|
1219
|
+
});
|
|
949
1220
|
client.on("error", () => void 0);
|
|
950
1221
|
let engine;
|
|
1222
|
+
let targetMajor;
|
|
1223
|
+
let begun = false;
|
|
951
1224
|
try {
|
|
952
1225
|
await client.connect();
|
|
953
|
-
|
|
1226
|
+
const version = (await client.query("SELECT version() AS version")).rows[0]?.version ?? "";
|
|
1227
|
+
engine = engineOf(version);
|
|
1228
|
+
targetMajor = majorVersionOf(version);
|
|
954
1229
|
if (engine === "pglite" && plan.targetEngine !== "pglite") return {
|
|
955
1230
|
cleared: false,
|
|
956
1231
|
started: false,
|
|
957
1232
|
failure: "The managed development database cannot take this dump: its rows are COPY data, which PGlite's socket server cannot receive.",
|
|
958
1233
|
advice: "Pull into Postgres in Docker instead: `rebase db pull --docker`."
|
|
959
1234
|
};
|
|
1235
|
+
const refused = encodingRefusal(engine, encoding);
|
|
1236
|
+
if (refused) return refused;
|
|
960
1237
|
const { rows } = await client.query("SELECT nspname AS \"schema\" FROM pg_namespace");
|
|
1238
|
+
begun = true;
|
|
961
1239
|
await client.query("BEGIN");
|
|
962
1240
|
await client.query(`SET LOCAL lock_timeout = '${CLEAR_LOCK_TIMEOUT}'`);
|
|
963
1241
|
for (const statement of clearStatements(schemasToClear(rows, plan.schemas))) await client.query(statement);
|
|
964
1242
|
await client.query("COMMIT");
|
|
965
1243
|
} catch (error) {
|
|
966
|
-
await client.query("ROLLBACK").catch(() => void 0);
|
|
1244
|
+
if (begun) await client.query("ROLLBACK").catch(() => void 0);
|
|
967
1245
|
return clearFailure(error);
|
|
968
1246
|
} finally {
|
|
969
1247
|
await client.end().catch(() => void 0);
|
|
970
1248
|
}
|
|
971
|
-
stripAttverFromArchive(dumpFile);
|
|
1249
|
+
const attver = stripAttverFromArchive(dumpFile);
|
|
972
1250
|
const run = await execa("pg_restore", restoreArgs(plan, dumpFile), {
|
|
973
1251
|
env: restoreEnv(plan),
|
|
974
1252
|
stdin: "ignore",
|
|
@@ -977,9 +1255,12 @@ async function restoreCopy(plan, dumpFile) {
|
|
|
977
1255
|
reject: false
|
|
978
1256
|
});
|
|
979
1257
|
if (engine === "pglite") await resetSharedSession(plan.target);
|
|
1258
|
+
const outcome = restoreOutcome(run, engine, attver, targetMajor);
|
|
1259
|
+
const notice = [attverNotice(attver), outcome.notice].filter((line) => line).join(" ");
|
|
980
1260
|
return {
|
|
981
1261
|
cleared: true,
|
|
982
|
-
...
|
|
1262
|
+
...outcome,
|
|
1263
|
+
...notice ? { notice } : {}
|
|
983
1264
|
};
|
|
984
1265
|
}
|
|
985
1266
|
/**
|
|
@@ -995,8 +1276,8 @@ async function resetSharedSession(target) {
|
|
|
995
1276
|
const { Client } = await import("pg");
|
|
996
1277
|
const client = new Client({
|
|
997
1278
|
connectionString: target,
|
|
998
|
-
connectionTimeoutMillis:
|
|
999
|
-
query_timeout:
|
|
1279
|
+
connectionTimeoutMillis: LOCAL_CONNECT_TIMEOUT_MS,
|
|
1280
|
+
query_timeout: LOCAL_QUERY_TIMEOUT_MS
|
|
1000
1281
|
});
|
|
1001
1282
|
client.on("error", () => void 0);
|
|
1002
1283
|
try {
|
|
@@ -1022,4 +1303,4 @@ function describeRestoreFailure(outcome, source) {
|
|
|
1022
1303
|
//#endregion
|
|
1023
1304
|
export { anonymizeCopy, describeRestoreFailure, describeTarget, dumpSource, findPgTool, provisionableSchemas, restoreCopy, sourceProblem };
|
|
1024
1305
|
|
|
1025
|
-
//# sourceMappingURL=pull-
|
|
1306
|
+
//# sourceMappingURL=pull-CTIsST6T.js.map
|