@akal/supaforge 0.0.33 → 0.0.34

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 (39) hide show
  1. package/README.md +39 -2
  2. package/dist/base-command.js +4 -3
  3. package/dist/{chunk-DMIWAJRB.js → chunk-3WKWPSFN.js} +6 -6
  4. package/dist/{chunk-GZREXCQZ.js → chunk-5STH2A6K.js} +17 -10
  5. package/dist/{chunk-6LJERPUN.js → chunk-6ERVCWLY.js} +20 -12
  6. package/dist/{chunk-GEHPTPNZ.js → chunk-7DL63NWP.js} +3 -3
  7. package/dist/{chunk-UWAVXC57.js → chunk-DQJSSTIJ.js} +39 -15
  8. package/dist/{chunk-ORQJVE57.js → chunk-EFKQOQGG.js} +15 -16
  9. package/dist/{chunk-7NAZGZPV.js → chunk-F46FFUKC.js} +16 -17
  10. package/dist/chunk-GQPGH6YR.js +50 -0
  11. package/dist/{chunk-6Q7MHFBM.js → chunk-HNJ6BNNZ.js} +2 -2
  12. package/dist/{chunk-MIRLB5JM.js → chunk-ICSCHS72.js} +66 -14
  13. package/dist/{chunk-6WAMNZLO.js → chunk-KNXHLVF7.js} +126 -4
  14. package/dist/{chunk-SQPCWGQO.js → chunk-MG3SFV5J.js} +22 -121
  15. package/dist/{chunk-BUOWHE36.js → chunk-N5VNNOA2.js} +37 -52
  16. package/dist/{chunk-3HGAV5CC.js → chunk-OB5GP7UB.js} +19 -16
  17. package/dist/{chunk-4IVN7QVY.js → chunk-PYAGSMFB.js} +23 -15
  18. package/dist/{chunk-SC2XHGIS.js → chunk-S5L4A3UR.js} +3 -3
  19. package/dist/{chunk-2SELREHW.js → chunk-TPX2MAO4.js} +7 -9
  20. package/dist/{chunk-NTUASFQ3.js → chunk-V2SBZERO.js} +4 -4
  21. package/dist/{chunk-G2DIPIYU.js → chunk-WK5YTINL.js} +29 -2
  22. package/dist/{chunk-BLKJWDTL.js → chunk-ZI435CAU.js} +2 -2
  23. package/dist/commands/clone.js +11 -11
  24. package/dist/commands/diff.d.ts +13 -1
  25. package/dist/commands/diff.js +19 -16
  26. package/dist/commands/hukam.js +15 -14
  27. package/dist/commands/init.js +5 -1
  28. package/dist/commands/mcp.js +15 -9
  29. package/dist/commands/migrate/baseline.js +5 -4
  30. package/dist/commands/migrate/create.js +8 -7
  31. package/dist/commands/migrate/list.js +6 -5
  32. package/dist/commands/migrate/run.js +8 -7
  33. package/dist/commands/report.js +5 -4
  34. package/dist/commands/restore.js +13 -12
  35. package/dist/commands/snapshot.d.ts +7 -0
  36. package/dist/commands/snapshot.js +36 -8
  37. package/dist/commands/sync.js +15 -14
  38. package/dist/index.js +14 -14
  39. package/package.json +2 -2
@@ -3,15 +3,16 @@ import {
3
3
  } from "./chunk-DQQ5E563.js";
4
4
  import {
5
5
  Check,
6
- errMsg,
7
6
  inRolledBackTransaction,
7
+ newPgClient,
8
+ newPgPool,
8
9
  pgClientConfig,
9
10
  pgQuery,
10
11
  quoteIdent,
11
12
  quoteLiteral,
12
13
  quoteName,
13
14
  readOrAbsent
14
- } from "./chunk-SQPCWGQO.js";
15
+ } from "./chunk-MG3SFV5J.js";
15
16
  import {
16
17
  DEFAULT_IGNORE_SCHEMAS,
17
18
  MIGRATIONS_SUBDIR,
@@ -21,15 +22,15 @@ import {
21
22
  SUPABASE_PLATFORM_SCHEMAS,
22
23
  SUPAFORGE_DIR,
23
24
  dim,
25
+ errMsg,
24
26
  ok,
25
27
  warn
26
- } from "./chunk-6WAMNZLO.js";
28
+ } from "./chunk-KNXHLVF7.js";
27
29
 
