@akal/supaforge 0.0.34 → 0.0.35
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 +28 -12
- package/dist/base-command.d.ts +1 -1
- package/dist/base-command.js +2 -2
- package/dist/{branch-C4ndfoj5.d.ts → branch-BppjQBv_.d.ts} +1 -1
- package/dist/{chunk-PYAGSMFB.js → chunk-44UVQJV2.js} +146 -13
- package/dist/{chunk-OB5GP7UB.js → chunk-4AGJRRBT.js} +376 -32
- package/dist/{chunk-MG3SFV5J.js → chunk-4M6OQLPO.js} +1 -1
- package/dist/{chunk-TPX2MAO4.js → chunk-5Q6LSLA3.js} +53 -4
- package/dist/{chunk-F46FFUKC.js → chunk-7N63OPFN.js} +20 -12
- package/dist/chunk-AGONS5JJ.js +242 -0
- package/dist/{chunk-7DL63NWP.js → chunk-H2D3YSKM.js} +6 -2
- package/dist/{chunk-3WKWPSFN.js → chunk-NEM5AEPQ.js} +171 -21
- package/dist/{chunk-6ERVCWLY.js → chunk-NX2KKUS7.js} +6 -6
- package/dist/{chunk-S5L4A3UR.js → chunk-O5ERC2SE.js} +2 -2
- package/dist/{chunk-ICSCHS72.js → chunk-SM7HP6EP.js} +10 -180
- package/dist/{chunk-N5VNNOA2.js → chunk-T7GMPGUO.js} +578 -16
- package/dist/{chunk-DQJSSTIJ.js → chunk-WNTCZM2J.js} +4 -476
- package/dist/{chunk-5STH2A6K.js → chunk-XLZCX6R2.js} +2 -2
- package/dist/{chunk-EFKQOQGG.js → chunk-YWERIWFD.js} +6 -4
- package/dist/{chunk-V2SBZERO.js → chunk-YZM76W22.js} +3 -3
- package/dist/commands/clone.d.ts +2 -2
- package/dist/commands/clone.js +7 -6
- package/dist/commands/diff.d.ts +24 -22
- package/dist/commands/diff.js +11 -11
- package/dist/commands/hukam.d.ts +2 -3
- package/dist/commands/hukam.js +11 -11
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/mcp.js +8 -8
- package/dist/commands/migrate/baseline.d.ts +1 -1
- package/dist/commands/migrate/baseline.js +3 -3
- package/dist/commands/migrate/create.d.ts +1 -1
- package/dist/commands/migrate/create.js +12 -7
- package/dist/commands/migrate/list.d.ts +1 -1
- package/dist/commands/migrate/list.js +3 -3
- package/dist/commands/migrate/run.d.ts +4 -1
- package/dist/commands/migrate/run.js +7 -6
- package/dist/commands/report.d.ts +1 -1
- package/dist/commands/report.js +2 -2
- package/dist/commands/restore.d.ts +1 -1
- package/dist/commands/restore.js +10 -10
- package/dist/commands/snapshot.d.ts +1 -1
- package/dist/commands/snapshot.js +5 -5
- package/dist/commands/sync.d.ts +2 -3
- package/dist/commands/sync.js +11 -11
- package/dist/{config-CTbeRlJk.d.ts → config-l3ggjw9r.d.ts} +2 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.js +13 -13
- package/package.json +2 -2
- package/dist/chunk-DQQ5E563.js +0 -64
|
@@ -1,472 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
bareName,
|
|
3
|
-
createdPolicies,
|
|
4
|
-
createdTriggers,
|
|
5
|
-
createsOnlyPolicies,
|
|
6
|
-
createsOnlyTriggers,
|
|
7
|
-
destructiveReason,
|
|
8
|
-
identifierMatcher,
|
|
9
|
-
orderStatements,
|
|
10
|
-
parseStatements,
|
|
11
|
-
referencedTables,
|
|
12
|
-
sqlSkeleton
|
|
13
|
-
} from "./chunk-N5VNNOA2.js";
|
|
14
|
-
import {
|
|
15
|
-
isCommentOnly,
|
|
16
|
-
splitSqlStatements
|
|
17
|
-
} from "./chunk-WK5YTINL.js";
|
|
18
|
-
import {
|
|
19
|
-
globToRegExp,
|
|
20
|
-
matchesGlob,
|
|
21
|
-
parseFlagList
|
|
22
|
-
} from "./chunk-DQQ5E563.js";
|
|
23
1
|
import {
|
|
24
2
|
Check,
|
|
25
|
-
newPgClient,
|
|
26
3
|
pgQuery,
|
|
27
4
|
quoteName
|
|
28
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4M6OQLPO.js";
|
|
29
6
|
import {
|
|
30
|
-
SUPABASE_PLATFORM_SCHEMAS
|
|
31
|
-
errMsg
|
|
7
|
+
SUPABASE_PLATFORM_SCHEMAS
|
|
32
8
|
} from "./chunk-KNXHLVF7.js";
|
|
33
9
|
|
|
34
|
-
// src/utils/table-filter.ts
|
|
35
|
-
var parseTableList = parseFlagList;
|
|
36
|
-
function resolveTableFilter(config, cli = {}) {
|
|
37
|
-
const cliTables = parseTableList(cli.tables);
|
|
38
|
-
const cliExclude = parseTableList(cli.excludeTables);
|
|
39
|
-
const configTables = Array.isArray(config?.checks?.tables) ? config.checks.tables : [];
|
|
40
|
-
const configExclude = Array.isArray(config?.checks?.excludeTables) ? config.checks.excludeTables : [];
|
|
41
|
-
const tables = cliTables.length > 0 ? cliTables : parseTableList(configTables);
|
|
42
|
-
const excludeTables = [.../* @__PURE__ */ new Set([...parseTableList(configExclude), ...cliExclude])];
|
|
43
|
-
const filter = {};
|
|
44
|
-
if (tables.length > 0) filter.tables = tables;
|
|
45
|
-
if (excludeTables.length > 0) filter.excludeTables = excludeTables;
|
|
46
|
-
return filter;
|
|
47
|
-
}
|
|
48
|
-
function isFiltered(filter) {
|
|
49
|
-
return Boolean(filter?.tables?.length || filter?.excludeTables?.length);
|
|
50
|
-
}
|
|
51
|
-
function describeTableFilter(filter) {
|
|
52
|
-
if (!isFiltered(filter)) return null;
|
|
53
|
-
const parts = [];
|
|
54
|
-
if (filter?.tables?.length) parts.push(`only ${filter.tables.join(", ")}`);
|
|
55
|
-
if (filter?.excludeTables?.length) parts.push(`excluding ${filter.excludeTables.join(", ")}`);
|
|
56
|
-
return `Scoped to ${parts.join(", ")} \u2014 applies to the schema and data checks; other layers are unfiltered.`;
|
|
57
|
-
}
|
|
58
|
-
function matchesPattern(name, pattern) {
|
|
59
|
-
const candidates = [name.toLowerCase()];
|
|
60
|
-
const dot = name.indexOf(".");
|
|
61
|
-
if (dot !== -1) candidates.push(name.slice(dot + 1).toLowerCase());
|
|
62
|
-
const rx = globToRegExp(pattern.toLowerCase());
|
|
63
|
-
return candidates.some((c) => rx.test(c));
|
|
64
|
-
}
|
|
65
|
-
function applyTableFilter(names, filter) {
|
|
66
|
-
if (!isFiltered(filter)) return names;
|
|
67
|
-
let out = names;
|
|
68
|
-
if (filter?.tables?.length) {
|
|
69
|
-
out = out.filter((n) => filter.tables.some((p) => matchesPattern(n, p)));
|
|
70
|
-
}
|
|
71
|
-
if (filter?.excludeTables?.length) {
|
|
72
|
-
out = out.filter((n) => !filter.excludeTables.some((p) => matchesPattern(n, p)));
|
|
73
|
-
}
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// src/types/drift.ts
|
|
78
|
-
var CHECK_NAMES = [
|
|
79
|
-
"schema",
|
|
80
|
-
"rls",
|
|
81
|
-
"rls-coverage",
|
|
82
|
-
"edge-functions",
|
|
83
|
-
"storage",
|
|
84
|
-
"auth",
|
|
85
|
-
"cron",
|
|
86
|
-
"data",
|
|
87
|
-
"webhooks",
|
|
88
|
-
"realtime",
|
|
89
|
-
"vault",
|
|
90
|
-
"extensions",
|
|
91
|
-
"migrations",
|
|
92
|
-
"roles"
|
|
93
|
-
];
|
|
94
|
-
var CHECK_META = {
|
|
95
|
-
"schema": { number: 1, emoji: "\u{1F5C4}\uFE0F", label: "Schema" },
|
|
96
|
-
"rls": { number: 2, emoji: "\u{1F512}", label: "RLS Policies" },
|
|
97
|
-
"rls-coverage": { number: 3, emoji: "\u{1F6E1}\uFE0F", label: "RLS Coverage" },
|
|
98
|
-
"edge-functions": { number: 4, emoji: "\u26A1", label: "Edge Functions" },
|
|
99
|
-
"storage": { number: 5, emoji: "\u{1FAA3}", label: "Storage" },
|
|
100
|
-
"auth": { number: 6, emoji: "\u{1F511}", label: "Auth Config" },
|
|
101
|
-
"cron": { number: 7, emoji: "\u23F0", label: "Cron Jobs" },
|
|
102
|
-
"data": { number: 8, emoji: "\u{1F5C3}\uFE0F", label: "Reference Data" },
|
|
103
|
-
"webhooks": { number: 9, emoji: "\u26A1\u{1F517}", label: "Webhooks" },
|
|
104
|
-
"realtime": { number: 10, emoji: "\u{1F4E1}", label: "Realtime Publications" },
|
|
105
|
-
"vault": { number: 11, emoji: "\u{1F510}", label: "Vault Secrets" },
|
|
106
|
-
"extensions": { number: 12, emoji: "\u{1F9E9}", label: "Postgres Extensions" },
|
|
107
|
-
"migrations": { number: 13, emoji: "\u{1F4CB}", label: "Migration History" },
|
|
108
|
-
"roles": { number: 14, emoji: "\u{1F464}", label: "Postgres Roles & Grants" }
|
|
109
|
-
};
|
|
110
|
-
var CHECK_KIND = {
|
|
111
|
-
"schema": "comparison",
|
|
112
|
-
"rls": "comparison",
|
|
113
|
-
"rls-coverage": "posture",
|
|
114
|
-
"edge-functions": "comparison",
|
|
115
|
-
"storage": "comparison",
|
|
116
|
-
"auth": "comparison",
|
|
117
|
-
"cron": "comparison",
|
|
118
|
-
"data": "comparison",
|
|
119
|
-
"webhooks": "comparison",
|
|
120
|
-
"realtime": "comparison",
|
|
121
|
-
"vault": "comparison",
|
|
122
|
-
"extensions": "comparison",
|
|
123
|
-
"migrations": "posture",
|
|
124
|
-
"roles": "comparison"
|
|
125
|
-
};
|
|
126
|
-
function isComparisonCheck(name) {
|
|
127
|
-
return CHECK_KIND[name] === "comparison";
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/pg-errors.ts
|
|
131
|
-
var ABSENT_ON_TARGET = /* @__PURE__ */ new Set(["42P01", "42883", "3F000", "42704"]);
|
|
132
|
-
var UNDEFINED_COLUMN = "42703";
|
|
133
|
-
var EXTENSION_UNAVAILABLE = /* @__PURE__ */ new Set(["0A000", "58P01"]);
|
|
134
|
-
function sqlState(err) {
|
|
135
|
-
const code = err?.code;
|
|
136
|
-
return typeof code === "string" ? code : void 0;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/promote.ts
|
|
140
|
-
function outOfScopeReason(sql, filter) {
|
|
141
|
-
if (!isFiltered(filter)) return null;
|
|
142
|
-
const referenced = referencedTables(sql);
|
|
143
|
-
if (referenced.length === 0) return null;
|
|
144
|
-
const excluded = referenced.filter((t) => applyTableFilter([t], filter).length === 0);
|
|
145
|
-
if (excluded.length === 0) return null;
|
|
146
|
-
const names = excluded.map((t) => `'${t}'`).join(", ");
|
|
147
|
-
const flag = filter?.tables?.length ? "--tables" : "--exclude-tables";
|
|
148
|
-
const noun = excluded.length === 1 ? "table" : "tables";
|
|
149
|
-
return `Depends on ${noun} ${names}, excluded by ${flag}`;
|
|
150
|
-
}
|
|
151
|
-
function isSelected(issueId, only) {
|
|
152
|
-
if (!only?.length) return true;
|
|
153
|
-
return only.some((pattern) => matchesGlob(issueId, pattern));
|
|
154
|
-
}
|
|
155
|
-
function withDefaultGrantRevokes(scanResult, only) {
|
|
156
|
-
if (!only?.length) return only;
|
|
157
|
-
const issues = scanResult.checks.flatMap((c) => c.issues);
|
|
158
|
-
const created = new Set(issues.filter((i) => i.sql?.up && isSelected(i.id, only)).flatMap((i) => relationsCreatedBy(i.sql.up)));
|
|
159
|
-
if (created.size === 0) return only;
|
|
160
|
-
const companions = issues.filter((i) => i.id.startsWith("roles-grant-default-") && [...created].some((rel) => rel.endsWith("(") ? i.id.toLowerCase().includes(`.${rel}`) : i.id.toLowerCase().endsWith(`.${rel}`))).map((i) => i.id);
|
|
161
|
-
return [...only, ...companions];
|
|
162
|
-
}
|
|
163
|
-
function relationsCreatedBy(sql) {
|
|
164
|
-
const statements = parseStatements(sql);
|
|
165
|
-
if (!statements) return [];
|
|
166
|
-
return statements.flatMap(({ kind, node }) => {
|
|
167
|
-
if (kind === "CreateFunctionStmt") {
|
|
168
|
-
const parts = (node.funcname ?? []).map((n) => n.String?.sval ?? "");
|
|
169
|
-
const name = parts.at(-1);
|
|
170
|
-
return name ? [`${(parts.length > 1 ? parts.at(-2) : "public").toLowerCase()}.${name.toLowerCase()}(`] : [];
|
|
171
|
-
}
|
|
172
|
-
const rel = kind === "CreateStmt" ? node.relation : kind === "ViewStmt" ? node.view : kind === "CreateTableAsStmt" ? node.into?.rel : void 0;
|
|
173
|
-
return rel?.relname ? [`${(rel.schemaname || "public").toLowerCase()}.${String(rel.relname).toLowerCase()}`] : [];
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
function classifyIssue(issue, options, recreatedPolicies = /* @__PURE__ */ new Set()) {
|
|
177
|
-
if (!isSelected(issue.id, options.only)) {
|
|
178
|
-
return { kind: "skip", reason: "Not selected by --only" };
|
|
179
|
-
}
|
|
180
|
-
if (issue.manualOnly) return { kind: "skip", reason: issue.manualOnly };
|
|
181
|
-
if (!issue.sql?.up) {
|
|
182
|
-
if (issue.action?.method === "DELETE" && !options.allowDestructive) {
|
|
183
|
-
return { kind: "skip", reason: `Destructive \u2014 ${issue.action.label}; re-run with --allow-destructive to apply` };
|
|
184
|
-
}
|
|
185
|
-
if (issue.action) return { kind: "api", action: issue.action };
|
|
186
|
-
return { kind: "skip", reason: issue.manualOnly ?? "No SQL fix or API action available" };
|
|
187
|
-
}
|
|
188
|
-
if (!options.allowDestructive) {
|
|
189
|
-
const why = issue.destructive ?? destructiveReason(issue.sql.up, recreatedPolicies);
|
|
190
|
-
if (why) {
|
|
191
|
-
return { kind: "skip", reason: `Destructive \u2014 ${why}; re-run with --allow-destructive to apply` };
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const outOfScope = outOfScopeReason(issue.sql.up, options.tableFilter);
|
|
195
|
-
if (outOfScope) return { kind: "skip", reason: outOfScope };
|
|
196
|
-
return { kind: "sql", sql: issue.sql.up };
|
|
197
|
-
}
|
|
198
|
-
function policiesCreatedBySelectedFixes(checks, options) {
|
|
199
|
-
const created = /* @__PURE__ */ new Set();
|
|
200
|
-
for (const check of checks) {
|
|
201
|
-
const askedForExplicitly = options.checks?.includes(check.check) ?? false;
|
|
202
|
-
if (!isComparisonCheck(check.check) && !options.applyPosture && !askedForExplicitly) continue;
|
|
203
|
-
for (const issue of check.issues) {
|
|
204
|
-
const sql = issue.sql?.up;
|
|
205
|
-
if (!sql || !isSelected(issue.id, options.only)) continue;
|
|
206
|
-
if (!options.allowDestructive && destructiveReason(sql)) continue;
|
|
207
|
-
if (outOfScopeReason(sql, options.tableFilter)) continue;
|
|
208
|
-
for (const key of createdPolicies(sql)) created.add(key);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return created;
|
|
212
|
-
}
|
|
213
|
-
function planWork(scanResult, options = {}) {
|
|
214
|
-
options = { ...options, only: withDefaultGrantRevokes(scanResult, options.only) };
|
|
215
|
-
const plan = { sqlStatements: [], apiActions: [], skipped: [] };
|
|
216
|
-
const relevant = scanResult.checks.filter(
|
|
217
|
-
(c) => c.status === "drifted" && (!options.checks || options.checks.includes(c.check))
|
|
218
|
-
);
|
|
219
|
-
const recreatedPolicies = policiesCreatedBySelectedFixes(relevant, options);
|
|
220
|
-
const keptBack = [];
|
|
221
|
-
for (const checkResult of relevant) {
|
|
222
|
-
const askedForExplicitly = options.checks?.includes(checkResult.check) ?? false;
|
|
223
|
-
if (!isComparisonCheck(checkResult.check) && !options.applyPosture && !askedForExplicitly) {
|
|
224
|
-
for (const issue of checkResult.issues) {
|
|
225
|
-
plan.skipped.push({
|
|
226
|
-
check: checkResult.check,
|
|
227
|
-
issueId: issue.id,
|
|
228
|
-
reason: "Posture finding about the target, not drift from the source \u2014 applying it would create drift. Use --apply-posture to apply anyway."
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
for (const issue of checkResult.issues) {
|
|
234
|
-
const at = { check: checkResult.check, issueId: issue.id };
|
|
235
|
-
const outcome = classifyIssue(issue, options, recreatedPolicies);
|
|
236
|
-
if (outcome.kind === "sql") plan.sqlStatements.push({ ...at, sql: outcome.sql });
|
|
237
|
-
else if (outcome.kind === "api") plan.apiActions.push({ ...at, action: outcome.action });
|
|
238
|
-
else {
|
|
239
|
-
plan.skipped.push({ ...at, reason: outcome.reason });
|
|
240
|
-
if (outcome.reason.startsWith("Destructive") && issue.sql?.down) {
|
|
241
|
-
keptBack.push({ issueId: issue.id, definition: issue.sql.down });
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
plan.sqlStatements = holdBackDropsStillInUse(plan.sqlStatements, keptBack, plan.skipped, downsOf(relevant));
|
|
247
|
-
const dbdiffOrder = new Map(plan.sqlStatements.filter((s) => s.check === "schema").map((s, i) => [s, i]));
|
|
248
|
-
plan.sqlStatements = orderStatements(plan.sqlStatements, (s) => s.sql, (s) => dbdiffOrder.get(s));
|
|
249
|
-
plan.sqlStatements = dropDuplicateObjectFixes(plan.sqlStatements, plan.skipped);
|
|
250
|
-
return plan;
|
|
251
|
-
}
|
|
252
|
-
var DROPS_SUPPORTING_OBJECT = /^\s*DROP\s+(?:TYPE|DOMAIN|FUNCTION|PROCEDURE|ROUTINE|SEQUENCE)\s+(?:IF\s+EXISTS\s+)?((?:"[^"]+"|[\w$]+)(?:\s*\.\s*(?:"[^"]+"|[\w$]+))?)/i;
|
|
253
|
-
function holdBackDropsStillInUse(statements, keptBack, skipped, downs = /* @__PURE__ */ new Map()) {
|
|
254
|
-
const kept = keptBack.map((k) => ({ issueId: k.issueId, skeleton: sqlSkeleton(k.definition) }));
|
|
255
|
-
let remaining = statements;
|
|
256
|
-
for (let changed = kept.length > 0; changed; ) {
|
|
257
|
-
changed = false;
|
|
258
|
-
remaining = remaining.filter((statement) => {
|
|
259
|
-
const names = droppedSupportingObjects(statement.sql);
|
|
260
|
-
if (names.length === 0) return true;
|
|
261
|
-
const user = kept.find((k) => names.some((n) => identifierMatcher(bareName(n)).test(k.skeleton)));
|
|
262
|
-
if (!user) return true;
|
|
263
|
-
skipped.push({
|
|
264
|
-
check: statement.check,
|
|
265
|
-
issueId: statement.issueId,
|
|
266
|
-
reason: `Still used by what ${user.issueId} keeps, which is held back as destructive; re-run with --allow-destructive to apply both`
|
|
267
|
-
});
|
|
268
|
-
const definition = downs.get(statement.issueId);
|
|
269
|
-
if (definition) kept.push({ issueId: user.issueId, skeleton: sqlSkeleton(definition) });
|
|
270
|
-
changed = true;
|
|
271
|
-
return false;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
return remaining;
|
|
275
|
-
}
|
|
276
|
-
function droppedSupportingObjects(sql) {
|
|
277
|
-
const parts = splitSqlStatements(sql).filter((s) => !isCommentOnly(s));
|
|
278
|
-
const names = parts.map((s) => DROPS_SUPPORTING_OBJECT.exec(sqlSkeleton(s))?.[1]);
|
|
279
|
-
return names.length > 0 && names.every((n) => n !== void 0) ? names : [];
|
|
280
|
-
}
|
|
281
|
-
function downsOf(checks) {
|
|
282
|
-
const downs = /* @__PURE__ */ new Map();
|
|
283
|
-
for (const check of checks) {
|
|
284
|
-
for (const issue of check.issues) {
|
|
285
|
-
if (issue.sql?.down) downs.set(issue.id, issue.sql.down);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return downs;
|
|
289
|
-
}
|
|
290
|
-
function dropDuplicateObjectFixes(statements, skipped) {
|
|
291
|
-
const kinds = [
|
|
292
|
-
{ what: "policy", created: createdPolicies, onlyThis: createsOnlyPolicies, seen: /* @__PURE__ */ new Set() },
|
|
293
|
-
{ what: "trigger", created: createdTriggers, onlyThis: createsOnlyTriggers, seen: /* @__PURE__ */ new Set() }
|
|
294
|
-
];
|
|
295
|
-
const kept = [];
|
|
296
|
-
for (const statement of statements) {
|
|
297
|
-
const duplicate = kinds.find((kind) => {
|
|
298
|
-
const names = kind.created(statement.sql);
|
|
299
|
-
return names.length > 0 && names.every((n) => kind.seen.has(n)) && kind.onlyThis(statement.sql);
|
|
300
|
-
});
|
|
301
|
-
if (duplicate) {
|
|
302
|
-
skipped.push({
|
|
303
|
-
check: statement.check,
|
|
304
|
-
issueId: statement.issueId,
|
|
305
|
-
reason: `Already created by the schema fix for the same ${duplicate.what}`
|
|
306
|
-
});
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
for (const kind of kinds) {
|
|
310
|
-
for (const name of kind.created(statement.sql)) kind.seen.add(name);
|
|
311
|
-
}
|
|
312
|
-
kept.push(statement);
|
|
313
|
-
}
|
|
314
|
-
return kept;
|
|
315
|
-
}
|
|
316
|
-
async function executeSql(dbUrl, statements, result, transactional) {
|
|
317
|
-
if (statements.length === 0) return;
|
|
318
|
-
const client = newPgClient(dbUrl);
|
|
319
|
-
await client.connect();
|
|
320
|
-
try {
|
|
321
|
-
if (transactional) await runInTransaction(client, statements, result);
|
|
322
|
-
else await runIndependently(client, statements, result);
|
|
323
|
-
} finally {
|
|
324
|
-
await client.end();
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
async function runLikeApply(dbUrl, statements) {
|
|
328
|
-
const result = { applied: [], skipped: [], errors: [] };
|
|
329
|
-
await executeSql(dbUrl, statements, result, true);
|
|
330
|
-
return result;
|
|
331
|
-
}
|
|
332
|
-
async function runIndependently(client, statements, result) {
|
|
333
|
-
for (const stmt of statements) {
|
|
334
|
-
try {
|
|
335
|
-
await client.query(stmt.sql);
|
|
336
|
-
result.applied.push({ check: stmt.check, issueId: stmt.issueId, sql: stmt.sql });
|
|
337
|
-
} catch (err) {
|
|
338
|
-
result.errors.push({ check: stmt.check, issueId: stmt.issueId, error: errMsg(err) });
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function isEnumValueAddition(sql) {
|
|
343
|
-
const statements = splitSqlStatements(sql).filter((s) => !isCommentOnly(s));
|
|
344
|
-
return statements.length > 0 && statements.every((s) => /^\s*ALTER\s+TYPE\s+\S+\s+ADD\s+VALUE\b/i.test(sqlSkeleton(s)));
|
|
345
|
-
}
|
|
346
|
-
async function runInTransaction(client, statements, result) {
|
|
347
|
-
const additions = statements.filter((s) => isEnumValueAddition(s.sql));
|
|
348
|
-
const rest = statements.filter((s) => !isEnumValueAddition(s.sql));
|
|
349
|
-
if (additions.length > 0 && !await runBatch(client, additions, result)) return;
|
|
350
|
-
await runBatch(client, rest, result);
|
|
351
|
-
}
|
|
352
|
-
function unmetDependency(sql, err) {
|
|
353
|
-
const code = sqlState(err);
|
|
354
|
-
if (!code) return void 0;
|
|
355
|
-
if (/^\s*CREATE\s+EXTENSION\b/i.test(sqlSkeleton(sql))) {
|
|
356
|
-
return EXTENSION_UNAVAILABLE.has(code) ? "this server does not ship it" : void 0;
|
|
357
|
-
}
|
|
358
|
-
if (ABSENT_ON_TARGET.has(code) || code === UNDEFINED_COLUMN) {
|
|
359
|
-
return "it needs something the target does not have";
|
|
360
|
-
}
|
|
361
|
-
return void 0;
|
|
362
|
-
}
|
|
363
|
-
async function runBatch(client, statements, result) {
|
|
364
|
-
if (statements.length === 0) return true;
|
|
365
|
-
const done = [];
|
|
366
|
-
await client.query("BEGIN");
|
|
367
|
-
let pending = statements;
|
|
368
|
-
let unmet = [];
|
|
369
|
-
while (pending.length > 0) {
|
|
370
|
-
unmet = [];
|
|
371
|
-
for (const stmt of pending) {
|
|
372
|
-
await client.query("SAVEPOINT sf_fix");
|
|
373
|
-
try {
|
|
374
|
-
await client.query(stmt.sql);
|
|
375
|
-
await client.query("RELEASE SAVEPOINT sf_fix");
|
|
376
|
-
done.push({ check: stmt.check, issueId: stmt.issueId, sql: stmt.sql });
|
|
377
|
-
} catch (err) {
|
|
378
|
-
const why = unmetDependency(stmt.sql, err);
|
|
379
|
-
if (why && await client.query("ROLLBACK TO SAVEPOINT sf_fix").then(() => true, () => false)) {
|
|
380
|
-
unmet.push({ stmt, err, why });
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
await client.query("ROLLBACK").catch(() => {
|
|
384
|
-
});
|
|
385
|
-
result.errors.push({ check: stmt.check, issueId: stmt.issueId, error: errMsg(err) });
|
|
386
|
-
result.rolledBack = [...result.rolledBack ?? [], ...done];
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (unmet.length === pending.length) break;
|
|
391
|
-
pending = unmet.map((u) => u.stmt);
|
|
392
|
-
}
|
|
393
|
-
await client.query("COMMIT");
|
|
394
|
-
result.applied.push(...done);
|
|
395
|
-
for (const { stmt, err, why } of unmet) {
|
|
396
|
-
result.errors.push({
|
|
397
|
-
check: stmt.check,
|
|
398
|
-
issueId: stmt.issueId,
|
|
399
|
-
error: `${errMsg(err)} \u2014 not applied: ${why}. The other fixes were.`
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
async function executeApiActions(actions, fetchFn, result) {
|
|
405
|
-
for (const act of actions) {
|
|
406
|
-
try {
|
|
407
|
-
const init = {
|
|
408
|
-
method: act.action.method,
|
|
409
|
-
headers: { "Content-Type": "application/json", ...act.action.headers }
|
|
410
|
-
};
|
|
411
|
-
if (act.action.body !== void 0) {
|
|
412
|
-
init.body = JSON.stringify(act.action.body);
|
|
413
|
-
}
|
|
414
|
-
const res = await fetchFn(act.action.url, init);
|
|
415
|
-
if (!res.ok) {
|
|
416
|
-
const text = await res.text().catch(() => res.statusText);
|
|
417
|
-
throw new Error(`${act.action.method} ${act.action.url} \u2192 ${res.status}: ${text}`);
|
|
418
|
-
}
|
|
419
|
-
result.applied.push({ check: act.check, issueId: act.issueId, action: act.action.label });
|
|
420
|
-
} catch (err) {
|
|
421
|
-
result.errors.push({ check: act.check, issueId: act.issueId, error: errMsg(err) });
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
async function promote(options) {
|
|
426
|
-
const {
|
|
427
|
-
dbUrl,
|
|
428
|
-
scanResult,
|
|
429
|
-
checks,
|
|
430
|
-
dryRun = false,
|
|
431
|
-
allowDestructive = false,
|
|
432
|
-
tableFilter,
|
|
433
|
-
only,
|
|
434
|
-
applyPosture = false,
|
|
435
|
-
transactional = true,
|
|
436
|
-
fetchFn = globalThis.fetch.bind(globalThis)
|
|
437
|
-
} = options;
|
|
438
|
-
const { sqlStatements, apiActions, skipped } = planWork(scanResult, {
|
|
439
|
-
checks,
|
|
440
|
-
allowDestructive,
|
|
441
|
-
tableFilter,
|
|
442
|
-
only,
|
|
443
|
-
applyPosture
|
|
444
|
-
});
|
|
445
|
-
const result = { applied: [], skipped, errors: [] };
|
|
446
|
-
if (dryRun) {
|
|
447
|
-
for (const stmt of sqlStatements) {
|
|
448
|
-
result.applied.push({ check: stmt.check, issueId: stmt.issueId, sql: stmt.sql });
|
|
449
|
-
}
|
|
450
|
-
for (const act of apiActions) {
|
|
451
|
-
result.applied.push({ check: act.check, issueId: act.issueId, action: act.action.label });
|
|
452
|
-
}
|
|
453
|
-
return result;
|
|
454
|
-
}
|
|
455
|
-
await executeSql(dbUrl, sqlStatements, result, transactional);
|
|
456
|
-
if (result.rolledBack) {
|
|
457
|
-
for (const act of apiActions) {
|
|
458
|
-
result.skipped.push({
|
|
459
|
-
check: act.check,
|
|
460
|
-
issueId: act.issueId,
|
|
461
|
-
reason: "Not attempted \u2014 the SQL fixes were rolled back"
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
return result;
|
|
465
|
-
}
|
|
466
|
-
await executeApiActions(apiActions, fetchFn, result);
|
|
467
|
-
return result;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
10
|
// src/checks/roles.ts
|
|
471
11
|
var PLATFORM_ROLES = [
|
|
472
12
|
"postgres",
|
|
@@ -922,19 +462,7 @@ function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set()) {
|
|
|
922
462
|
}
|
|
923
463
|
|
|
924
464
|
export {
|
|
925
|
-
resolveTableFilter,
|
|
926
|
-
isFiltered,
|
|
927
|
-
describeTableFilter,
|
|
928
|
-
applyTableFilter,
|
|
929
|
-
CHECK_NAMES,
|
|
930
|
-
CHECK_META,
|
|
931
|
-
isComparisonCheck,
|
|
932
465
|
PLATFORM_ROLES,
|
|
933
|
-
RolesCheck
|
|
934
|
-
ABSENT_ON_TARGET,
|
|
935
|
-
EXTENSION_UNAVAILABLE,
|
|
936
|
-
planWork,
|
|
937
|
-
runLikeApply,
|
|
938
|
-
promote
|
|
466
|
+
RolesCheck
|
|
939
467
|
};
|
|
940
|
-
//# sourceMappingURL=chunk-
|
|
468
|
+
//# sourceMappingURL=chunk-WNTCZM2J.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_MIGRATIONS_DIR,
|
|
3
3
|
Preflight
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4M6OQLPO.js";
|
|
5
5
|
import {
|
|
6
6
|
installProcessGuard,
|
|
7
7
|
noteJsonWritten
|
|
@@ -211,4 +211,4 @@ export {
|
|
|
211
211
|
readRunLog,
|
|
212
212
|
BaseCommand
|
|
213
213
|
};
|
|
214
|
-
//# sourceMappingURL=chunk-
|
|
214
|
+
//# sourceMappingURL=chunk-XLZCX6R2.js.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
captureSnapshot
|
|
2
|
+
captureSnapshot
|
|
3
|
+
} from "./chunk-SM7HP6EP.js";
|
|
4
|
+
import {
|
|
3
5
|
checkPgDumpCompat
|
|
4
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AGONS5JJ.js";
|
|
5
7
|
import {
|
|
6
8
|
newPgClient,
|
|
7
9
|
pgQuery,
|
|
8
10
|
quoteName
|
|
9
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-4M6OQLPO.js";
|
|
10
12
|
import {
|
|
11
13
|
BRANCHES_FILE,
|
|
12
14
|
CLONE_PROGRESS_INTERVAL_MS,
|
|
@@ -638,4 +640,4 @@ export {
|
|
|
638
640
|
isCloneDatabase,
|
|
639
641
|
sourceLooksLikeCloneOf
|
|
640
642
|
};
|
|
641
|
-
//# sourceMappingURL=chunk-
|
|
643
|
+
//# sourceMappingURL=chunk-YWERIWFD.js.map
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
captureSnapshot,
|
|
7
7
|
findLatestSnapshot,
|
|
8
8
|
loadSnapshot
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SM7HP6EP.js";
|
|
10
10
|
import {
|
|
11
11
|
slugify
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-AGONS5JJ.js";
|
|
13
13
|
import {
|
|
14
14
|
MIGRATIONS_SUBDIR,
|
|
15
15
|
SUPAFORGE_DIR
|
|
@@ -245,4 +245,4 @@ export {
|
|
|
245
245
|
loadMigrations,
|
|
246
246
|
listMigrationFiles
|
|
247
247
|
};
|
|
248
|
-
//# sourceMappingURL=chunk-
|
|
248
|
+
//# sourceMappingURL=chunk-YZM76W22.js.map
|
package/dist/commands/clone.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _oclif_core_interfaces from '@oclif/core/interfaces';
|
|
2
2
|
import { BaseCommand } from '../base-command.js';
|
|
3
|
-
import { R as RestoreFailure } from '../branch-
|
|
4
|
-
import { S as SupaForgeConfig } from '../config-
|
|
3
|
+
import { R as RestoreFailure } from '../branch-BppjQBv_.js';
|
|
4
|
+
import { S as SupaForgeConfig } from '../config-l3ggjw9r.js';
|
|
5
5
|
import '@oclif/core';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/commands/clone.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "../chunk-ZI435CAU.js";
|
|
4
4
|
import {
|
|
5
5
|
BaseCommand
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-XLZCX6R2.js";
|
|
7
7
|
import {
|
|
8
8
|
addBranchToManifest,
|
|
9
9
|
cloneRemoteToLocal,
|
|
@@ -11,20 +11,21 @@ import {
|
|
|
11
11
|
listBranches,
|
|
12
12
|
reconcileClones,
|
|
13
13
|
replaceDbName
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-YWERIWFD.js";
|
|
15
15
|
import {
|
|
16
16
|
captureSnapshot,
|
|
17
|
-
checkPgDumpCompat,
|
|
18
17
|
formatSnapshotLayers
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import
|
|
18
|
+
} from "../chunk-SM7HP6EP.js";
|
|
19
|
+
import {
|
|
20
|
+
checkPgDumpCompat
|
|
21
|
+
} from "../chunk-AGONS5JJ.js";
|
|
21
22
|
import {
|
|
22
23
|
DEFAULT_LOCAL_PORT,
|
|
23
24
|
LOCAL_PG_PASSWORD,
|
|
24
25
|
LOCAL_PG_USER,
|
|
25
26
|
newPgClient,
|
|
26
27
|
startLocalPg
|
|
27
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-4M6OQLPO.js";
|
|
28
29
|
import "../chunk-GQPGH6YR.js";
|
|
29
30
|
import {
|
|
30
31
|
CLONE_EXTRA_EXCLUDE_SCHEMAS,
|
package/dist/commands/diff.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Interfaces } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../base-command.js';
|
|
3
|
-
import '
|
|
4
|
-
import '../config-CTbeRlJk.js';
|
|
3
|
+
import '../config-l3ggjw9r.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* What to do after a rolled-back apply.
|
|
@@ -42,25 +41,26 @@ declare class Diff extends BaseCommand {
|
|
|
42
41
|
description: string;
|
|
43
42
|
}[];
|
|
44
43
|
static flags: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'
|
|
63
|
-
'fail-on
|
|
44
|
+
'source-dir': Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
45
|
+
check: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
46
|
+
skip: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
|
|
47
|
+
detail: Interfaces.BooleanFlag<boolean>;
|
|
48
|
+
apply: Interfaces.BooleanFlag<boolean>;
|
|
49
|
+
'allow-destructive': Interfaces.BooleanFlag<boolean>;
|
|
50
|
+
'dry-run': Interfaces.BooleanFlag<boolean>;
|
|
51
|
+
'no-transaction': Interfaces.BooleanFlag<boolean>;
|
|
52
|
+
only: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
|
|
53
|
+
'include-files': Interfaces.BooleanFlag<boolean>;
|
|
54
|
+
tables: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
|
|
55
|
+
'exclude-tables': Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
|
|
56
|
+
json: Interfaces.BooleanFlag<boolean>;
|
|
57
|
+
source: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
58
|
+
target: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
59
|
+
ci: Interfaces.BooleanFlag<boolean>;
|
|
60
|
+
prove: Interfaces.BooleanFlag<boolean>;
|
|
61
|
+
'apply-posture': Interfaces.BooleanFlag<boolean>;
|
|
62
|
+
'fail-on': Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
63
|
+
'fail-on-posture': Interfaces.BooleanFlag<boolean>;
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
66
|
* Report what `--apply` did, or — under `--dry-run` — what it would do.
|
|
@@ -72,6 +72,8 @@ declare class Diff extends BaseCommand {
|
|
|
72
72
|
*/
|
|
73
73
|
private renderApplyResult;
|
|
74
74
|
run(): Promise<void>;
|
|
75
|
+
/** The comparison itself, between the config's source and target. */
|
|
76
|
+
private compare;
|
|
75
77
|
/**
|
|
76
78
|
* Stop before applying anything: the proof could not run, or ran and found
|
|
77
79
|
* the migration would not reproduce the source. Under --json the reason is
|