@akal/supaforge 0.0.46 → 0.0.48
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/README.md +21 -11
- package/dist/base-command.js +2 -2
- package/dist/{chunk-C32M67YH.js → chunk-3XQHSJOJ.js} +3 -3
- package/dist/{chunk-YE3RQLCR.js → chunk-AMG4PVQS.js} +24 -3
- package/dist/{chunk-XBXMOGI3.js → chunk-C7VBY54T.js} +179 -41
- package/dist/{chunk-PH2PU4NS.js → chunk-D3JEYV4M.js} +6 -6
- package/dist/{chunk-CKH6J7DI.js → chunk-EPGKCP3K.js} +8 -6
- package/dist/{chunk-AJ53RPJS.js → chunk-FKL3TQB7.js} +8 -8
- package/dist/{chunk-FFRGDQMV.js → chunk-HKG4KGDV.js} +2 -2
- package/dist/{chunk-HWRRFF55.js → chunk-HZ2FKMY3.js} +2 -2
- package/dist/{chunk-LV44B3BX.js → chunk-NCMERJNX.js} +2 -2
- package/dist/{chunk-AUNVMGTR.js → chunk-PSSMJRMM.js} +39 -15
- package/dist/{chunk-BLP7UO6C.js → chunk-RXPYUFJR.js} +6 -6
- package/dist/{chunk-YDISW5X7.js → chunk-S2GQI7ZO.js} +34 -21
- package/dist/{chunk-2ELJ46KR.js → chunk-VEXHBRNW.js} +7 -7
- package/dist/{chunk-RC7ZU7OV.js → chunk-W42J6U7R.js} +3 -1
- package/dist/{chunk-67JVGG3G.js → chunk-X4L3JT4R.js} +10 -7
- package/dist/{chunk-ZBQLDCYV.js → chunk-Z3SB66RS.js} +5 -5
- package/dist/commands/clone.js +5 -5
- package/dist/commands/diff.js +9 -9
- package/dist/commands/hukam.js +9 -9
- package/dist/commands/mcp.js +8 -8
- package/dist/commands/migrate/baseline.js +3 -3
- package/dist/commands/migrate/create.js +8 -8
- package/dist/commands/migrate/list.js +3 -3
- package/dist/commands/migrate/run.js +7 -7
- package/dist/commands/report.js +2 -2
- package/dist/commands/restore.js +8 -8
- package/dist/commands/snapshot.js +5 -5
- package/dist/commands/sync.js +9 -9
- package/dist/index.js +13 -13
- package/package.json +23 -3
package/README.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# supaforge
|
|
2
2
|
|
|
3
|
-
> Diff and
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
> Diff, sync and clone Supabase and Postgres environments - and prove every change before it reaches production.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/akalsoftware/supaforge/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@akal/supaforge)
|
|
7
|
+
[](https://www.npmjs.com/package/@akal/supaforge)
|
|
8
|
+
[](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.akalsoftware/supaforge)
|
|
9
|
+
[](https://github.com/akalsoftware/supaforge/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
SupaForge compares two environments (dev and prod, say) across everything
|
|
12
|
+
that makes up a Supabase project, not just the schema. It reports every
|
|
13
|
+
difference, including the security gaps - an RLS policy that never reached
|
|
14
|
+
production, a bucket public on one side only - and makes the target match the
|
|
15
|
+
source. Fixes run in dependency order, in one transaction, and can be proved
|
|
16
|
+
on a throwaway copy before anything changes. With a single project, it
|
|
17
|
+
snapshots, restores and clones it. It works with Supabase Cloud, self-hosted
|
|
18
|
+
Supabase, local stacks and plain PostgreSQL.
|
|
10
19
|
|
|
11
20
|
- **The whole project.** It covers schema, RLS, storage, auth, Edge Functions,
|
|
12
21
|
cron, webhooks, Realtime, queues, partition sets, Vault, extensions, grants,
|
|
@@ -22,7 +31,8 @@ anything changes. With a single project, it snapshots, restores and clones it.
|
|
|
22
31
|
- **Anywhere.** It works with Supabase Cloud, self-hosted stacks, plain
|
|
23
32
|
PostgreSQL targets, CI pipelines and AI agents (MCP).
|
|
24
33
|
|
|
25
|
-
Built by [Akal](https://
|
|
34
|
+
Built by [Akal Software](https://akalsoftware.com). Website and guides:
|
|
35
|
+
[supaforge.dev](https://supaforge.dev).
|
|
26
36
|
|
|
27
37
|
## Quick start
|
|
28
38
|
|
|
@@ -44,9 +54,9 @@ Everything that writes previews first. Add `--apply` to make it happen.
|
|
|
44
54
|
| npm | `npm install -g @akal/supaforge`, or run it with `npx @akal/supaforge` |
|
|
45
55
|
| Homebrew | `brew install akalsoftware/tap/supaforge` |
|
|
46
56
|
| Docker | `docker run --rm -v "$PWD:/work" ghcr.io/akalsoftware/supaforge diff` |
|
|
47
|
-
| GitHub Actions | [`akalsoftware/supaforge-action`](https://github.com/akalsoftware/supaforge-action)
|
|
57
|
+
| GitHub Actions | [`akalsoftware/supaforge-action`](https://github.com/akalsoftware/supaforge-action) - see [CI](#ci-and-exit-codes) |
|
|
48
58
|
| VS Code and its forks | The SupaForge extension: commands, and the MCP server for the editor's agent. Each [release](https://github.com/akalsoftware/supaforge/releases/latest) carries it as a `.vsix` |
|
|
49
|
-
| Cursor, VS Code, Claude | One-click installs of the MCP server
|
|
59
|
+
| Cursor, VS Code, Claude | One-click installs of the MCP server - see [MCP](#mcp-ai-agents) |
|
|
50
60
|
|
|
51
61
|
It needs Node.js 22 or newer. DBDiff, its diff engine, comes with it as a
|
|
52
62
|
native binary for your platform, so there is nothing else to install. The
|
|
@@ -279,7 +289,7 @@ supaforge migrate run --env=prod --apply
|
|
|
279
289
|
| `SUPAFORGE_CONNECT_TIMEOUT` | `15` | Seconds to wait for a connection |
|
|
280
290
|
| `SUPAFORGE_CHECK_CONCURRENCY` | `4` | Checks run at once. Lower it behind a tight pooler |
|
|
281
291
|
| `SUPAFORGE_PROVE_ROWS` | `1000` | Rows of each table `--prove` copies to check they survive; `0` checks structure only |
|
|
282
|
-
| `SUPAFORGE_PG_BIN` | — | A directory of PostgreSQL client tools (`pg_dump`, `psql`), used ahead of `PATH
|
|
292
|
+
| `SUPAFORGE_PG_BIN` | — | A directory of PostgreSQL client tools (`pg_dump`, `psql`), used ahead of `PATH`, for a server newer than the tools on `PATH` |
|
|
283
293
|
|
|
284
294
|
## Self-hosted Supabase
|
|
285
295
|
|
package/dist/base-command.js
CHANGED
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
captureSnapshot,
|
|
3
3
|
findLatestSnapshot,
|
|
4
4
|
loadSnapshot
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-X4L3JT4R.js";
|
|
6
6
|
import {
|
|
7
7
|
isCommentOnly,
|
|
8
8
|
slugify,
|
|
9
9
|
splitSqlStatements
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-AMG4PVQS.js";
|
|
11
11
|
import {
|
|
12
12
|
MIGRATIONS_SUBDIR,
|
|
13
13
|
SUPAFORGE_DIR
|
|
@@ -243,4 +243,4 @@ export {
|
|
|
243
243
|
loadMigrations,
|
|
244
244
|
listMigrationFiles
|
|
245
245
|
};
|
|
246
|
-
//# sourceMappingURL=chunk-
|
|
246
|
+
//# sourceMappingURL=chunk-3XQHSJOJ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
newPgClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-W42J6U7R.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/sql-split.ts
|
|
6
6
|
var ROUTINE_HEAD = /^CREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE)\b/i;
|
|
@@ -354,6 +354,26 @@ function getInstallInstructions(majorVersion) {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
// src/utils/pg-env.ts
|
|
358
|
+
function pgToolConnection(url, base = process.env) {
|
|
359
|
+
let parsed;
|
|
360
|
+
try {
|
|
361
|
+
parsed = new URL(url);
|
|
362
|
+
} catch {
|
|
363
|
+
return { url, env: base };
|
|
364
|
+
}
|
|
365
|
+
if (!/^postgres(?:ql)?:$/.test(parsed.protocol)) return { url, env: base };
|
|
366
|
+
const inQuery = parsed.searchParams.get("password");
|
|
367
|
+
const password = parsed.password ? decodeURIComponent(parsed.password) : inQuery;
|
|
368
|
+
if (password === null || password === "") return { url, env: base };
|
|
369
|
+
parsed.password = "";
|
|
370
|
+
if (inQuery !== null) {
|
|
371
|
+
const rest = parsed.search.slice(1).split("&").filter((p) => !/^password(?:=|$)/.test(p));
|
|
372
|
+
parsed.search = rest.length ? `?${rest.join("&")}` : "";
|
|
373
|
+
}
|
|
374
|
+
return { url: parsed.toString(), env: { ...base, PGPASSWORD: password } };
|
|
375
|
+
}
|
|
376
|
+
|
|
357
377
|
export {
|
|
358
378
|
splitSqlStatements,
|
|
359
379
|
isCommentOnly,
|
|
@@ -370,6 +390,7 @@ export {
|
|
|
370
390
|
describeMissingPgDump,
|
|
371
391
|
getServerMajorVersion,
|
|
372
392
|
dbdiffPgToolsEnv,
|
|
373
|
-
checkPgDumpCompat
|
|
393
|
+
checkPgDumpCompat,
|
|
394
|
+
pgToolConnection
|
|
374
395
|
};
|
|
375
|
-
//# sourceMappingURL=chunk-
|
|
396
|
+
//# sourceMappingURL=chunk-AMG4PVQS.js.map
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
isCommentOnly,
|
|
8
8
|
matchesGlob,
|
|
9
9
|
parseFlagList,
|
|
10
|
+
pgToolConnection,
|
|
10
11
|
resolvePgDumpPath,
|
|
11
12
|
splitSqlStatements
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-AMG4PVQS.js";
|
|
13
14
|
import {
|
|
14
15
|
Check,
|
|
15
16
|
heldSnapshot,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
quoteLiteral,
|
|
20
21
|
quoteName,
|
|
21
22
|
snapshotsOff
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-W42J6U7R.js";
|
|
23
24
|
import {
|
|
24
25
|
DBDIFF_EXEC_TIMEOUT_MS,
|
|
25
26
|
DBDIFF_MAX_BUFFER,
|
|
@@ -156,7 +157,12 @@ var PLATFORM_ROLES = [
|
|
|
156
157
|
"supabase_functions_admin",
|
|
157
158
|
"supabase_realtime_admin",
|
|
158
159
|
"supabase_read_only_user",
|
|
159
|
-
"supabase_replication_admin"
|
|
160
|
+
"supabase_replication_admin",
|
|
161
|
+
// Newer images add these two, reserved: Supabase refuses to drop or alter
|
|
162
|
+
// them. Syncing plain PostgreSQL into such a project offered DROP ROLE for
|
|
163
|
+
// both, and the refusal rolled back the whole apply.
|
|
164
|
+
"supabase_etl_admin",
|
|
165
|
+
"supabase_privileged_role"
|
|
160
166
|
];
|
|
161
167
|
var API_ROLES = ["anon", "authenticated", "service_role"];
|
|
162
168
|
var quoted = (names2) => names2.map((n) => `'${n.replace(/'/g, "''")}'`).join(", ");
|
|
@@ -1009,37 +1015,113 @@ function withoutDropStatements(sql) {
|
|
|
1009
1015
|
if (!/\bDROP\b/i.test(sql)) return sql;
|
|
1010
1016
|
return splitSqlStatements(sql).filter((s) => !/^\s*DROP\b/i.test(sqlSkeleton(s))).join("\n");
|
|
1011
1017
|
}
|
|
1012
|
-
function
|
|
1013
|
-
const
|
|
1014
|
-
const
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1018
|
+
function orderNodes(nodes) {
|
|
1019
|
+
const n = nodes.length;
|
|
1020
|
+
const waiting = new Array(n);
|
|
1021
|
+
const dependents = Array.from({ length: n }, () => []);
|
|
1022
|
+
for (let i = 0; i < n; i++) {
|
|
1023
|
+
waiting[i] = nodes[i].after.size;
|
|
1024
|
+
for (const dep of nodes[i].after) dependents[dep].push(i);
|
|
1025
|
+
}
|
|
1026
|
+
const ranked = new MinHeap((a, b) => nodes[a].rank - nodes[b].rank || a - b);
|
|
1027
|
+
const free = new MinHeap((a, b) => nodes[a].phase - nodes[b].phase || a - b);
|
|
1028
|
+
const enqueue = (i) => (nodes[i].rank !== void 0 ? ranked : free).push(i);
|
|
1029
|
+
const sequenceLeft = /* @__PURE__ */ new Map();
|
|
1030
|
+
for (const node of nodes) {
|
|
1031
|
+
if (node.rank !== void 0 && !DROP_PHASES.has(node.phase)) {
|
|
1032
|
+
sequenceLeft.set(node.phase, (sequenceLeft.get(node.phase) ?? 0) + 1);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
const earliestInSequence = () => {
|
|
1036
|
+
let min = Infinity;
|
|
1037
|
+
for (const [phase, count] of sequenceLeft) if (count > 0 && phase < min) min = phase;
|
|
1038
|
+
return min;
|
|
1039
|
+
};
|
|
1040
|
+
const done = new Array(n).fill(false);
|
|
1041
|
+
for (let i = 0; i < n; i++) if (waiting[i] === 0) enqueue(i);
|
|
1042
|
+
let lowest = 0;
|
|
1043
|
+
const order = [];
|
|
1044
|
+
const peek = (heap) => {
|
|
1045
|
+
while (heap.size > 0 && done[heap.peek()]) heap.pop();
|
|
1046
|
+
return heap.size > 0 ? heap.peek() : void 0;
|
|
1047
|
+
};
|
|
1048
|
+
while (order.length < n) {
|
|
1049
|
+
const head = peek(ranked);
|
|
1050
|
+
const other = peek(free);
|
|
1051
|
+
let next;
|
|
1052
|
+
if (head === void 0 || other === void 0) {
|
|
1053
|
+
if (head !== void 0 || other !== void 0) {
|
|
1054
|
+
next = head ?? other;
|
|
1055
|
+
} else {
|
|
1056
|
+
while (done[lowest]) lowest++;
|
|
1057
|
+
next = lowest;
|
|
1058
|
+
}
|
|
1059
|
+
} else {
|
|
1060
|
+
next = nodes[other].phase < earliestInSequence() ? other : head;
|
|
1061
|
+
}
|
|
1062
|
+
done[next] = true;
|
|
1063
|
+
order.push(next);
|
|
1064
|
+
const node = nodes[next];
|
|
1065
|
+
if (node.rank !== void 0 && !DROP_PHASES.has(node.phase)) {
|
|
1066
|
+
sequenceLeft.set(node.phase, sequenceLeft.get(node.phase) - 1);
|
|
1067
|
+
}
|
|
1068
|
+
for (const d of dependents[next]) {
|
|
1069
|
+
if (--waiting[d] === 0 && !done[d]) enqueue(d);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return order;
|
|
1073
|
+
}
|
|
1074
|
+
var MinHeap = class {
|
|
1075
|
+
constructor(compare) {
|
|
1076
|
+
this.compare = compare;
|
|
1077
|
+
}
|
|
1078
|
+
compare;
|
|
1079
|
+
items = [];
|
|
1080
|
+
get size() {
|
|
1081
|
+
return this.items.length;
|
|
1082
|
+
}
|
|
1083
|
+
peek() {
|
|
1084
|
+
return this.items[0];
|
|
1085
|
+
}
|
|
1086
|
+
push(item) {
|
|
1087
|
+
const items = this.items;
|
|
1088
|
+
items.push(item);
|
|
1089
|
+
let i = items.length - 1;
|
|
1090
|
+
while (i > 0) {
|
|
1091
|
+
const parent = i - 1 >> 1;
|
|
1092
|
+
if (this.compare(items[i], items[parent]) >= 0) break;
|
|
1093
|
+
[items[i], items[parent]] = [items[parent], items[i]];
|
|
1094
|
+
i = parent;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
pop() {
|
|
1098
|
+
const items = this.items;
|
|
1099
|
+
const top = items[0];
|
|
1100
|
+
const last = items.pop();
|
|
1101
|
+
if (items.length > 0) {
|
|
1102
|
+
items[0] = last;
|
|
1103
|
+
let i = 0;
|
|
1104
|
+
for (; ; ) {
|
|
1105
|
+
const l = 2 * i + 1;
|
|
1106
|
+
const r = l + 1;
|
|
1107
|
+
let m = i;
|
|
1108
|
+
if (l < items.length && this.compare(items[l], items[m]) < 0) m = l;
|
|
1109
|
+
if (r < items.length && this.compare(items[r], items[m]) < 0) m = r;
|
|
1110
|
+
if (m === i) break;
|
|
1111
|
+
[items[i], items[m]] = [items[m], items[i]];
|
|
1112
|
+
i = m;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return top;
|
|
1024
1116
|
}
|
|
1025
|
-
|
|
1026
|
-
}
|
|
1117
|
+
};
|
|
1027
1118
|
function orderStatements(items, sqlOf, rankOf = () => void 0) {
|
|
1028
1119
|
if (items.length < 2) return [...items];
|
|
1029
1120
|
const texts = items.map(sqlOf);
|
|
1030
1121
|
const provides = texts.map(providedNames);
|
|
1031
1122
|
const nodes = texts.map((sql, i) => ({ phase: statementPhase(sql), rank: rankOf(items[i]), after: /* @__PURE__ */ new Set() }));
|
|
1032
1123
|
linkDependencies(nodes, texts, provides);
|
|
1033
|
-
|
|
1034
|
-
let remaining = texts.map((_, i) => i);
|
|
1035
|
-
const ordered = [];
|
|
1036
|
-
while (remaining.length > 0) {
|
|
1037
|
-
const next = nextReady(remaining, nodes, done);
|
|
1038
|
-
ordered.push(items[next]);
|
|
1039
|
-
done.add(next);
|
|
1040
|
-
remaining = remaining.filter((i) => i !== next);
|
|
1041
|
-
}
|
|
1042
|
-
return ordered;
|
|
1124
|
+
return orderNodes(nodes).map((i) => items[i]);
|
|
1043
1125
|
}
|
|
1044
1126
|
function splitQualified(identifier) {
|
|
1045
1127
|
const parts = identifier.match(/"[^"]+"|[\w$]+/g) ?? [];
|
|
@@ -1212,8 +1294,9 @@ function snapshotArgs(sourceUrl, targetUrl) {
|
|
|
1212
1294
|
function buildDbDiffArgs(options, outputFile) {
|
|
1213
1295
|
const args = [
|
|
1214
1296
|
"diff",
|
|
1215
|
-
|
|
1216
|
-
|
|
1297
|
+
// A process's arguments are readable by every user on the machine; its
|
|
1298
|
+
// environment only by its own user. See dbdiffUrlEnv().
|
|
1299
|
+
...options.urlsOnCommandLine ? [`--server1-url=${options.sourceUrl}`, `--server2-url=${options.targetUrl}`] : [],
|
|
1217
1300
|
`--type=${options.type}`,
|
|
1218
1301
|
// Was hardcoded to 'both', silently ignoring options.include. Every caller
|
|
1219
1302
|
// passes 'both' (sqlToIssues pairs each UP statement with its DOWN
|
|
@@ -1241,7 +1324,7 @@ function buildDbDiffArgs(options, outputFile) {
|
|
|
1241
1324
|
if (memoryLimit) {
|
|
1242
1325
|
args.push(`--memory-limit=${memoryLimit}`);
|
|
1243
1326
|
}
|
|
1244
|
-
if (options.type === "schema"
|
|
1327
|
+
if (options.ignoreSchemas && (options.type === "schema" || options.type === "data")) {
|
|
1245
1328
|
args.push(`--ignore-schemas=${schemaDiffIgnores(options.ignoreSchemas).join(",")}`);
|
|
1246
1329
|
}
|
|
1247
1330
|
const ignore = options.ignoreTables ?? [];
|
|
@@ -1253,6 +1336,14 @@ function buildDbDiffArgs(options, outputFile) {
|
|
|
1253
1336
|
}
|
|
1254
1337
|
return args;
|
|
1255
1338
|
}
|
|
1339
|
+
function dataScope(tables, ignoreSchemas) {
|
|
1340
|
+
if (!tables.some((t) => t.includes("."))) return { tables };
|
|
1341
|
+
return { tables: tables.map((t) => t.includes(".") ? t : `public.${t}`), ignoreSchemas };
|
|
1342
|
+
}
|
|
1343
|
+
function dbdiffUrlEnv(options) {
|
|
1344
|
+
if (options.urlsOnCommandLine) return {};
|
|
1345
|
+
return { DBDIFF_SERVER1_URL: options.sourceUrl, DBDIFF_SERVER2_URL: options.targetUrl };
|
|
1346
|
+
}
|
|
1256
1347
|
function attachProgress(running, onProgress) {
|
|
1257
1348
|
if (!onProgress) return;
|
|
1258
1349
|
try {
|
|
@@ -1290,7 +1381,7 @@ async function runDbDiff(options) {
|
|
|
1290
1381
|
const running = execFileAsync(command, args, {
|
|
1291
1382
|
timeout: timeoutMs,
|
|
1292
1383
|
maxBuffer: DBDIFF_MAX_BUFFER,
|
|
1293
|
-
|
|
1384
|
+
env: { ...process.env, ...pgTools, ...dbdiffUrlEnv(options) }
|
|
1294
1385
|
});
|
|
1295
1386
|
attachProgress(running, options.onProgress);
|
|
1296
1387
|
const { stdout } = await running;
|
|
@@ -1310,6 +1401,9 @@ async function runDbDiff(options) {
|
|
|
1310
1401
|
if (options.units !== false && /"--units" option does not exist/.test(`${combined} ${stdout}`)) {
|
|
1311
1402
|
return runDbDiff({ ...options, units: false });
|
|
1312
1403
|
}
|
|
1404
|
+
if (!options.urlsOnCommandLine && /Missing input argument/.test(`${combined} ${stdout}`)) {
|
|
1405
|
+
return runDbDiff({ ...options, urlsOnCommandLine: true });
|
|
1406
|
+
}
|
|
1313
1407
|
if (dbdiffNotInstalled(errObj.code, stderr)) {
|
|
1314
1408
|
throw new DiagnosticError(
|
|
1315
1409
|
"@dbdiff/cli is not installed. Install it with: npm install @dbdiff/cli"
|
|
@@ -1539,12 +1633,45 @@ function platformExtensionMoves(issues) {
|
|
|
1539
1633
|
});
|
|
1540
1634
|
}
|
|
1541
1635
|
var quoteIdent2 = (name) => /^[a-z_][a-z0-9_$]*$/.test(name) ? name : `"${name.replace(/"/g, '""')}"`;
|
|
1542
|
-
|
|
1543
|
-
|
|
1636
|
+
var accepts = (fn, args) => args >= fn.minArgs && args <= fn.maxArgs;
|
|
1637
|
+
function argumentCount(sql, mask, open) {
|
|
1638
|
+
let depth = 0;
|
|
1639
|
+
let commas = 0;
|
|
1640
|
+
let empty = true;
|
|
1641
|
+
for (let i = open; i < mask.length; i++) {
|
|
1642
|
+
const c = mask[i];
|
|
1643
|
+
if (c === "(" || c === "[") {
|
|
1644
|
+
depth++;
|
|
1645
|
+
if (depth > 1) empty = false;
|
|
1646
|
+
continue;
|
|
1647
|
+
}
|
|
1648
|
+
if (c === ")" || c === "]") {
|
|
1649
|
+
if (--depth === 0) return empty ? 0 : commas + 1;
|
|
1650
|
+
continue;
|
|
1651
|
+
}
|
|
1652
|
+
if (depth === 1 && c === ",") commas++;
|
|
1653
|
+
if (depth >= 1 && !/\s/.test(sql[i])) empty = false;
|
|
1654
|
+
}
|
|
1655
|
+
return void 0;
|
|
1656
|
+
}
|
|
1657
|
+
var DEFINES = /\bCREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE|AGGREGATE)\s*$/i;
|
|
1658
|
+
function withPlatformExtensionCalls(issues, moves, functions, shadows = []) {
|
|
1659
|
+
const rules = moves.flatMap((move) => (functions.get(move.name) ?? []).map((fn) => ({ move, fn })));
|
|
1544
1660
|
if (!rules.length) return issues;
|
|
1545
1661
|
const nameRe = String.raw`("(?:[^"]|"")+"|[\w$]+)`;
|
|
1546
1662
|
const call = new RegExp(String.raw`${nameRe}(\s*\.\s*)${nameRe}(?=\s*\()`, "g");
|
|
1547
1663
|
const unq = (part) => part.startsWith('"') ? part.slice(1, -1).replace(/""/g, '"') : part.toLowerCase();
|
|
1664
|
+
const defined = [...shadows];
|
|
1665
|
+
for (const issue of issues) {
|
|
1666
|
+
for (const sql of issue.sql ? [issue.sql.up, issue.sql.down] : []) {
|
|
1667
|
+
const mask = codeMask(sql);
|
|
1668
|
+
for (const m of mask.matchAll(call)) {
|
|
1669
|
+
if (!DEFINES.test(mask.slice(0, m.index))) continue;
|
|
1670
|
+
const args = argumentCount(sql, mask, mask.indexOf("(", m.index + m[0].length));
|
|
1671
|
+
if (args !== void 0) defined.push({ schema: unq(m[1]), name: unq(m[3]), minArgs: args, maxArgs: args });
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1548
1675
|
const rewrite = (sql, seen) => {
|
|
1549
1676
|
const mask = codeMask(sql);
|
|
1550
1677
|
let out = "";
|
|
@@ -1552,8 +1679,12 @@ function withPlatformExtensionCalls(issues, moves, functions) {
|
|
|
1552
1679
|
for (const m of mask.matchAll(call)) {
|
|
1553
1680
|
const schema = unq(m[1]);
|
|
1554
1681
|
const fn = unq(m[3]);
|
|
1555
|
-
|
|
1682
|
+
if (DEFINES.test(mask.slice(0, m.index))) continue;
|
|
1683
|
+
const args = argumentCount(sql, mask, mask.indexOf("(", m.index + m[0].length));
|
|
1684
|
+
if (args === void 0) continue;
|
|
1685
|
+
const rule = rules.find((r) => r.move.sourceSchema === schema && r.fn.name === fn && accepts(r.fn, args));
|
|
1556
1686
|
if (!rule) continue;
|
|
1687
|
+
if (defined.some((d) => d.schema === schema && d.name === fn && accepts(d, args))) continue;
|
|
1557
1688
|
out += sql.slice(at, m.index) + quoteIdent2(rule.move.targetSchema) + m[2] + sql.slice(m.index + m[1].length + m[2].length, m.index + m[0].length);
|
|
1558
1689
|
at = m.index + m[0].length;
|
|
1559
1690
|
seen.add(`${quoteIdent2(schema)}.${quoteIdent2(fn)}() \u2192 ${quoteIdent2(rule.move.targetSchema)}.${quoteIdent2(fn)}()`);
|
|
@@ -2923,8 +3054,10 @@ async function sampleInto(psql, fromUrl, intoUrl, schemas, limit) {
|
|
|
2923
3054
|
}
|
|
2924
3055
|
function pipeCopy(psql, fromUrl, intoUrl, out, into) {
|
|
2925
3056
|
return new Promise((resolve, reject) => {
|
|
2926
|
-
const
|
|
2927
|
-
const
|
|
3057
|
+
const reading = pgToolConnection(fromUrl);
|
|
3058
|
+
const writing = pgToolConnection(intoUrl);
|
|
3059
|
+
const reader = spawn(psql, [reading.url, "-X", "-q", "-v", "ON_ERROR_STOP=1", "-c", out], { stdio: ["ignore", "pipe", "pipe"], env: reading.env });
|
|
3060
|
+
const writer = spawn(psql, [writing.url, "-X", "-q", "-v", "ON_ERROR_STOP=1", "-f", "-"], { stdio: ["pipe", "pipe", "pipe"], env: writing.env });
|
|
2928
3061
|
let stderr = "";
|
|
2929
3062
|
reader.stderr.on("data", (d) => {
|
|
2930
3063
|
stderr += d.toString();
|
|
@@ -3202,8 +3335,9 @@ async function copyStructure(fromUrl, intoUrl, schemas, tools, migratingFrom) {
|
|
|
3202
3335
|
if (present.has(name) && !supporting.includes(name)) supporting.push(name);
|
|
3203
3336
|
}
|
|
3204
3337
|
}
|
|
3338
|
+
const from = pgToolConnection(fromUrl);
|
|
3205
3339
|
const dumpArgs = [
|
|
3206
|
-
|
|
3340
|
+
from.url,
|
|
3207
3341
|
"--schema-only",
|
|
3208
3342
|
"--no-owner",
|
|
3209
3343
|
"--no-privileges",
|
|
@@ -3211,7 +3345,8 @@ async function copyStructure(fromUrl, intoUrl, schemas, tools, migratingFrom) {
|
|
|
3211
3345
|
];
|
|
3212
3346
|
const { stdout: structure } = await exec(tools.pgDump, dumpArgs, {
|
|
3213
3347
|
maxBuffer: 256 * 1024 * 1024,
|
|
3214
|
-
timeout: 3e5
|
|
3348
|
+
timeout: 3e5,
|
|
3349
|
+
env: from.env
|
|
3215
3350
|
});
|
|
3216
3351
|
const { sql: replayable } = dropUnsupportedSetStatements(
|
|
3217
3352
|
tolerateExistingSchemas(structure),
|
|
@@ -3290,8 +3425,10 @@ function runSql(psqlPath, dbUrl, sql) {
|
|
|
3290
3425
|
const trimmed = sql.trim();
|
|
3291
3426
|
if (!trimmed) return Promise.resolve();
|
|
3292
3427
|
return new Promise((resolve, reject) => {
|
|
3293
|
-
const
|
|
3294
|
-
|
|
3428
|
+
const conn = pgToolConnection(dbUrl);
|
|
3429
|
+
const child = spawn2(psqlPath, [conn.url, "-v", "ON_ERROR_STOP=1", "-q", "-f", "-"], {
|
|
3430
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
3431
|
+
env: conn.env
|
|
3295
3432
|
});
|
|
3296
3433
|
let stderr = "";
|
|
3297
3434
|
child.stderr.on("data", (d) => {
|
|
@@ -3437,6 +3574,7 @@ export {
|
|
|
3437
3574
|
PLATFORM_ROLES,
|
|
3438
3575
|
RolesCheck,
|
|
3439
3576
|
ExtensionsCheck,
|
|
3577
|
+
dataScope,
|
|
3440
3578
|
runDbDiff,
|
|
3441
3579
|
isDestructiveSql,
|
|
3442
3580
|
destructiveReason,
|
|
@@ -3465,4 +3603,4 @@ export {
|
|
|
3465
3603
|
residualHeldBack,
|
|
3466
3604
|
proofScope
|
|
3467
3605
|
};
|
|
3468
|
-
//# sourceMappingURL=chunk-
|
|
3606
|
+
//# sourceMappingURL=chunk-C7VBY54T.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
targetFingerprint,
|
|
3
3
|
writtenAgainst
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NCMERJNX.js";
|
|
5
5
|
import {
|
|
6
6
|
ensureMigrationsTable,
|
|
7
7
|
getAppliedVersions,
|
|
8
8
|
getPendingMigrations,
|
|
9
9
|
runMigration
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HZ2FKMY3.js";
|
|
11
11
|
import {
|
|
12
12
|
isDestructiveSql
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-C7VBY54T.js";
|
|
14
14
|
import {
|
|
15
15
|
BaseCommand
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-EPGKCP3K.js";
|
|
17
17
|
import {
|
|
18
18
|
splitSqlStatements
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-AMG4PVQS.js";
|
|
20
20
|
import {
|
|
21
21
|
DEFAULT_IGNORE_SCHEMAS,
|
|
22
22
|
bold,
|
|
@@ -180,4 +180,4 @@ export {
|
|
|
180
180
|
findDestructiveStatements,
|
|
181
181
|
truncateSql
|
|
182
182
|
};
|
|
183
|
-
//# sourceMappingURL=chunk-
|
|
183
|
+
//# sourceMappingURL=chunk-D3JEYV4M.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_MIGRATIONS_DIR,
|
|
3
3
|
Preflight
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-W42J6U7R.js";
|
|
5
5
|
import {
|
|
6
6
|
installProcessGuard,
|
|
7
7
|
noteJsonWritten
|
|
@@ -22,7 +22,7 @@ import { formatWithOptions } from "util";
|
|
|
22
22
|
import { Command } from "@oclif/core";
|
|
23
23
|
|
|
24
24
|
// src/run-log.ts
|
|
25
|
-
import { readFile, writeFile, mkdir, appendFile } from "fs/promises";
|
|
25
|
+
import { readFile, writeFile, mkdir, appendFile, chmod } from "fs/promises";
|
|
26
26
|
import { homedir } from "os";
|
|
27
27
|
import { join } from "path";
|
|
28
28
|
function runLogPath() {
|
|
@@ -33,10 +33,12 @@ function runLogDir() {
|
|
|
33
33
|
}
|
|
34
34
|
async function appendRunLog(entry) {
|
|
35
35
|
const dir = runLogDir();
|
|
36
|
-
await mkdir(dir, { recursive: true });
|
|
36
|
+
await mkdir(dir, { recursive: true, mode: 448 });
|
|
37
37
|
const path = runLogPath();
|
|
38
38
|
const line = JSON.stringify(entry) + "\n";
|
|
39
|
-
await appendFile(path, line, "utf8");
|
|
39
|
+
await appendFile(path, line, { encoding: "utf8", mode: 384 });
|
|
40
|
+
await chmod(path, 384).catch(() => {
|
|
41
|
+
});
|
|
40
42
|
pruneRunLog(path).catch(() => {
|
|
41
43
|
});
|
|
42
44
|
}
|
|
@@ -60,7 +62,7 @@ async function pruneRunLog(path) {
|
|
|
60
62
|
const lines = raw.split("\n").filter(Boolean);
|
|
61
63
|
if (lines.length <= RUN_LOG_MAX_ENTRIES) return;
|
|
62
64
|
const trimmed = lines.slice(lines.length - RUN_LOG_MAX_ENTRIES);
|
|
63
|
-
await writeFile(path, trimmed.join("\n") + "\n", "utf8");
|
|
65
|
+
await writeFile(path, trimmed.join("\n") + "\n", { encoding: "utf8", mode: 384 });
|
|
64
66
|
} catch {
|
|
65
67
|
}
|
|
66
68
|
}
|
|
@@ -211,4 +213,4 @@ export {
|
|
|
211
213
|
readRunLog,
|
|
212
214
|
BaseCommand
|
|
213
215
|
};
|
|
214
|
-
//# sourceMappingURL=chunk-
|
|
216
|
+
//# sourceMappingURL=chunk-EPGKCP3K.js.map
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
formatSkips,
|
|
7
7
|
renderDetailed,
|
|
8
8
|
renderSummary
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-HKG4KGDV.js";
|
|
10
10
|
import {
|
|
11
11
|
createDefaultRegistry,
|
|
12
12
|
proveBeforeApply,
|
|
13
13
|
scan,
|
|
14
14
|
summarizeByKind
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-PSSMJRMM.js";
|
|
16
16
|
import {
|
|
17
17
|
CHECK_META,
|
|
18
18
|
CHECK_NAMES,
|
|
@@ -24,17 +24,17 @@ import {
|
|
|
24
24
|
psqlBeside,
|
|
25
25
|
resolveTableFilter,
|
|
26
26
|
withDatabase
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-C7VBY54T.js";
|
|
28
28
|
import {
|
|
29
29
|
renderTip
|
|
30
30
|
} from "./chunk-RQCXGO37.js";
|
|
31
31
|
import {
|
|
32
32
|
BaseCommand
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-EPGKCP3K.js";
|
|
34
34
|
import {
|
|
35
35
|
isCloneDatabase,
|
|
36
36
|
sourceLooksLikeCloneOf
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-S2GQI7ZO.js";
|
|
38
38
|
import {
|
|
39
39
|
describeMissingPgDump,
|
|
40
40
|
getServerMajorVersion,
|
|
@@ -42,12 +42,12 @@ import {
|
|
|
42
42
|
parseFlagList,
|
|
43
43
|
resolvePgDumpPath,
|
|
44
44
|
splitSqlStatements
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-AMG4PVQS.js";
|
|
46
46
|
import {
|
|
47
47
|
Preflight,
|
|
48
48
|
pgQuery,
|
|
49
49
|
quoteName
|
|
50
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-W42J6U7R.js";
|
|
51
51
|
import {
|
|
52
52
|
CLONE_SKIP_FLAGS,
|
|
53
53
|
DEFAULT_IGNORE_SCHEMAS,
|
|
@@ -754,4 +754,4 @@ export {
|
|
|
754
754
|
inertApplyFlags,
|
|
755
755
|
Diff
|
|
756
756
|
};
|
|
757
|
-
//# sourceMappingURL=chunk-
|
|
757
|
+
//# sourceMappingURL=chunk-FKL3TQB7.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHECK_META,
|
|
3
3
|
isComparisonCheck
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-C7VBY54T.js";
|
|
5
5
|
import {
|
|
6
6
|
CHECK_LINE_PADDING,
|
|
7
7
|
bold,
|
|
@@ -241,4 +241,4 @@ export {
|
|
|
241
241
|
renderDetailed,
|
|
242
242
|
formatSkips
|
|
243
243
|
};
|
|
244
|
-
//# sourceMappingURL=chunk-
|
|
244
|
+
//# sourceMappingURL=chunk-HKG4KGDV.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pgQuery,
|
|
3
3
|
readLocalMigrations
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-W42J6U7R.js";
|
|
5
5
|
import {
|
|
6
6
|
MIGRATIONS_SCHEMA,
|
|
7
7
|
MIGRATIONS_TABLE
|
|
@@ -119,4 +119,4 @@ export {
|
|
|
119
119
|
runMigration,
|
|
120
120
|
baselineMigrations
|
|
121
121
|
};
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
122
|
+
//# sourceMappingURL=chunk-HZ2FKMY3.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
comparedSchemas,
|
|
3
3
|
fingerprint
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-C7VBY54T.js";
|
|
5
5
|
|
|
6
6
|
// src/written-against.ts
|
|
7
7
|
import { createHash } from "crypto";
|
|
@@ -24,4 +24,4 @@ export {
|
|
|
24
24
|
writtenAgainstLine,
|
|
25
25
|
writtenAgainst
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-NCMERJNX.js.map
|