@akal/supaforge 0.0.31 → 0.0.33

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -11
  3. package/dist/base-command.d.ts +1 -0
  4. package/dist/base-command.js +2 -2
  5. package/dist/{chunk-BHYLBKYD.js → chunk-2SELREHW.js} +5 -5
  6. package/dist/{chunk-5Z3SAIQS.js → chunk-3HGAV5CC.js} +97 -831
  7. package/dist/{chunk-XMYMIURR.js → chunk-4IVN7QVY.js} +119 -39
  8. package/dist/{chunk-NXRSAVRU.js → chunk-6LJERPUN.js} +28 -7
  9. package/dist/{chunk-4OU7KO5Y.js → chunk-6Q7MHFBM.js} +2 -2
  10. package/dist/{chunk-PARSNTBD.js → chunk-7NAZGZPV.js} +56 -25
  11. package/dist/{chunk-VOXZWQ3N.js → chunk-BUOWHE36.js} +372 -9
  12. package/dist/{chunk-TQJSQLWA.js → chunk-DMIWAJRB.js} +38 -10
  13. package/dist/{chunk-LQXF65MC.js → chunk-GEHPTPNZ.js} +3 -3
  14. package/dist/chunk-GZREXCQZ.js +207 -0
  15. package/dist/{chunk-YVDSR4GM.js → chunk-MIRLB5JM.js} +51 -23
  16. package/dist/{chunk-KIFJGON5.js → chunk-NTUASFQ3.js} +2 -2
  17. package/dist/{chunk-5QQBTLWO.js → chunk-ORQJVE57.js} +3 -3
  18. package/dist/{chunk-VMTBLHN2.js → chunk-SC2XHGIS.js} +2 -2
  19. package/dist/{chunk-X6V2GGDZ.js → chunk-SQPCWGQO.js} +388 -64
  20. package/dist/chunk-UWAVXC57.js +916 -0
  21. package/dist/commands/clone.js +10 -10
  22. package/dist/commands/diff.d.ts +16 -0
  23. package/dist/commands/diff.js +11 -12
  24. package/dist/commands/hukam.js +11 -12
  25. package/dist/commands/mcp.d.ts +1 -0
  26. package/dist/commands/mcp.js +18 -9
  27. package/dist/commands/migrate/baseline.js +3 -3
  28. package/dist/commands/migrate/create.js +5 -6
  29. package/dist/commands/migrate/list.js +4 -4
  30. package/dist/commands/migrate/run.js +5 -6
  31. package/dist/commands/report.js +3 -3
  32. package/dist/commands/restore.js +11 -13
  33. package/dist/commands/snapshot.js +6 -8
  34. package/dist/commands/sync.js +11 -12
  35. package/dist/index.d.ts +5 -0
  36. package/dist/index.js +16 -16
  37. package/package.json +10 -8
  38. package/bin/dev.js +0 -10
  39. package/dist/base-command.js.map +0 -1
  40. package/dist/chunk-4OU7KO5Y.js.map +0 -1
  41. package/dist/chunk-5QQBTLWO.js.map +0 -1
  42. package/dist/chunk-5Z3SAIQS.js.map +0 -1
  43. package/dist/chunk-6WAMNZLO.js.map +0 -1
  44. package/dist/chunk-BHYLBKYD.js.map +0 -1
  45. package/dist/chunk-BLKJWDTL.js.map +0 -1
  46. package/dist/chunk-DQQ5E563.js.map +0 -1
  47. package/dist/chunk-G2DIPIYU.js.map +0 -1
  48. package/dist/chunk-H5MJ5DFX.js +0 -16
  49. package/dist/chunk-H5MJ5DFX.js.map +0 -1
  50. package/dist/chunk-KIFJGON5.js.map +0 -1
  51. package/dist/chunk-LQXF65MC.js.map +0 -1
  52. package/dist/chunk-NXRSAVRU.js.map +0 -1
  53. package/dist/chunk-PARSNTBD.js.map +0 -1
  54. package/dist/chunk-RRMI5CZD.js +0 -376
  55. package/dist/chunk-RRMI5CZD.js.map +0 -1
  56. package/dist/chunk-SF3YA42C.js +0 -506
  57. package/dist/chunk-SF3YA42C.js.map +0 -1
  58. package/dist/chunk-TQJSQLWA.js.map +0 -1
  59. package/dist/chunk-VMTBLHN2.js.map +0 -1
  60. package/dist/chunk-VOXZWQ3N.js.map +0 -1
  61. package/dist/chunk-X6V2GGDZ.js.map +0 -1
  62. package/dist/chunk-XMYMIURR.js.map +0 -1
  63. package/dist/chunk-YVDSR4GM.js.map +0 -1
  64. package/dist/commands/clone.js.map +0 -1
  65. package/dist/commands/diff.js.map +0 -1
  66. package/dist/commands/help.js.map +0 -1
  67. package/dist/commands/hukam.js.map +0 -1
  68. package/dist/commands/init.js.map +0 -1
  69. package/dist/commands/mcp.js.map +0 -1
  70. package/dist/commands/migrate/baseline.js.map +0 -1
  71. package/dist/commands/migrate/create.js.map +0 -1
  72. package/dist/commands/migrate/list.js.map +0 -1
  73. package/dist/commands/migrate/run.js.map +0 -1
  74. package/dist/commands/report.js.map +0 -1
  75. package/dist/commands/restore.js.map +0 -1
  76. package/dist/commands/snapshot.js.map +0 -1
  77. package/dist/commands/sync.js.map +0 -1
  78. package/dist/help.js.map +0 -1
  79. package/dist/index.js.map +0 -1