28
30
  // src/pg-tools.ts
29
31
  import { execFile } from "child_process";
30
32
  import { platform } from "os";
31
33
  import { existsSync } from "fs";
32
- import pg from "pg";
33
34
  function parsePgDumpVersion(output) {
34
35
  const m = output.match(/(\d+)(?:\.\d+)?/);
35
36
  return m ? Number(m[1]) : null;
@@ -90,6 +91,14 @@ async function resolvePgDumpPath(serverMajor) {
90
91
  }
91
92
  return null;
92
93
  }
94
+ function assertPgBinUsable() {
95
+ const named = process.env.SUPAFORGE_PG_BIN?.trim();
96
+ if (named && !existsSync(`${named}/pg_dump`)) {
97
+ throw new Error(
98
+ `SUPAFORGE_PG_BIN is set to "${named}", which has no pg_dump. Point it at a directory of PostgreSQL client tools, or unset it to use the ones on PATH.`
99
+ );
100
+ }
101
+ }
93
102
  async function describeMissingPgDump(neededMajor) {
94
103
  const onPath = await getLocalPgDumpVersion();
95
104
  const named = process.env.SUPAFORGE_PG_BIN?.trim();
@@ -112,7 +121,7 @@ function versionsToCheck(required) {
112
121
  return versions;
113
122
  }
114
123
  async function getServerMajorVersion(dbUrl) {
115
- const client = new pg.Client(pgClientConfig(dbUrl));
124
+ const client = newPgClient(dbUrl);
116
125
  try {
117
126
  await client.connect();
118
127
  const { rows } = await client.query("SHOW server_version");
@@ -194,14 +203,13 @@ import { execFile as execFileCb } from "child_process";
194
203
  import { promisify } from "util";
195
204
 
196
205
  // src/schema-introspect.ts
197
- import pg2 from "pg";
198
206
  async function introspectSchema(dbUrl, ignoreSchemas, clientQueryFn) {
199
207
  let queryFn;
200
208
  let pool;
201
209
  if (clientQueryFn) {
202
210
  queryFn = clientQueryFn;
203
211
  } else {
204
- pool = new pg2.Pool({ ...pgClientConfig(dbUrl), max: 6 });
212
+ pool = newPgPool({ ...pgClientConfig(dbUrl), max: 6 });
205
213
  queryFn = async (sql, params) => {
206
214
  const { rows } = await pool.query(sql, params);
207
215
  return rows;
@@ -695,6 +703,39 @@ function diffPublications(source, target) {
695
703
  return issues;
696
704
  }
697
705
 
706
+ // src/utils/http.ts
707
+ function httpStatus(res) {
708
+ return [res.status, res.statusText].filter(Boolean).join(" ") || "with no status";
709
+ }
710
+ async function readJson(res, what) {
711
+ try {
712
+ return await res.json();
713
+ } catch {
714
+ throw new Error(`${what} answered HTTP ${httpStatus(res)} with a body that is not JSON`);
715
+ }
716
+ }
717
+ async function readJsonArray(res, what) {
718
+ const value = await readJson(res, what);
719
+ if (!Array.isArray(value)) throw new Error(`${what} answered with ${shapeOf(value)} where a list was expected`);
720
+ return value;
721
+ }
722
+ async function readJsonObject(res, what) {
723
+ const value = await readJson(res, what);
724
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
725
+ throw new Error(`${what} answered with ${shapeOf(value)} where an object was expected`);
726
+ }
727
+ return value;
728
+ }
729
+ function shapeOf(value) {
730
+ if (value === null) return "null";
731
+ if (Array.isArray(value)) return "a list";
732
+ if (typeof value === "object") {
733
+ const message = value.message;
734
+ return typeof message === "string" ? `an object saying "${message.slice(0, 120)}"` : "an object";
735
+ }
736
+ return `a ${typeof value}`;
737
+ }
738
+
698
739
  // src/snapshot.ts
699
740
  var execFile2 = promisify(execFileCb);
700
741
  function generateTimestamp() {
@@ -707,6 +748,7 @@ function snapshotDir(cwd, timestamp) {
707
748
  return join(snapshotsBaseDir(cwd), timestamp);
708
749
  }
709
750
  async function captureSnapshot(options) {
751
+ assertPgBinUsable();
710
752
  const cwd = options.cwd ?? process.cwd();
711
753
  const timestamp = generateTimestamp();
712
754
  const dir = options.outputDir ? join(resolve(options.outputDir), timestamp) : snapshotDir(cwd, timestamp);
@@ -738,11 +780,17 @@ async function captureSnapshot(options) {
738
780
  await writeFile(join(dir, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
739
781
  return { manifest, dir, timestamp };
740
782
  }
783
+ function unrestorableSchema(manifest) {
784
+ const schema = manifest.layers.schema;
785
+ return schema?.captured && schema.sqlSkipReason ? schema.sqlSkipReason : void 0;
786
+ }
741
787
  function formatSnapshotLayers(manifest) {
742
788
  const layers = manifest.layers;
743
789
  const lines = [];
744
790
  for (const [name, info] of Object.entries(layers)) {
745
- if (info.captured) {
791
+ if (info.captured && info.sqlSkipReason) {
792
+ lines.push(`${warn("\u26A0")} ${name.padEnd(16)} ${info.itemCount} item(s) ${warn(`\u2014 no schema.sql, so restore cannot recreate the schema: ${info.sqlSkipReason}`)}`);
793
+ } else if (info.captured) {
746
794
  lines.push(`${ok("\u2713")} ${name.padEnd(16)} ${info.itemCount} item(s)`);
747
795
  } else if (info.error) {
748
796
  lines.push(`${warn("\u2717")} ${name.padEnd(16)} ${warn(`error: ${info.error}`)}`);
@@ -801,7 +849,7 @@ async function captureSchemaSql(dir, dbUrl, schemas) {
801
849
  const resolved = await resolvePgDumpPath(serverMajor);
802
850
  if (!resolved) {
803
851
  return {
804
- sqlSkipReason: `no pg_dump new enough for this server (needs ${serverMajor} or later) \u2014 schema.json was still captured, but restore cannot replay the schema`
852
+ sqlSkipReason: `${await describeMissingPgDump(serverMajor)} \u2014 schema.json was still captured, but restore cannot replay the schema`
805
853
  };
806
854
  }
807
855
  const { stdout } = await execFile2(resolved.path, [
@@ -857,8 +905,8 @@ async function captureEdgeFunctions(dir, env, fetchFn) {
857
905
  const res = await fetchFn(url, {
858
906
  headers: { Authorization: `Bearer ${token}` }
859
907
  });
860
- if (!res.ok) throw new Error(res.statusText);
861
- const functions = await res.json();
908
+ if (!res.ok) throw new Error(`HTTP ${httpStatus(res)}`);
909
+ const functions = await readJsonArray(res, "The Edge Function list");
862
910
  await writeFile(join(dir, file), JSON.stringify(functions, null, 2) + "\n");
863
911
  return { captured: true, file, itemCount: functions.length };
864
912
  } catch (err) {
@@ -919,8 +967,8 @@ async function captureAuthConfig(dir, env, fetchFn) {
919
967
  const res = await fetchFn(url, {
920
968
  headers: { Authorization: `Bearer ${token}` }
921
969
  });
922
- if (!res.ok) throw new Error(res.statusText);
923
- const config = await res.json();
970
+ if (!res.ok) throw new Error(`HTTP ${httpStatus(res)}`);
971
+ const config = await readJsonObject(res, "The auth config");
924
972
  await writeFile(join(dir, file), JSON.stringify(config, null, 2) + "\n");
925
973
  return { captured: true, file, itemCount: Object.keys(config).length };
926
974
  } catch (err) {
@@ -1276,12 +1324,16 @@ export {
1276
1324
  diffSchemaPolicies,
1277
1325
  defaultCanonicalizer,
1278
1326
  dropEquivalentPolicyChanges,
1327
+ httpStatus,
1328
+ readJsonArray,
1329
+ readJsonObject,
1279
1330
  RealtimeCheck,
1280
1331
  resolvePgDumpPath,
1281
1332
  describeMissingPgDump,
1282
1333
  getServerMajorVersion,
1283
1334
  checkPgDumpCompat,
1284
1335
  captureSnapshot,
1336
+ unrestorableSchema,
1285
1337
  formatSnapshotLayers,
1286
1338
  loadSnapshot,
1287
1339
  findLatestSnapshot,
@@ -1289,4 +1341,4 @@ export {
1289
1341
  DEFAULT_KEEP_COUNT,
1290
1342
  pruneSnapshots
1291
1343
  };
1292
- //# sourceMappingURL=chunk-MIRLB5JM.js.map
1344
+ //# sourceMappingURL=chunk-ICSCHS72.js.map
@@ -1,3 +1,111 @@
1
+ // src/utils/error.ts
2
+ var DB_URL_RE = /\b((?:postgres(?:ql)?|mysql|mariadb):\/\/)(\S+)/g;
3
+ function redactUrls(message) {
4
+ return message.replace(DB_URL_RE, (_, scheme, rest) => {
5
+ const lastAt = rest.lastIndexOf("@");
6
+ if (lastAt === -1) return scheme + rest;
7
+ const creds = rest.slice(0, lastAt);
8
+ const hostPart = rest.slice(lastAt);
9
+ const colonIdx = creds.indexOf(":");
10
+ if (colonIdx === -1) return scheme + rest;
11
+ return scheme + creds.slice(0, colonIdx) + ":***" + hostPart;
12
+ });
13
+ }
14
+ var UNDESCRIBED_ERROR = "unknown error \u2014 no message reported";
15
+ function describeFailure(err) {
16
+ if (typeof err === "string") return err.trim() || UNDESCRIBED_ERROR;
17
+ const candidate = err;
18
+ const message = typeof candidate?.message === "string" ? candidate.message.trim() : "";
19
+ if (message) return message;
20
+ const code = typeof candidate?.code === "string" ? candidate.code.trim() : "";
21
+ if (code) return `${code} (no further detail reported)`;
22
+ const name = typeof candidate?.name === "string" ? candidate.name.trim() : "";
23
+ if (name && name !== "Error") return `${name} (no further detail reported)`;
24
+ if (err !== null && err !== void 0 && !(err instanceof Error)) {
25
+ const rendered = String(err).trim();
26
+ if (rendered && rendered !== "[object Object]") return rendered;
27
+ }
28
+ return UNDESCRIBED_ERROR;
29
+ }
30
+ function errMsg(err) {
31
+ return redactUrls(describeFailure(err));
32
+ }
33
+ var DiagnosticError = class extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = "DiagnosticError";
37
+ }
38
+ };
39
+ function isDiagnosticError(err) {
40
+ return err instanceof DiagnosticError || err instanceof Error && err.name === "DiagnosticError";
41
+ }
42
+ var CONNECTION_ERROR_PATTERNS = [
43
+ {
44
+ test: (m) => /ECONNREFUSED|Connection refused/i.test(m),
45
+ build: (host) => `Cannot connect to PostgreSQL at ${host} \u2014 the server does not appear to be running. Start it and try again.`
46
+ },
47
+ {
48
+ test: (m) => /ENOTFOUND|getaddrinfo/i.test(m),
49
+ build: (host) => `Cannot resolve hostname ${host} \u2014 check the database URL in your config.`
50
+ },
51
+ {
52
+ // Before the connection timeout: the server answered, and a query ran
53
+ // past its statement_timeout. Calling that a connection problem sent
54
+ // people to check a host and port that were fine.
55
+ test: (m) => /canceling statement due to statement timeout|57014/i.test(m),
56
+ 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.`
57
+ },
58
+ {
59
+ // Deliberately narrow. A bare /timeout/i also matches our own remediation
60
+ // text — "set SUPAFORGE_DBDIFF_TIMEOUT=600" contains "TIMEOUT" — which is
61
+ // how an accurate "Schema diff timed out after Ns" message was being
62
+ // rewritten into a wrong "check the host and port" one (issue #29).
63
+ // DiagnosticError below is the primary guard; this is defence in depth.
64
+ test: (m) => /ETIMEDOUT|connection timed out|timeout expired/i.test(m),
65
+ build: (host) => `Connection to ${host} timed out \u2014 verify the host and port are correct and that the server is reachable.`
66
+ },
67
+ {
68
+ test: (m) => /password authentication failed/i.test(m),
69
+ build: (host) => `Authentication failed for ${host} \u2014 check the username and password in your database URL.`
70
+ },
71
+ {
72
+ // Must stay anchored to "database ... does not exist" (Postgres SQLSTATE
73
+ // 3D000). A bare /does not exist/ is the same trap as the timeout pattern
74
+ // above: it matched dbdiff's own CLI complaint — The "--allow-destructive"
75
+ // option does not exist — and rewrote it into "Database does not exist on
76
+ // 127.0.0.1:5432", sending you off to check a database name that was fine
77
+ // while the real cause (an outdated @dbdiff/cli) went unmentioned.
78
+ test: (m) => /database\s+"[^"]*"\s+does not exist|3D000/i.test(m),
79
+ build: (host) => `Database does not exist on ${host} \u2014 verify the database name in your config.`
80
+ },
81
+ {
82
+ test: (m) => /SSL.*required|no pg_hba.conf entry/i.test(m),
83
+ build: (host) => `Connection rejected by ${host} \u2014 the server requires SSL or your IP is not allowed. Check pg_hba.conf and SSL settings.`
84
+ }
85
+ ];
86
+ function extractHost(dbUrl) {
87
+ try {
88
+ const url = new URL(dbUrl);
89
+ return url.port ? `${url.hostname}:${url.port}` : url.hostname;
90
+ } catch {
91
+ return "the configured host";
92
+ }
93
+ }
94
+ function friendlyDbError(err, dbUrl) {
95
+ const raw = errMsg(err);
96
+ if (isDiagnosticError(err)) return raw;
97
+ const host = dbUrl ? extractHost(dbUrl) : "the configured host";
98
+ for (const pattern of CONNECTION_ERROR_PATTERNS) {
99
+ try {
100
+ if (pattern.test(raw)) {
101
+ return pattern.build(host);
102
+ }
103
+ } catch {
104
+ }
105
+ }
106
+ return raw;
107
+ }
108
+
1
109
  // src/defaults.ts
2
110
  var DEFAULT_IGNORE_SCHEMAS = [
3
111
  "auth",
@@ -164,13 +272,22 @@ async function loadConfig(cwd = process.cwd()) {
164
272
  await loadEnvFiles(cwd);
165
273
  const configPath = resolve2(cwd, CONFIG_FILENAME);
166
274
  const raw = await readFile2(configPath, "utf-8");
167
- const config = JSON.parse(raw);
168
- return resolveConfig(config);
275
+ let parsed;
276
+ try {
277
+ parsed = JSON.parse(raw);
278
+ } catch (err) {
279
+ throw new Error(`${CONFIG_FILENAME} is not valid JSON: ${errMsg(err)}`);
280
+ }
281
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
282
+ throw new Error(`${CONFIG_FILENAME} must hold a JSON object, with an "environments" object inside`);
283
+ }
284
+ return resolveConfig(parsed);
169
285
  }
170
286
  function resolveConfig(config) {
171
287
  return {
172
288
  ...config,
173
- environments: expandEnvironments(config.environments),
289
+ // Missing, it is validateConfig's to report, not a crash here.
290
+ environments: expandEnvironments(config.environments ?? {}),
174
291
  ignoreSchemas: config.ignoreSchemas ?? DEFAULT_IGNORE_SCHEMAS
175
292
  };
176
293
  }
@@ -285,6 +402,11 @@ function printBanner(log) {
285
402
  }
286
403
 
287
404
  export {
405
+ redactUrls,
406
+ describeFailure,
407
+ errMsg,
408
+ DiagnosticError,
409
+ friendlyDbError,
288
410
  DEFAULT_IGNORE_SCHEMAS,
289
411
  SUPABASE_PLATFORM_SCHEMAS,
290
412
  schemaDiffIgnores,
@@ -333,4 +455,4 @@ export {
333
455
  printHints,
334
456
  printBanner
335
457
  };
336
- //# sourceMappingURL=chunk-6WAMNZLO.js.map
458
+ //# sourceMappingURL=chunk-KNXHLVF7.js.map
@@ -7,118 +7,12 @@ import {
7
7
  RUNTIME_DETECT_TIMEOUT_MS,
8
8
  bold,
9
9
  cmd,
10
+ describeFailure,
10
11
  dim,
11
12
  ok,
13
+ redactUrls,
12
14
  warn
13
- } from "./chunk-6WAMNZLO.js";
14
-
15
- // src/utils/error.ts
16
- var DB_URL_RE = /\b((?:postgres(?:ql)?|mysql|mariadb):\/\/)(\S+)/g;
17
- function redactUrls(message) {
18
- return message.replace(DB_URL_RE, (_, scheme, rest) => {
19
- const lastAt = rest.lastIndexOf("@");
20
- if (lastAt === -1) return scheme + rest;
21
- const creds = rest.slice(0, lastAt);
22
- const hostPart = rest.slice(lastAt);
23
- const colonIdx = creds.indexOf(":");
24
- if (colonIdx === -1) return scheme + rest;
25
- return scheme + creds.slice(0, colonIdx) + ":***" + hostPart;
26
- });
27
- }
28
- var UNDESCRIBED_ERROR = "unknown error \u2014 no message reported";
29
- function describeFailure(err) {
30
- if (typeof err === "string") return err.trim() || UNDESCRIBED_ERROR;
31
- const candidate = err;
32
- const message = typeof candidate?.message === "string" ? candidate.message.trim() : "";
33
- if (message) return message;
34
- const code = typeof candidate?.code === "string" ? candidate.code.trim() : "";
35
- if (code) return `${code} (no further detail reported)`;
36
- const name = typeof candidate?.name === "string" ? candidate.name.trim() : "";
37
- if (name && name !== "Error") return `${name} (no further detail reported)`;
38
- if (err !== null && err !== void 0 && !(err instanceof Error)) {
39
- const rendered = String(err).trim();
40
- if (rendered && rendered !== "[object Object]") return rendered;
41
- }
42
- return UNDESCRIBED_ERROR;
43
- }
44
- function errMsg(err) {
45
- return redactUrls(describeFailure(err));
46
- }
47
- var DiagnosticError = class extends Error {
48
- constructor(message) {
49
- super(message);
50
- this.name = "DiagnosticError";
51
- }
52
- };
53
- function isDiagnosticError(err) {
54
- return err instanceof DiagnosticError || err instanceof Error && err.name === "DiagnosticError";
55
- }
56
- var CONNECTION_ERROR_PATTERNS = [
57
- {
58
- test: (m) => /ECONNREFUSED|Connection refused/i.test(m),
59
- build: (host) => `Cannot connect to PostgreSQL at ${host} \u2014 the server does not appear to be running. Start it and try again.`
60
- },
61
- {
62
- test: (m) => /ENOTFOUND|getaddrinfo/i.test(m),
63
- build: (host) => `Cannot resolve hostname ${host} \u2014 check the database URL in your config.`
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
- },
72
- {
73
- // Deliberately narrow. A bare /timeout/i also matches our own remediation
74
- // text — "set SUPAFORGE_DBDIFF_TIMEOUT=600" contains "TIMEOUT" — which is
75
- // how an accurate "Schema diff timed out after Ns" message was being
76
- // rewritten into a wrong "check the host and port" one (issue #29).
77
- // DiagnosticError below is the primary guard; this is defence in depth.
78
- test: (m) => /ETIMEDOUT|connection timed out|timeout expired/i.test(m),
79
- build: (host) => `Connection to ${host} timed out \u2014 verify the host and port are correct and that the server is reachable.`
80
- },
81
- {
82
- test: (m) => /password authentication failed/i.test(m),
83
- build: (host) => `Authentication failed for ${host} \u2014 check the username and password in your database URL.`
84
- },
85
- {
86
- // Must stay anchored to "database ... does not exist" (Postgres SQLSTATE
87
- // 3D000). A bare /does not exist/ is the same trap as the timeout pattern
88
- // above: it matched dbdiff's own CLI complaint — The "--allow-destructive"
89
- // option does not exist — and rewrote it into "Database does not exist on
90
- // 127.0.0.1:5432", sending you off to check a database name that was fine
91
- // while the real cause (an outdated @dbdiff/cli) went unmentioned.
92
- test: (m) => /database\s+"[^"]*"\s+does not exist|3D000/i.test(m),
93
- build: (host) => `Database does not exist on ${host} \u2014 verify the database name in your config.`
94
- },
95
- {
96
- test: (m) => /SSL.*required|no pg_hba.conf entry/i.test(m),
97
- build: (host) => `Connection rejected by ${host} \u2014 the server requires SSL or your IP is not allowed. Check pg_hba.conf and SSL settings.`
98
- }
99
- ];
100
- function extractHost(dbUrl) {
101
- try {
102
- const url = new URL(dbUrl);
103
- return url.port ? `${url.hostname}:${url.port}` : url.hostname;
104
- } catch {
105
- return "the configured host";
106
- }
107
- }
108
- function friendlyDbError(err, dbUrl) {
109
- const raw = errMsg(err);
110
- if (isDiagnosticError(err)) return raw;
111
- const host = dbUrl ? extractHost(dbUrl) : "the configured host";
112
- for (const pattern of CONNECTION_ERROR_PATTERNS) {
113
- try {
114
- if (pattern.test(raw)) {
115
- return pattern.build(host);
116
- }
117
- } catch {
118
- }
119
- }
120
- return raw;
121
- }
15
+ } from "./chunk-KNXHLVF7.js";
122
16
 
123
17
  // src/db.ts
124
18
  import pg from "pg";
@@ -140,17 +34,29 @@ function pgClientConfig(dbUrl, queryTimeoutMs) {
140
34
  }
141
35
  return config;
142
36
  }
37
+ function newPgClient(dbUrl, queryTimeoutMs) {
38
+ const client = new pg.Client(pgClientConfig(dbUrl, queryTimeoutMs));
39
+ client.on("error", () => void 0);
40
+ return client;
41
+ }
42
+ function newPgPool(config) {
43
+ const pool = new pg.Pool(config);
44
+ pool.on("error", () => void 0);
45
+ pool.on("connect", (client) => {
46
+ client.on("error", () => void 0);
47
+ });
48
+ return pool;
49
+ }
143
50
  var pools = /* @__PURE__ */ new Map();
144
51
  var POOL_MAX = 4;
145
52
  function poolFor(dbUrl) {
146
53
  const existing = pools.get(dbUrl);
147
54
  if (existing) return existing;
148
- const pool = new pg.Pool({
55
+ const pool = newPgPool({
149
56
  ...pgClientConfig(dbUrl),
150
57
  max: POOL_MAX,
151
58
  allowExitOnIdle: true
152
59
  });
153
- pool.on("error", () => void 0);
154
60
  pools.set(dbUrl, pool);
155
61
  return pool;
156
62
  }
@@ -175,7 +81,6 @@ async function inRolledBackTransaction(dbUrl, fn) {
175
81
  // src/local-pg.ts
176
82
  import { execFile } from "child_process";
177
83
  import { promisify } from "util";
178
- import pg2 from "pg";
179
84
  var defaultExecFile = promisify(execFile);
180
85
  var PG_IMAGE = "docker.io/library/postgres:17";
181
86
  var DEFAULT_LOCAL_PORT = 5432;
@@ -185,7 +90,7 @@ var LOCAL_PG_PASSWORD = "postgres";
185
90
  var READINESS_RETRIES = 30;
186
91
  var READINESS_INTERVAL_MS = 2e3;
187
92
  async function defaultConnectFn(url) {
188
- const client = new pg2.Client(pgClientConfig(url));
93
+ const client = newPgClient(url);
189
94
  await client.connect();
190
95
  await client.end();
191
96
  }
@@ -294,7 +199,6 @@ function sleep(ms) {
294
199
  }
295
200
 
296
201
  // src/preflight.ts
297
- import pg3 from "pg";
298
202
  var SUPABASE_LOCAL_PORT = "54322";
299
203
  var DEFAULT_PG_PORT = "5432";
300
204
  var CONNECT_TIMEOUT_RE = /timeout expired|connection timeout/i;
@@ -312,7 +216,7 @@ async function checkConnection(dbUrl) {
312
216
  const connectTimeoutMs = resolveConnectTimeoutMs();
313
217
  let client;
314
218
  try {
315
- client = new pg3.Client(pgClientConfig(dbUrl, DB_PROBE_TIMEOUT_MS));
219
+ client = newPgClient(dbUrl, DB_PROBE_TIMEOUT_MS);
316
220
  await client.connect();
317
221
  const { rows } = await client.query("SHOW server_version");
318
222
  const version = rows[0].server_version;
@@ -628,12 +532,9 @@ function markAppliedSql(version, name) {
628
532
  }
629
533
 
630
534
  export {
631
- redactUrls,
632
- describeFailure,
633
- errMsg,
634
- DiagnosticError,
635
- friendlyDbError,
636
535
  pgClientConfig,
536
+ newPgClient,
537
+ newPgPool,
637
538
  pgQuery,
638
539
  inRolledBackTransaction,
639
540
  DEFAULT_LOCAL_PORT,
@@ -654,4 +555,4 @@ export {
654
555
  MigrationsCheck,
655
556
  readLocalMigrations
656
557
  };
657
- //# sourceMappingURL=chunk-SQPCWGQO.js.map
558
+ //# sourceMappingURL=chunk-MG3SFV5J.js.map