@akal/supaforge 0.0.32 → 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.
- package/LICENSE +21 -0
- package/README.md +66 -11
- package/dist/base-command.js +4 -3
- package/dist/{chunk-DMIWAJRB.js → chunk-3WKWPSFN.js} +6 -6
- package/dist/{chunk-GZREXCQZ.js → chunk-5STH2A6K.js} +17 -10
- package/dist/{chunk-6LJERPUN.js → chunk-6ERVCWLY.js} +20 -12
- package/dist/{chunk-GEHPTPNZ.js → chunk-7DL63NWP.js} +3 -3
- package/dist/{chunk-UWAVXC57.js → chunk-DQJSSTIJ.js} +39 -15
- package/dist/{chunk-ORQJVE57.js → chunk-EFKQOQGG.js} +15 -16
- package/dist/{chunk-7NAZGZPV.js → chunk-F46FFUKC.js} +16 -17
- package/dist/chunk-GQPGH6YR.js +50 -0
- package/dist/{chunk-6Q7MHFBM.js → chunk-HNJ6BNNZ.js} +2 -2
- package/dist/{chunk-MIRLB5JM.js → chunk-ICSCHS72.js} +66 -14
- package/dist/{chunk-6WAMNZLO.js → chunk-KNXHLVF7.js} +126 -4
- package/dist/{chunk-SQPCWGQO.js → chunk-MG3SFV5J.js} +22 -121
- package/dist/{chunk-BUOWHE36.js → chunk-N5VNNOA2.js} +37 -52
- package/dist/{chunk-3HGAV5CC.js → chunk-OB5GP7UB.js} +19 -16
- package/dist/{chunk-4IVN7QVY.js → chunk-PYAGSMFB.js} +23 -15
- package/dist/{chunk-SC2XHGIS.js → chunk-S5L4A3UR.js} +3 -3
- package/dist/{chunk-2SELREHW.js → chunk-TPX2MAO4.js} +7 -9
- package/dist/{chunk-NTUASFQ3.js → chunk-V2SBZERO.js} +4 -4
- package/dist/{chunk-G2DIPIYU.js → chunk-WK5YTINL.js} +29 -2
- package/dist/{chunk-BLKJWDTL.js → chunk-ZI435CAU.js} +2 -2
- package/dist/commands/clone.js +11 -11
- package/dist/commands/diff.d.ts +13 -1
- package/dist/commands/diff.js +19 -16
- package/dist/commands/hukam.js +15 -14
- package/dist/commands/init.js +5 -1
- package/dist/commands/mcp.d.ts +1 -0
- package/dist/commands/mcp.js +26 -10
- package/dist/commands/migrate/baseline.js +5 -4
- package/dist/commands/migrate/create.js +8 -7
- package/dist/commands/migrate/list.js +6 -5
- package/dist/commands/migrate/run.js +8 -7
- package/dist/commands/report.js +5 -4
- package/dist/commands/restore.js +13 -12
- package/dist/commands/snapshot.d.ts +7 -0
- package/dist/commands/snapshot.js +36 -8
- package/dist/commands/sync.js +15 -14
- package/dist/index.js +14 -14
- package/package.json +10 -8
- package/bin/dev.js +0 -10
- package/dist/base-command.js.map +0 -1
- package/dist/chunk-2SELREHW.js.map +0 -1
- package/dist/chunk-3HGAV5CC.js.map +0 -1
- package/dist/chunk-4IVN7QVY.js.map +0 -1
- package/dist/chunk-6LJERPUN.js.map +0 -1
- package/dist/chunk-6Q7MHFBM.js.map +0 -1
- package/dist/chunk-6WAMNZLO.js.map +0 -1
- package/dist/chunk-7NAZGZPV.js.map +0 -1
- package/dist/chunk-BLKJWDTL.js.map +0 -1
- package/dist/chunk-BUOWHE36.js.map +0 -1
- package/dist/chunk-DMIWAJRB.js.map +0 -1
- package/dist/chunk-DQQ5E563.js.map +0 -1
- package/dist/chunk-G2DIPIYU.js.map +0 -1
- package/dist/chunk-GEHPTPNZ.js.map +0 -1
- package/dist/chunk-GZREXCQZ.js.map +0 -1
- package/dist/chunk-MIRLB5JM.js.map +0 -1
- package/dist/chunk-NTUASFQ3.js.map +0 -1
- package/dist/chunk-ORQJVE57.js.map +0 -1
- package/dist/chunk-SC2XHGIS.js.map +0 -1
- package/dist/chunk-SQPCWGQO.js.map +0 -1
- package/dist/chunk-UWAVXC57.js.map +0 -1
- package/dist/commands/clone.js.map +0 -1
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/help.js.map +0 -1
- package/dist/commands/hukam.js.map +0 -1
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/migrate/baseline.js.map +0 -1
- package/dist/commands/migrate/create.js.map +0 -1
- package/dist/commands/migrate/list.js.map +0 -1
- package/dist/commands/migrate/run.js.map +0 -1
- package/dist/commands/report.js.map +0 -1
- package/dist/commands/restore.js.map +0 -1
- package/dist/commands/snapshot.js.map +0 -1
- package/dist/commands/sync.js.map +0 -1
- package/dist/help.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadMigrations
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V2SBZERO.js";
|
|
4
4
|
import {
|
|
5
5
|
ensureMigrationsTable,
|
|
6
6
|
getAppliedVersions
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-S5L4A3UR.js";
|
|
8
8
|
import {
|
|
9
9
|
dropUnsupportedSetStatements,
|
|
10
10
|
knownParameters
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3WKWPSFN.js";
|
|
12
12
|
import {
|
|
13
13
|
ABSENT_ON_TARGET,
|
|
14
14
|
EXTENSION_UNAVAILABLE,
|
|
15
15
|
PLATFORM_ROLES
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-DQJSSTIJ.js";
|
|
17
17
|
import {
|
|
18
18
|
rolesNamedBy,
|
|
19
19
|
sqlSkeleton,
|
|
20
20
|
statementSubject
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-N5VNNOA2.js";
|
|
22
22
|
import {
|
|
23
23
|
isCommentOnly,
|
|
24
24
|
isPsqlMetaCommand,
|
|
25
25
|
splitSqlStatements,
|
|
26
26
|
stripPsqlMetaCommands
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-WK5YTINL.js";
|
|
28
28
|
import {
|
|
29
29
|
loadSnapshot
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-ICSCHS72.js";
|
|
31
31
|
import {
|
|
32
|
-
|
|
33
|
-
pgClientConfig,
|
|
32
|
+
newPgClient,
|
|
34
33
|
pgQuery,
|
|
35
34
|
quoteIdent,
|
|
36
35
|
quoteLiteral,
|
|
37
36
|
quoteName
|
|
38
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-MG3SFV5J.js";
|
|
39
38
|
import {
|
|
40
39
|
DEFAULT_IGNORE_SCHEMAS,
|
|
41
40
|
MIGRATIONS_TABLE,
|
|
42
|
-
SUPABASE_PLATFORM_SCHEMAS
|
|
43
|
-
|
|
41
|
+
SUPABASE_PLATFORM_SCHEMAS,
|
|
42
|
+
errMsg
|
|
43
|
+
} from "./chunk-KNXHLVF7.js";
|
|
44
44
|
|
|
45
45
|
// src/restore.ts
|
|
46
46
|
import { readFile as readFile2, access } from "fs/promises";
|
|
47
47
|
import { constants } from "fs";
|
|
48
48
|
import { join as join2 } from "path";
|
|
49
|
-
import pg from "pg";
|
|
50
49
|
|
|
51
50
|
// src/restore-data.ts
|
|
52
51
|
import { readdir, readFile } from "fs/promises";
|
|
@@ -357,7 +356,7 @@ async function resetRelationGrants(client, schemas) {
|
|
|
357
356
|
// src/restore.ts
|
|
358
357
|
async function getPublicTables(targetUrl) {
|
|
359
358
|
const ignoreList = DEFAULT_IGNORE_SCHEMAS.map((s) => `'${s}'`).join(", ");
|
|
360
|
-
const client =
|
|
359
|
+
const client = newPgClient(targetUrl);
|
|
361
360
|
await client.connect();
|
|
362
361
|
try {
|
|
363
362
|
const { rows } = await client.query(
|
|
@@ -376,7 +375,7 @@ async function restoreFromSnapshot(options) {
|
|
|
376
375
|
const result = { applied: [], skipped: [], errors: [], mode: "snapshot" };
|
|
377
376
|
const manifest = await loadSnapshot(options.snapshotDir);
|
|
378
377
|
const sqlOrder = RESTORE_SQL_ORDER;
|
|
379
|
-
const client =
|
|
378
|
+
const client = newPgClient(options.targetUrl);
|
|
380
379
|
await client.connect();
|
|
381
380
|
const transactional = !options.noTransaction;
|
|
382
381
|
if (transactional) await client.query("BEGIN");
|
|
@@ -571,7 +570,7 @@ async function restoreFromMigrations(options) {
|
|
|
571
570
|
if (options.toVersion) {
|
|
572
571
|
filtered = filtered.filter((m) => m.version <= options.toVersion);
|
|
573
572
|
}
|
|
574
|
-
const client =
|
|
573
|
+
const client = newPgClient(options.targetUrl);
|
|
575
574
|
await client.connect();
|
|
576
575
|
try {
|
|
577
576
|
await ensureMigrationsTable(options.targetUrl, queryFn);
|
|
@@ -865,4 +864,4 @@ export {
|
|
|
865
864
|
previewMigrationRestore,
|
|
866
865
|
summarizeStatement
|
|
867
866
|
};
|
|
868
|
-
//# sourceMappingURL=chunk-
|
|
867
|
+
//# sourceMappingURL=chunk-F46FFUKC.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describeFailure,
|
|
3
|
+
redactUrls
|
|
4
|
+
} from "./chunk-KNXHLVF7.js";
|
|
5
|
+
|
|
6
|
+
// src/process-guard.ts
|
|
7
|
+
var installed = false;
|
|
8
|
+
var jsonWritten = false;
|
|
9
|
+
var keepRunning = false;
|
|
10
|
+
function noteJsonWritten() {
|
|
11
|
+
jsonWritten = true;
|
|
12
|
+
}
|
|
13
|
+
function keepRunningOnStrayErrors() {
|
|
14
|
+
keepRunning = true;
|
|
15
|
+
}
|
|
16
|
+
function installProcessGuard(argv = process.argv) {
|
|
17
|
+
if (installed) return;
|
|
18
|
+
installed = true;
|
|
19
|
+
const onStray = (err) => {
|
|
20
|
+
const message = redactUrls(describeFailure(err));
|
|
21
|
+
if (keepRunning) {
|
|
22
|
+
process.stderr.write(`SupaForge: an error no handler caught, carrying on: ${message}
|
|
23
|
+
`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (argv.includes("--json") && !jsonWritten) {
|
|
27
|
+
jsonWritten = true;
|
|
28
|
+
process.stdout.write(JSON.stringify({ error: message }, null, 2) + "\n");
|
|
29
|
+
}
|
|
30
|
+
process.stderr.write(
|
|
31
|
+
`
|
|
32
|
+
Unexpected error: ${message}
|
|
33
|
+
If this looks like a bug, please report it:
|
|
34
|
+
https://github.com/akalsoftware/supaforge/issues/new
|
|
35
|
+
|
|
36
|
+
`
|
|
37
|
+
);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
process.stdout.write("", () => process.exit(1));
|
|
40
|
+
};
|
|
41
|
+
process.on("uncaughtException", onStray);
|
|
42
|
+
process.on("unhandledRejection", onStray);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
noteJsonWritten,
|
|
47
|
+
keepRunningOnStrayErrors,
|
|
48
|
+
installProcessGuard
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=chunk-GQPGH6YR.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
redactUrls
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KNXHLVF7.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/sanitize.ts
|
|
6
6
|
function sanitizeForReport(text) {
|
|
@@ -10,4 +10,4 @@ function sanitizeForReport(text) {
|
|
|
10
10
|
export {
|
|
11
11
|
sanitizeForReport
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-HNJ6BNNZ.js.map
|
|
@@ -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-
|
|
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-
|
|
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 =
|
|
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 =
|
|
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:
|
|
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
|
|
861
|
-
const functions = await res
|
|
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
|
|
923
|
-
const config = await res
|
|
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-
|
|
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
|
-
|
|
168
|
-
|
|
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
|
-
|
|
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-
|
|
458
|
+
//# sourceMappingURL=chunk-KNXHLVF7.js.map
|