@@ -1,60 +1,17 @@
1
1
  import {
2
+ CONTAINER_RM_TIMEOUT_MS,
3
+ CONTAINER_START_TIMEOUT_MS,
2
4
  DB_CONNECT_TIMEOUT_MS,
3
- MIGRATIONS_TABLE
5
+ DB_PROBE_TIMEOUT_MS,
6
+ MIGRATIONS_TABLE,
7
+ RUNTIME_DETECT_TIMEOUT_MS,
8
+ bold,
9
+ cmd,
10
+ dim,
11
+ ok,
12
+ warn
4
13
  } from "./chunk-6WAMNZLO.js";
5
14
 
6
- // src/db.ts
7
- import pg from "pg";
8
- function resolveConnectTimeoutMs() {
9
- const raw = process.env.SUPAFORGE_CONNECT_TIMEOUT;
10
- if (raw) {
11
- const secs = Number(raw);
12
- if (Number.isFinite(secs) && secs > 0) return Math.round(secs * 1e3);
13
- }
14
- return DB_CONNECT_TIMEOUT_MS;
15
- }
16
- function pgClientConfig(dbUrl, queryTimeoutMs) {
17
- const config = {
18
- connectionString: dbUrl,
19
- connectionTimeoutMillis: resolveConnectTimeoutMs()
20
- };
21
- if (queryTimeoutMs !== void 0) {
22
- config.query_timeout = queryTimeoutMs;
23
- }
24
- return config;
25
- }
26
- var pools = /* @__PURE__ */ new Map();
27
- var POOL_MAX = 4;
28
- function poolFor(dbUrl) {
29
- const existing = pools.get(dbUrl);
30
- if (existing) return existing;
31
- const pool = new pg.Pool({
32
- ...pgClientConfig(dbUrl),
33
- max: POOL_MAX,
34
- allowExitOnIdle: true
35
- });
36
- pool.on("error", () => void 0);
37
- pools.set(dbUrl, pool);
38
- return pool;
39
- }
40
- var pgQuery = async (dbUrl, sql, params) => {
41
- const { rows } = await poolFor(dbUrl).query(sql, params);
42
- return rows;
43
- };
44
- async function inRolledBackTransaction(dbUrl, fn) {
45
- const client = await poolFor(dbUrl).connect();
46
- try {
47
- await client.query("BEGIN");
48
- try {
49
- return await fn(client);
50
- } finally {
51
- await client.query("ROLLBACK").catch(() => void 0);
52
- }
53
- } finally {
54
- client.release();
55
- }
56
- }
57
-
58
15
  // src/utils/error.ts
59
16
  var DB_URL_RE = /\b((?:postgres(?:ql)?|mysql|mariadb):\/\/)(\S+)/g;
60
17
  function redactUrls(message) {
@@ -105,13 +62,20 @@ var CONNECTION_ERROR_PATTERNS = [
105
62
  test: (m) => /ENOTFOUND|getaddrinfo/i.test(m),
106
63
  build: (host) => `Cannot resolve hostname ${host} \u2014 check the database URL in your config.`
107
64
  },
65
+ {
66
+ // Before the connection timeout: the server answered, and a query ran
67
+ // past its statement_timeout. Calling that a connection problem sent
68
+ // people to check a host and port that were fine.
69
+ test: (m) => /canceling statement due to statement timeout|57014/i.test(m),
70
+ build: (host) => `A query on ${host} was cancelled by statement_timeout \u2014 the server is reachable. Raise statement_timeout for this role or connection and try again.`
71
+ },
108
72
  {
109
73
  // Deliberately narrow. A bare /timeout/i also matches our own remediation
110
74
  // text — "set SUPAFORGE_DBDIFF_TIMEOUT=600" contains "TIMEOUT" — which is
111
75
  // how an accurate "Schema diff timed out after Ns" message was being
112
76
  // rewritten into a wrong "check the host and port" one (issue #29).
113
77
  // DiagnosticError below is the primary guard; this is defence in depth.
114
- test: (m) => /ETIMEDOUT|connection timed out|timeout expired|statement timeout/i.test(m),
78
+ test: (m) => /ETIMEDOUT|connection timed out|timeout expired/i.test(m),
115
79
  build: (host) => `Connection to ${host} timed out \u2014 verify the host and port are correct and that the server is reachable.`
116
80
  },
117
81
  {
@@ -156,6 +120,351 @@ function friendlyDbError(err, dbUrl) {
156
120
  return raw;
157
121
  }
158
122
 
123
+ // src/db.ts
124
+ import pg from "pg";
125
+ function resolveConnectTimeoutMs() {
126
+ const raw = process.env.SUPAFORGE_CONNECT_TIMEOUT;
127
+ if (raw) {
128
+ const secs = Number(raw);
129
+ if (Number.isFinite(secs) && secs > 0) return Math.round(secs * 1e3);
130
+ }
131
+ return DB_CONNECT_TIMEOUT_MS;
132
+ }
133
+ function pgClientConfig(dbUrl, queryTimeoutMs) {
134
+ const config = {
135
+ connectionString: dbUrl,
136
+ connectionTimeoutMillis: resolveConnectTimeoutMs()
137
+ };
138
+ if (queryTimeoutMs !== void 0) {
139
+ config.query_timeout = queryTimeoutMs;
140
+ }
141
+ return config;
142
+ }
143
+ var pools = /* @__PURE__ */ new Map();
144
+ var POOL_MAX = 4;
145
+ function poolFor(dbUrl) {
146
+ const existing = pools.get(dbUrl);
147
+ if (existing) return existing;
148
+ const pool = new pg.Pool({
149
+ ...pgClientConfig(dbUrl),
150
+ max: POOL_MAX,
151
+ allowExitOnIdle: true
152
+ });
153
+ pool.on("error", () => void 0);
154
+ pools.set(dbUrl, pool);
155
+ return pool;
156
+ }
157
+ var pgQuery = async (dbUrl, sql, params) => {
158
+ const { rows } = await poolFor(dbUrl).query(sql, params);
159
+ return rows;
160
+ };
161
+ async function inRolledBackTransaction(dbUrl, fn) {
162
+ const client = await poolFor(dbUrl).connect();
163
+ try {
164
+ await client.query("BEGIN");
165
+ try {
166
+ return await fn(client);
167
+ } finally {
168
+ await client.query("ROLLBACK").catch(() => void 0);
169
+ }
170
+ } finally {
171
+ client.release();
172
+ }
173
+ }
174
+
175
+ // src/local-pg.ts
176
+ import { execFile } from "child_process";
177
+ import { promisify } from "util";
178
+ import pg2 from "pg";
179
+ var defaultExecFile = promisify(execFile);
180
+ var PG_IMAGE = "docker.io/library/postgres:17";
181
+ var DEFAULT_LOCAL_PORT = 5432;
182
+ var CONTAINER_NAME = "supaforge-local-pg";
183
+ var LOCAL_PG_USER = "postgres";
184
+ var LOCAL_PG_PASSWORD = "postgres";
185
+ var READINESS_RETRIES = 30;
186
+ var READINESS_INTERVAL_MS = 2e3;
187
+ async function defaultConnectFn(url) {
188
+ const client = new pg2.Client(pgClientConfig(url));
189
+ await client.connect();
190
+ await client.end();
191
+ }
192
+ async function detectRuntime(execFn = defaultExecFile) {
193
+ for (const rt of ["podman", "docker"]) {
194
+ try {
195
+ await execFn(rt, ["--version"], { timeout: RUNTIME_DETECT_TIMEOUT_MS });
196
+ return rt;
197
+ } catch {
198
+ continue;
199
+ }
200
+ }
201
+ return null;
202
+ }
203
+ async function startLocalPg(options = {}) {
204
+ const exec = options.execFn ?? defaultExecFile;
205
+ const connect = options.connectFn ?? defaultConnectFn;
206
+ const runtime = options.runtime ?? await detectRuntime(exec);
207
+ if (!runtime) {
208
+ throw new Error(
209
+ "No container runtime found. Install Podman (recommended) or Docker.\n Podman: https://podman.io/docs/installation\n Docker: https://docs.docker.com/engine/install/"
210
+ );
211
+ }
212
+ const port = options.port ?? DEFAULT_LOCAL_PORT;
213
+ const password = options.password ?? LOCAL_PG_PASSWORD;
214
+ const name = options.name ?? CONTAINER_NAME;
215
+ const image = options.image ?? PG_IMAGE;
216
+ const existing = await getContainerStatus(runtime, name, exec);
217
+ if (existing === "running") {
218
+ return {
219
+ runtime,
220
+ containerName: name,
221
+ port,
222
+ url: buildLocalUrl(port, password)
223
+ };
224
+ }
225
+ if (existing === "stopped") {
226
+ await exec(runtime, ["rm", "-f", name], { timeout: CONTAINER_RM_TIMEOUT_MS });
227
+ }
228
+ const args = [
229
+ "run",
230
+ "-d",
231
+ "--name",
232
+ name,
233
+ "-p",
234
+ `${port}:5432`,
235
+ "-e",
236
+ `POSTGRES_PASSWORD=${password}`,
237
+ "-e",
238
+ `POSTGRES_USER=${LOCAL_PG_USER}`,
239
+ "--tmpfs",
240
+ "/var/lib/postgresql/data",
241
+ "--health-cmd",
242
+ `pg_isready -U ${LOCAL_PG_USER}`,
243
+ "--health-interval",
244
+ "5s",
245
+ "--health-timeout",
246
+ "5s",
247
+ "--health-retries",
248
+ "20",
249
+ "--health-start-period",
250
+ "10s",
251
+ image
252
+ ];
253
+ try {
254
+ await exec(runtime, args, { timeout: CONTAINER_START_TIMEOUT_MS });
255
+ } catch (err) {
256
+ throw new Error(
257
+ `Failed to start PostgreSQL container via ${runtime}: ${err.message}`
258
+ );
259
+ }
260
+ const url = buildLocalUrl(port, password);
261
+ await waitForPg(url, connect);
262
+ return { runtime, containerName: name, port, url };
263
+ }
264
+ async function getContainerStatus(runtime, name, execFn) {
265
+ try {
266
+ const { stdout } = await execFn(
267
+ runtime,
268
+ ["inspect", "--format", "{{.State.Running}}", name],
269
+ { timeout: RUNTIME_DETECT_TIMEOUT_MS }
270
+ );
271
+ return stdout.trim() === "true" ? "running" : "stopped";
272
+ } catch {
273
+ return "none";
274
+ }
275
+ }
276
+ function buildLocalUrl(port, password) {
277
+ return `postgres://${LOCAL_PG_USER}:${password}@localhost:${port}/postgres`;
278
+ }
279
+ async function waitForPg(url, connectFn) {
280
+ for (let i = 0; i < READINESS_RETRIES; i++) {
281
+ try {
282
+ await connectFn(url);
283
+ return;
284
+ } catch {
285
+ await sleep(READINESS_INTERVAL_MS);
286
+ }
287
+ }
288
+ throw new Error(
289
+ `PostgreSQL at ${url} did not become ready within ${READINESS_RETRIES * READINESS_INTERVAL_MS / 1e3}s`
290
+ );
291
+ }
292
+ function sleep(ms) {
293
+ return new Promise((resolve) => setTimeout(resolve, ms));
294
+ }
295
+
296
+ // src/preflight.ts
297
+ import pg3 from "pg";
298
+ var SUPABASE_LOCAL_PORT = "54322";
299
+ var DEFAULT_PG_PORT = "5432";
300
+ var CONNECT_TIMEOUT_RE = /timeout expired|connection timeout/i;
301
+ var QUERY_TIMEOUT_RE = /query read timeout/i;
302
+ function describeTimeout(message, connectTimeoutMs, probeTimeoutMs) {
303
+ if (CONNECT_TIMEOUT_RE.test(message)) {
304
+ return `timed out after ${Math.round(connectTimeoutMs / 1e3)}s connecting \u2014 the host accepted the connection but never completed the handshake`;
305
+ }
306
+ if (QUERY_TIMEOUT_RE.test(message)) {
307
+ return `timed out after ${Math.round(probeTimeoutMs / 1e3)}s waiting for server response \u2014 connected, but the server did not answer`;
308
+ }
309
+ return message;
310
+ }
311
+ async function checkConnection(dbUrl) {
312
+ const connectTimeoutMs = resolveConnectTimeoutMs();
313
+ let client;
314
+ try {
315
+ client = new pg3.Client(pgClientConfig(dbUrl, DB_PROBE_TIMEOUT_MS));
316
+ await client.connect();
317
+ const { rows } = await client.query("SHOW server_version");
318
+ const version = rows[0].server_version;
319
+ return { reachable: true, version };
320
+ } catch (err) {
321
+ return {
322
+ reachable: false,
323
+ error: describeTimeout(describeFailure(err), connectTimeoutMs, DB_PROBE_TIMEOUT_MS)
324
+ };
325
+ } finally {
326
+ try {
327
+ await client?.end();
328
+ } catch {
329
+ }
330
+ }
331
+ }
332
+ var SERVER_REACHABLE_RE = /password authentication failed|does not exist|database .* does not exist|SSL.*required|no pg_hba\.conf entry/i;
333
+ async function buildLocalHints(dbUrl, error) {
334
+ const hints = [];
335
+ try {
336
+ const urlObj = new URL(dbUrl);
337
+ const isSupabasePort = urlObj.port === SUPABASE_LOCAL_PORT;
338
+ const isLocal = ["localhost", "127.0.0.1", "::1", ""].includes(urlObj.hostname);
339
+ if (!isLocal) return hints;
340
+ if (error && SERVER_REACHABLE_RE.test(error)) {
341
+ hints.push(`Check the username and password in your database URL.`);
342
+ if (isSupabasePort) {
343
+ hints.push(`Port ${SUPABASE_LOCAL_PORT} is the Supabase CLI default. The default password is "postgres".`);
344
+ }
345
+ return hints;
346
+ }
347
+ if (isSupabasePort) {
348
+ hints.push(`Port ${SUPABASE_LOCAL_PORT} is the Supabase CLI default. Run ${cmd('"supabase start"')} to start your local Supabase instance.`);
349
+ }
350
+ const runtime = await detectRuntime();
351
+ if (runtime) {
352
+ hints.push(`${bold(runtime)} detected \u2014 you can start a PostgreSQL container manually.`);
353
+ }
354
+ if (!isSupabasePort) {
355
+ hints.push(`Start PostgreSQL manually on port ${urlObj.port || DEFAULT_PG_PORT}.`);
356
+ }
357
+ } catch {
358
+ }
359
+ return hints;
360
+ }
361
+ function buildTimeoutHints() {
362
+ return [
363
+ "The host is listening but the database did not answer.",
364
+ "Check the database process is running and not paused, restarting, or overloaded.",
365
+ "Over a VPN or tunnel, check the connection is still up.",
366
+ `Raise the bound with ${cmd("SUPAFORGE_CONNECT_TIMEOUT")} (in seconds) if the link is simply slow.`
367
+ ];
368
+ }
369
+ async function buildConnectionHints(dbUrl, error) {
370
+ if (error && /timed out after \d+s/.test(error)) return buildTimeoutHints();
371
+ return buildLocalHints(dbUrl, error);
372
+ }
373
+ var defaultPending = (msg) => {
374
+ if (!process.stdout.isTTY) return;
375
+ process.stdout.write(msg === null ? "\r\x1B[2K" : `\r\x1B[2K${msg}`);
376
+ };
377
+ var Preflight = class {
378
+ title;
379
+ log;
380
+ pending;
381
+ databases = [];
382
+ customs = [];
383
+ infoLines = [];
384
+ constructor(title, log, pending = defaultPending) {
385
+ this.title = title;
386
+ this.log = log;
387
+ this.pending = pending;
388
+ }
389
+ /** Register a database connectivity check. */
390
+ addDatabase(label, envName, dbUrl) {
391
+ this.databases.push({ label, envName, dbUrl });
392
+ return this;
393
+ }
394
+ /** Add an informational line to the header (displayed after database lines). */
395
+ addInfo(label, value) {
396
+ this.infoLines.push({ label, value });
397
+ return this;
398
+ }
399
+ /** Register a custom check (runs after all DB connectivity checks). */
400
+ addCheck(label, fn) {
401
+ this.customs.push({ label, fn });
402
+ return this;
403
+ }
404
+ /** Execute all registered checks, render results, and return the report. */
405
+ async run() {
406
+ const entries = [];
407
+ const log = this.log;
408
+ log(`
409
+ ${bold(this.title)}
410
+ `);
411
+ for (const db of this.databases) {
412
+ log(` ${db.label}: ${db.envName} ${dim(`(${redactUrls(db.dbUrl)})`)}`);
413
+ }
414
+ for (const info of this.infoLines) {
415
+ log(` ${info.label}: ${info.value}`);
416
+ }
417
+ log("");
418
+ log(" Checks:");
419
+ for (const db of this.databases) {
420
+ this.pending(` ${dim(`\u2026 connecting to ${db.label.toLowerCase()}`)}`);
421
+ const result = await checkConnection(db.dbUrl);
422
+ this.pending(null);
423
+ if (result.reachable) {
424
+ log(` ${ok("\u2713")} ${db.label} reachable ${dim(`(PostgreSQL ${result.version})`)}`);
425
+ entries.push({ label: db.label, passed: true, detail: `PostgreSQL ${result.version}` });
426
+ } else {
427
+ log(` ${warn("\u2717")} ${db.label} not reachable: ${redactUrls(describeFailure(result.error))}`);
428
+ const hints = await buildConnectionHints(db.dbUrl, result.error);
429
+ if (hints.length > 0) {
430
+ log(`
431
+ ${dim("Hints:")}`);
432
+ for (const h of hints) log(` ${dim("\u2022")} ${h}`);
433
+ }
434
+ entries.push({ label: db.label, passed: false, error: result.error, hints });
435
+ }
436
+ }
437
+ for (const custom of this.customs) {
438
+ this.pending(` ${dim(`\u2026 ${custom.label}`)}`);
439
+ const result = await custom.fn();
440
+ this.pending(null);
441
+ if (!result.error) {
442
+ const suffix = result.detail ? ` ${dim(result.detail)}` : "";
443
+ log(` ${ok("\u2713")} ${custom.label}${suffix}`);
444
+ entries.push({ label: custom.label, passed: true, detail: result.detail });
445
+ } else {
446
+ log(` ${warn("\u2717")} ${custom.label}: ${redactUrls(describeFailure(result.error))}`);
447
+ if (result.hints?.length) {
448
+ log(`
449
+ ${dim("Hints:")}`);
450
+ for (const h of result.hints) log(` ${dim("\u2022")} ${h}`);
451
+ }
452
+ entries.push({ label: custom.label, passed: false, error: result.error, hints: result.hints });
453
+ }
454
+ }
455
+ const passed = entries.every((e) => e.passed);
456
+ log("");
457
+ if (!passed) {
458
+ log(` ${warn("Some checks failed.")} Fix the issues above first.
459
+ `);
460
+ } else {
461
+ log(` ${ok("All checks passed.")}
462
+ `);
463
+ }
464
+ return { passed, checks: entries };
465
+ }
466
+ };
467
+
159
468
  // src/checks/base.ts
160
469
  var CheckSkipped = class extends Error {
161
470
  /** Distinguishes a skip from a genuine error across module boundaries. */
@@ -167,6 +476,19 @@ var CheckSkipped = class extends Error {
167
476
  function isCheckSkipped(err) {
168
477
  return err instanceof Error && err.name === "CheckSkipped";
169
478
  }
479
+ var MISSING_OBJECT_CODES = /* @__PURE__ */ new Set(["42P01", "3F000", "42883"]);
480
+ function isMissingObject(err) {
481
+ const code = err?.code;
482
+ return typeof code === "string" && MISSING_OBJECT_CODES.has(code);
483
+ }
484
+ async function readOrAbsent(read, absent) {
485
+ try {
486
+ return await read();
487
+ } catch (err) {
488
+ if (isMissingObject(err)) return absent;
489
+ throw err;
490
+ }
491
+ }
170
492
  var Check = class {
171
493
  };
172
494
 
@@ -220,11 +542,7 @@ var MigrationsCheck = class extends Check {
220
542
  return diffMigrations(local, db, mode);
221
543
  }
222
544
  async fetchDbMigrations(dbUrl) {
223
- try {
224
- return await this.queryFn(dbUrl, MIGRATIONS_SQL);
225
- } catch {
226
- return [];
227
- }
545
+ return readOrAbsent(async () => await this.queryFn(dbUrl, MIGRATIONS_SQL), []);
228
546
  }
229
547
  };
230
548
  function parseFilename(filename) {
@@ -310,24 +628,30 @@ function markAppliedSql(version, name) {
310
628
  }
311
629
 
312
630
  export {
313
- resolveConnectTimeoutMs,
314
- pgClientConfig,
315
- pgQuery,
316
- inRolledBackTransaction,
317
631
  redactUrls,
318
632
  describeFailure,
319
633
  errMsg,
320
634
  DiagnosticError,
321
635
  friendlyDbError,
636
+ pgClientConfig,
637
+ pgQuery,
638
+ inRolledBackTransaction,
639
+ DEFAULT_LOCAL_PORT,
640
+ LOCAL_PG_USER,
641
+ LOCAL_PG_PASSWORD,
642
+ startLocalPg,
643
+ checkConnection,
644
+ Preflight,
322
645
  quoteIdent,
323
646
  quoteName,
324
647
  quoteLiteral,
325
648
  sqlLiteral,
326
649
  CheckSkipped,
327
650
  isCheckSkipped,
651
+ readOrAbsent,
328
652
  Check,
329
653
  DEFAULT_MIGRATIONS_DIR,
330
654
  MigrationsCheck,
331
655
  readLocalMigrations
332
656
  };
333
- //# sourceMappingURL=chunk-X6V2GGDZ.js.map
657
+ //# sourceMappingURL=chunk-SQPCWGQO.js.map