@akal/supaforge 0.0.48 → 0.0.49
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 +33 -8
- package/dist/base-command.js +2 -2
- package/dist/{chunk-HZ2FKMY3.js → chunk-4EEDB7Q3.js} +4 -3
- package/dist/{chunk-AMG4PVQS.js → chunk-56U2BYRZ.js} +2 -2
- package/dist/{chunk-FKL3TQB7.js → chunk-56UP3KK3.js} +17 -10
- package/dist/{chunk-S2GQI7ZO.js → chunk-EI7EP5IU.js} +4 -4
- package/dist/{chunk-VEXHBRNW.js → chunk-EJBEEWGI.js} +7 -7
- package/dist/{chunk-NCMERJNX.js → chunk-EJMRK6LG.js} +2 -2
- package/dist/{chunk-W42J6U7R.js → chunk-GKYJA56H.js} +15 -4
- package/dist/{chunk-PSSMJRMM.js → chunk-JLY4IG73.js} +53 -8
- package/dist/{chunk-Z3SB66RS.js → chunk-JPZZL3KJ.js} +5 -5
- package/dist/{chunk-HKG4KGDV.js → chunk-OZW36QCK.js} +2 -2
- package/dist/{chunk-D3JEYV4M.js → chunk-P66NJJ6I.js} +6 -6
- package/dist/{chunk-EPGKCP3K.js → chunk-SQHEF5NQ.js} +2 -2
- package/dist/{chunk-X4L3JT4R.js → chunk-TREPSQWG.js} +3 -3
- package/dist/{chunk-C7VBY54T.js → chunk-VCNTXXEC.js} +202 -22
- package/dist/{chunk-RXPYUFJR.js → chunk-Y6JGEFSW.js} +6 -6
- package/dist/{chunk-3XQHSJOJ.js → chunk-YCJXGDVL.js} +3 -3
- 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.d.ts +7 -1
- package/dist/index.js +13 -13
- package/package.json +2 -2
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
pgToolConnection,
|
|
11
11
|
resolvePgDumpPath,
|
|
12
12
|
splitSqlStatements
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-56U2BYRZ.js";
|
|
14
14
|
import {
|
|
15
15
|
Check,
|
|
16
16
|
heldSnapshot,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
quoteLiteral,
|
|
21
21
|
quoteName,
|
|
22
22
|
snapshotsOff
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-GKYJA56H.js";
|
|
24
24
|
import {
|
|
25
25
|
DBDIFF_EXEC_TIMEOUT_MS,
|
|
26
26
|
DBDIFF_MAX_BUFFER,
|
|
@@ -165,6 +165,7 @@ var PLATFORM_ROLES = [
|
|
|
165
165
|
"supabase_privileged_role"
|
|
166
166
|
];
|
|
167
167
|
var API_ROLES = ["anon", "authenticated", "service_role"];
|
|
168
|
+
var ROLE_NAMES_SQL = "SELECT rolname FROM pg_roles";
|
|
168
169
|
var quoted = (names2) => names2.map((n) => `'${n.replace(/'/g, "''")}'`).join(", ");
|
|
169
170
|
var ROLES_SQL = `
|
|
170
171
|
SELECT
|
|
@@ -375,7 +376,9 @@ var RolesCheck = class extends Check {
|
|
|
375
376
|
targetRoutines,
|
|
376
377
|
sourceSchemaGrants,
|
|
377
378
|
targetSchemaGrants,
|
|
378
|
-
sourceSchemas
|
|
379
|
+
sourceSchemas,
|
|
380
|
+
sourceRoleNames,
|
|
381
|
+
targetRoleNames
|
|
379
382
|
] = await Promise.all([
|
|
380
383
|
this.queryFn(ctx.source.dbUrl, ROLES_SQL),
|
|
381
384
|
this.queryFn(ctx.target.dbUrl, ROLES_SQL),
|
|
@@ -394,7 +397,9 @@ var RolesCheck = class extends Check {
|
|
|
394
397
|
this.queryFn(ctx.target.dbUrl, routinesSql(ignore)),
|
|
395
398
|
this.queryFn(ctx.source.dbUrl, schemaGrantsSql(ignore)),
|
|
396
399
|
this.queryFn(ctx.target.dbUrl, schemaGrantsSql(ignore)),
|
|
397
|
-
this.queryFn(ctx.source.dbUrl, schemasSql(ignore))
|
|
400
|
+
this.queryFn(ctx.source.dbUrl, schemasSql(ignore)),
|
|
401
|
+
this.queryFn(ctx.source.dbUrl, ROLE_NAMES_SQL),
|
|
402
|
+
this.queryFn(ctx.target.dbUrl, ROLE_NAMES_SQL)
|
|
398
403
|
]);
|
|
399
404
|
const sourceObjects = [...sourceRelations ?? [], ...sourceRoutines ?? [], ...sourceSchemas ?? []];
|
|
400
405
|
const targetObjects = [...targetRelations ?? [], ...targetRoutines ?? []];
|
|
@@ -408,7 +413,9 @@ var RolesCheck = class extends Check {
|
|
|
408
413
|
...diffGrants(
|
|
409
414
|
[...sourceAll, ...sourceColumns ?? []].filter((g) => comparable(g) && !byDefault(g)),
|
|
410
415
|
[...targetAll, ...targetColumns ?? []].filter(comparable),
|
|
411
|
-
absentOn(targetRoles, sourceRoles)
|
|
416
|
+
absentOn(targetRoles, sourceRoles),
|
|
417
|
+
// Every server has roles; none read means unknown, not none.
|
|
418
|
+
sourceRoleNames?.length && targetRoleNames?.length ? { source: new Set(sourceRoleNames.map((r) => r.rolname)), target: new Set(targetRoleNames.map((r) => r.rolname)) } : void 0
|
|
412
419
|
),
|
|
413
420
|
...defaultGrantsToRevoke(
|
|
414
421
|
sourceObjects,
|
|
@@ -471,7 +478,11 @@ function diffRoles(source, target) {
|
|
|
471
478
|
sql: {
|
|
472
479
|
up: `DROP ROLE IF EXISTS ${quoteName(name)};`,
|
|
473
480
|
down: `CREATE ROLE ${quoteName(name)} ${roleAttrs(tr)};`
|
|
474
|
-
}
|
|
481
|
+
},
|
|
482
|
+
// Roles belong to the whole server, not this database, and a login
|
|
483
|
+
// role is a credential something may be signing in with — another
|
|
484
|
+
// database on the server, another service. Nothing here can see who.
|
|
485
|
+
...tr.rolcanlogin ? { manualOnly: `"${name}" can log in, and roles are shared by every database on the server, so it may be in use outside this one; drop it by hand once nothing signs in with it` } : {}
|
|
475
486
|
});
|
|
476
487
|
}
|
|
477
488
|
}
|
|
@@ -585,13 +596,41 @@ function grantsToMissingRoles(grants) {
|
|
|
585
596
|
};
|
|
586
597
|
});
|
|
587
598
|
}
|
|
588
|
-
function
|
|
599
|
+
function grantsToAbsentRoles(grants, side) {
|
|
600
|
+
const byRole = /* @__PURE__ */ new Map();
|
|
601
|
+
for (const g of grants) byRole.set(g.grantee, [...byRole.get(g.grantee) ?? [], g]);
|
|
602
|
+
return [...byRole].map(([role, gs]) => {
|
|
603
|
+
const objects = new Set(gs.map((g) => describeObject(g))).size;
|
|
604
|
+
const what = `${gs.length} privilege${gs.length === 1 ? "" : "s"} on ${objects} object${objects === 1 ? "" : "s"}`;
|
|
605
|
+
return side === "source" ? {
|
|
606
|
+
id: `roles-grant-unmatched-${role}`,
|
|
607
|
+
check: "roles",
|
|
608
|
+
severity: "info",
|
|
609
|
+
title: `Grants to ${role}, a role the source does not have: ${what}`,
|
|
610
|
+
description: `The target grants ${what} to "${role}". The source has no such role, so it says nothing about what the role may do, and these are left as they are.`,
|
|
611
|
+
targetValue: gs,
|
|
612
|
+
manualOnly: `"${role}" does not exist on the source, so its grants on the target are left as they are; revoke any it should not have by hand`
|
|
613
|
+
} : {
|
|
614
|
+
id: `roles-grant-missing-role-${role}`,
|
|
615
|
+
check: "roles",
|
|
616
|
+
severity: "info",
|
|
617
|
+
title: `Grants to ${role}, a Supabase role the target does not have: ${what}`,
|
|
618
|
+
description: `The source grants ${what} to "${role}", one of the roles Supabase's Data API uses. The target is not a Supabase project and has no such role, so there is nothing to grant.`,
|
|
619
|
+
sourceValue: gs,
|
|
620
|
+
manualOnly: `"${role}" is a Supabase role, and the target does not have it`
|
|
621
|
+
};
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set(), roles) {
|
|
589
625
|
const issues = [];
|
|
590
626
|
const sourceMap = new Map(source.map((g) => [grantKey(g), g]));
|
|
591
627
|
const targetMap = new Map(target.map((g) => [grantKey(g), g]));
|
|
628
|
+
const absentFrom = (side, g) => side !== void 0 && g.grantee !== "PUBLIC" && !side.has(g.grantee);
|
|
592
629
|
const missing = [...sourceMap].filter(([key]) => !targetMap.has(key)).map(([, g]) => g);
|
|
630
|
+
const uncreatable = (g) => API_ROLES.includes(g.grantee) && absentFrom(roles?.target, g);
|
|
631
|
+
issues.push(...grantsToAbsentRoles(missing.filter(uncreatable), "target"));
|
|
593
632
|
issues.push(...grantsToMissingRoles(missing.filter((g) => missingRoles.has(g.grantee))));
|
|
594
|
-
for (const gs of grouped(missing.filter((g) => !missingRoles.has(g.grantee)))) {
|
|
633
|
+
for (const gs of grouped(missing.filter((g) => !missingRoles.has(g.grantee) && !uncreatable(g)))) {
|
|
595
634
|
const plural = gs.length > 1 ? "s" : "";
|
|
596
635
|
issues.push({
|
|
597
636
|
id: `roles-grant-missing-${groupKey(gs)}`,
|
|
@@ -623,7 +662,8 @@ function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set()) {
|
|
|
623
662
|
}
|
|
624
663
|
}
|
|
625
664
|
const extra = [...targetMap].filter(([key]) => !sourceMap.has(key)).map(([, g]) => g);
|
|
626
|
-
|
|
665
|
+
issues.push(...grantsToAbsentRoles(extra.filter((g) => absentFrom(roles?.source, g)), "source"));
|
|
666
|
+
for (const gs of grouped(extra.filter((g) => !absentFrom(roles?.source, g)))) {
|
|
627
667
|
const plural = gs.length > 1 ? "s" : "";
|
|
628
668
|
issues.push({
|
|
629
669
|
id: `roles-grant-extra-${groupKey(gs)}`,
|
|
@@ -815,6 +855,8 @@ var PHASE = {
|
|
|
815
855
|
COMMENT: 95,
|
|
816
856
|
/** Row changes, once the structure holding them is in place. */
|
|
817
857
|
DATA: 100,
|
|
858
|
+
/** A sequence moved past the ids the row changes wrote — see checks/data-sequences. */
|
|
859
|
+
AFTER_DATA: 105,
|
|
818
860
|
DROP_TABLE: 110,
|
|
819
861
|
/**
|
|
820
862
|
* Routines, dropped once nothing calls them: the triggers, views and
|
|
@@ -859,7 +901,8 @@ var PHASE_RULES = [
|
|
|
859
901
|
[/^\s*DROP\s+(?:FUNCTION|PROCEDURE)\b/i, PHASE.DROP_ROUTINE],
|
|
860
902
|
[/^\s*DROP\s+TABLE\b/i, PHASE.DROP_TABLE],
|
|
861
903
|
[/^\s*DROP\s+(?:TYPE|DOMAIN|SEQUENCE)\b/i, PHASE.DROP_BASE],
|
|
862
|
-
[/^\s*(?:INSERT|UPDATE|DELETE)\b/i, PHASE.DATA]
|
|
904
|
+
[/^\s*(?:INSERT|UPDATE|DELETE)\b/i, PHASE.DATA],
|
|
905
|
+
[/^\s*SELECT\s+setval\s*\(/i, PHASE.AFTER_DATA]
|
|
863
906
|
];
|
|
864
907
|
function statementPhase(sql) {
|
|
865
908
|
const skeleton = sqlSkeleton(sql);
|
|
@@ -2441,7 +2484,91 @@ function lockBudgetWarning(needed, budget, what) {
|
|
|
2441
2484
|
return `${what} takes about ${needed} locks in one transaction, and the target has room for about ${Math.max(free, 0)} (max_locks_per_transaction for each connection slot, less what other sessions hold). It may fail with "out of shared memory" and roll back. Raising max_locks_per_transaction on the target (a restart) makes room; --no-transaction commits as it goes instead.`;
|
|
2442
2485
|
}
|
|
2443
2486
|
|
|
2487
|
+
// src/data-sync.ts
|
|
2488
|
+
var FOREIGN_KEY_VIOLATION = "23503";
|
|
2489
|
+
var WRITES = /^\s*(?:INSERT\s+INTO|UPDATE(?:\s+ONLY)?|DELETE\s+FROM(?:\s+ONLY)?)\s+((?:"(?:[^"]|"")*"|[\w$]+)(?:\s*\.\s*(?:"(?:[^"]|"")*"|[\w$]+))?)/i;
|
|
2490
|
+
function writtenTable(sql) {
|
|
2491
|
+
return WRITES.exec(sql)?.[1];
|
|
2492
|
+
}
|
|
2493
|
+
var FACTS_SQL = `
|
|
2494
|
+
SELECT c.oid::regclass::text AS rel,
|
|
2495
|
+
pg_has_role(c.relowner, 'MEMBER') AS owned,
|
|
2496
|
+
coalesce((SELECT json_agg(t.tgname ORDER BY t.tgname) FROM pg_trigger t
|
|
2497
|
+
WHERE t.tgrelid = c.oid AND NOT t.tgisinternal AND t.tgconstraint = 0
|
|
2498
|
+
AND t.tgenabled = 'O'), '[]') AS triggers,
|
|
2499
|
+
coalesce((SELECT json_agg(json_build_object('name', k.conname,
|
|
2500
|
+
'qualified', quote_ident(n.nspname) || '.' || quote_ident(k.conname))
|
|
2501
|
+
ORDER BY k.conname)
|
|
2502
|
+
FROM pg_constraint k
|
|
2503
|
+
WHERE k.conrelid = c.oid AND k.confrelid = c.oid AND k.contype = 'f'
|
|
2504
|
+
AND NOT k.condeferrable), '[]') AS "selfKeys"
|
|
2505
|
+
FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
2506
|
+
WHERE c.oid = to_regclass($1)`;
|
|
2507
|
+
var DataSyncGuard = class {
|
|
2508
|
+
constructor(client) {
|
|
2509
|
+
this.client = client;
|
|
2510
|
+
}
|
|
2511
|
+
client;
|
|
2512
|
+
/** Facts per table as the fixes name it; null for a name the target does not resolve. */
|
|
2513
|
+
tables = /* @__PURE__ */ new Map();
|
|
2514
|
+
/** Statements to run before commit, in order: deferred checks first, then the triggers back on. */
|
|
2515
|
+
checks = [];
|
|
2516
|
+
reenable = [];
|
|
2517
|
+
deferred = /* @__PURE__ */ new Set();
|
|
2518
|
+
/** Said in the run's output: what was held off, and what could not be. */
|
|
2519
|
+
notes = [];
|
|
2520
|
+
warnings = [];
|
|
2521
|
+
/** Before a data fix: hold off the triggers of the table it writes, once per table. */
|
|
2522
|
+
async before(sql) {
|
|
2523
|
+
const name = writtenTable(sql);
|
|
2524
|
+
if (!name || this.tables.has(name)) return;
|
|
2525
|
+
const facts = await this.factsFor(name);
|
|
2526
|
+
this.tables.set(name, facts);
|
|
2527
|
+
if (!facts || facts.triggers.length === 0) return;
|
|
2528
|
+
const list = facts.triggers.map((t) => `"${t}"`).join(", ");
|
|
2529
|
+
if (!facts.owned) {
|
|
2530
|
+
this.warnings.push(`Triggers on ${facts.rel} fired as its rows were synced (${list}): the connecting role does not own the table, so they could not be held off, and what they write may differ from the source.`);
|
|
2531
|
+
return;
|
|
2532
|
+
}
|
|
2533
|
+
for (const trigger of facts.triggers) {
|
|
2534
|
+
await this.client.query(`ALTER TABLE ${facts.rel} DISABLE TRIGGER ${quoteName(trigger)}`);
|
|
2535
|
+
this.reenable.push(`ALTER TABLE ${facts.rel} ENABLE TRIGGER ${quoteName(trigger)}`);
|
|
2536
|
+
}
|
|
2537
|
+
this.notes.push(`Held off ${facts.triggers.length === 1 ? "trigger" : "triggers"} ${list} on ${facts.rel} while its rows were synced.`);
|
|
2538
|
+
}
|
|
2539
|
+
/**
|
|
2540
|
+
* After a data fix failed with `err`: true when the failure was the table's
|
|
2541
|
+
* own foreign key and it is now deferred, so the fix can be tried again.
|
|
2542
|
+
*/
|
|
2543
|
+
async deferSelfReference(sql, err) {
|
|
2544
|
+
if (err?.code !== FOREIGN_KEY_VIOLATION) return false;
|
|
2545
|
+
const name = writtenTable(sql);
|
|
2546
|
+
const facts = name ? this.tables.get(name) : void 0;
|
|
2547
|
+
if (!facts?.owned) return false;
|
|
2548
|
+
const constraint = err.constraint;
|
|
2549
|
+
const key = facts.selfKeys.find((k) => k.name === constraint);
|
|
2550
|
+
if (!key || this.deferred.has(key.qualified)) return false;
|
|
2551
|
+
await this.client.query(`ALTER TABLE ${facts.rel} ALTER CONSTRAINT ${quoteName(key.name)} DEFERRABLE INITIALLY DEFERRED`);
|
|
2552
|
+
this.deferred.add(key.qualified);
|
|
2553
|
+
this.checks.push(
|
|
2554
|
+
`SET CONSTRAINTS ${key.qualified} IMMEDIATE`,
|
|
2555
|
+
`ALTER TABLE ${facts.rel} ALTER CONSTRAINT ${quoteName(key.name)} NOT DEFERRABLE`
|
|
2556
|
+
);
|
|
2557
|
+
this.notes.push(`Checked ${facts.rel}'s rows against its own foreign key "${key.name}" once all were written: a row needed one written after it.`);
|
|
2558
|
+
return true;
|
|
2559
|
+
}
|
|
2560
|
+
/** Before commit: check what was deferred, and put the triggers back. Throws when a row is still orphaned. */
|
|
2561
|
+
async finish() {
|
|
2562
|
+
for (const statement of [...this.checks, ...this.reenable]) await this.client.query(statement);
|
|
2563
|
+
}
|
|
2564
|
+
async factsFor(name) {
|
|
2565
|
+
const { rows: [row] } = await this.client.query(FACTS_SQL, [name]);
|
|
2566
|
+
return row ?? null;
|
|
2567
|
+
}
|
|
2568
|
+
};
|
|
2569
|
+
|
|
2444
2570
|
// src/promote.ts
|
|
2571
|
+
var EXTENSION_NOT_SHIPPED = "this server does not ship it";
|
|
2445
2572
|
function outOfScopeReason(sql, filter) {
|
|
2446
2573
|
if (!isFiltered(filter)) return null;
|
|
2447
2574
|
const referenced = referencedTables(sql);
|
|
@@ -2465,6 +2592,13 @@ function withDefaultGrantRevokes(scanResult, only) {
|
|
|
2465
2592
|
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);
|
|
2466
2593
|
return [...only, ...companions];
|
|
2467
2594
|
}
|
|
2595
|
+
function withSequenceFixes(scanResult, only) {
|
|
2596
|
+
if (!only?.length) return only;
|
|
2597
|
+
const issues = scanResult.checks.flatMap((c) => c.issues);
|
|
2598
|
+
const rows = issues.some((i) => i.check === "data" && !i.id.startsWith("data-sequence-") && isSelected(i.id, only));
|
|
2599
|
+
if (!rows) return only;
|
|
2600
|
+
return [...only, ...issues.filter((i) => i.id.startsWith("data-sequence-")).map((i) => i.id)];
|
|
2601
|
+
}
|
|
2468
2602
|
function relationsCreatedBy(sql) {
|
|
2469
2603
|
const statements = parseStatements(sql);
|
|
2470
2604
|
if (!statements) return [];
|
|
@@ -2516,7 +2650,7 @@ function policiesCreatedBySelectedFixes(checks, options) {
|
|
|
2516
2650
|
return created;
|
|
2517
2651
|
}
|
|
2518
2652
|
function planWork(scanResult, options = {}) {
|
|
2519
|
-
options = { ...options, only: withDefaultGrantRevokes(scanResult, options.only) };
|
|
2653
|
+
options = { ...options, only: withSequenceFixes(scanResult, withDefaultGrantRevokes(scanResult, options.only)) };
|
|
2520
2654
|
const plan = { sqlStatements: [], apiActions: [], skipped: [] };
|
|
2521
2655
|
const relevant = scanResult.checks.filter(
|
|
2522
2656
|
(c) => c.status === "drifted" && (!options.checks || options.checks.includes(c.check))
|
|
@@ -2630,7 +2764,12 @@ async function executeSql(dbUrl, statements, result, transactional, sourceMajor)
|
|
|
2630
2764
|
try {
|
|
2631
2765
|
const olderTarget = sourceMajor !== void 0 && await majorOf(client) < sourceMajor;
|
|
2632
2766
|
if (transactional) await runInTransaction(client, statements, result, olderTarget);
|
|
2633
|
-
else
|
|
2767
|
+
else {
|
|
2768
|
+
if (statements.some((s) => s.check === "data")) {
|
|
2769
|
+
result.warnings = [...result.warnings ?? [], "With --no-transaction the target's triggers fire on the rows synced, and a row that needs one written after it in the same table fails: both need the single transaction."];
|
|
2770
|
+
}
|
|
2771
|
+
await runIndependently(client, statements, result);
|
|
2772
|
+
}
|
|
2634
2773
|
} finally {
|
|
2635
2774
|
await client.end();
|
|
2636
2775
|
}
|
|
@@ -2685,7 +2824,7 @@ function unmetDependency(sql, err, olderTarget = false) {
|
|
|
2685
2824
|
return "the target's PostgreSQL is older than the source's and does not support it";
|
|
2686
2825
|
}
|
|
2687
2826
|
if (/(?:^|;)\s*CREATE\s+EXTENSION\b/i.test(sqlSkeleton(sql))) {
|
|
2688
|
-
return EXTENSION_UNAVAILABLE.has(code) ?
|
|
2827
|
+
return EXTENSION_UNAVAILABLE.has(code) ? EXTENSION_NOT_SHIPPED : void 0;
|
|
2689
2828
|
}
|
|
2690
2829
|
if (ABSENT_ON_TARGET.has(code) || code === UNDEFINED_COLUMN) {
|
|
2691
2830
|
return "it needs something the target does not have";
|
|
@@ -2706,15 +2845,41 @@ function revokesFromAbsent(sql) {
|
|
|
2706
2845
|
}
|
|
2707
2846
|
return targets.size === 1;
|
|
2708
2847
|
}
|
|
2848
|
+
async function retriedWithKeyDeferred(client, guard, sql, err) {
|
|
2849
|
+
try {
|
|
2850
|
+
if (!await client.query("ROLLBACK TO SAVEPOINT sf_fix").then(() => true, () => false)) return false;
|
|
2851
|
+
if (!await guard.deferSelfReference(sql, err)) return false;
|
|
2852
|
+
await client.query(sql);
|
|
2853
|
+
await client.query("RELEASE SAVEPOINT sf_fix");
|
|
2854
|
+
return true;
|
|
2855
|
+
} catch {
|
|
2856
|
+
return false;
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2709
2859
|
async function runBatch(client, statements, result, olderTarget = false) {
|
|
2710
2860
|
if (statements.length === 0) return true;
|
|
2711
2861
|
const done = [];
|
|
2862
|
+
const guard = new DataSyncGuard(client);
|
|
2863
|
+
const fail = async (stmt, err) => {
|
|
2864
|
+
await client.query("ROLLBACK").catch(() => {
|
|
2865
|
+
});
|
|
2866
|
+
result.errors.push({ check: stmt.check, issueId: stmt.issueId, error: errMsg(err) });
|
|
2867
|
+
result.rolledBack = [...result.rolledBack ?? [], ...done.map(({ check, issueId }) => ({ check, issueId }))];
|
|
2868
|
+
return false;
|
|
2869
|
+
};
|
|
2712
2870
|
await client.query("BEGIN");
|
|
2713
2871
|
let pending = statements;
|
|
2714
2872
|
let unmet = [];
|
|
2715
2873
|
while (pending.length > 0) {
|
|
2716
2874
|
unmet = [];
|
|
2717
2875
|
for (const stmt of pending) {
|
|
2876
|
+
if (stmt.check === "data") {
|
|
2877
|
+
try {
|
|
2878
|
+
await guard.before(stmt.sql);
|
|
2879
|
+
} catch (err) {
|
|
2880
|
+
return fail(stmt, err);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2718
2883
|
await client.query("SAVEPOINT sf_fix");
|
|
2719
2884
|
try {
|
|
2720
2885
|
await client.query(stmt.sql);
|
|
@@ -2726,11 +2891,11 @@ async function runBatch(client, statements, result, olderTarget = false) {
|
|
|
2726
2891
|
unmet.push({ stmt, err, why });
|
|
2727
2892
|
continue;
|
|
2728
2893
|
}
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
return
|
|
2894
|
+
if (stmt.check === "data" && await retriedWithKeyDeferred(client, guard, stmt.sql, err)) {
|
|
2895
|
+
done.push({ check: stmt.check, issueId: stmt.issueId, sql: stmt.sql });
|
|
2896
|
+
continue;
|
|
2897
|
+
}
|
|
2898
|
+
return fail(stmt, err);
|
|
2734
2899
|
}
|
|
2735
2900
|
}
|
|
2736
2901
|
if (unmet.length === pending.length) break;
|
|
@@ -2741,13 +2906,24 @@ async function runBatch(client, statements, result, olderTarget = false) {
|
|
|
2741
2906
|
for (const { stmt } of gone) {
|
|
2742
2907
|
done.push({ check: stmt.check, issueId: stmt.issueId, sql: stmt.sql, note: "nothing to revoke: the object is not on the target" });
|
|
2743
2908
|
}
|
|
2909
|
+
try {
|
|
2910
|
+
await guard.finish();
|
|
2911
|
+
} catch (err) {
|
|
2912
|
+
return fail({ check: "data", issueId: "data" }, err);
|
|
2913
|
+
}
|
|
2914
|
+
if (guard.warnings.length > 0) result.warnings = [...result.warnings ?? [], ...guard.warnings];
|
|
2915
|
+
if (guard.notes.length > 0) result.notes = [...result.notes ?? [], ...guard.notes];
|
|
2744
2916
|
await client.query("COMMIT");
|
|
2745
2917
|
result.applied.push(...done);
|
|
2918
|
+
for (const { stmt } of unmet.filter((u) => u.why === EXTENSION_NOT_SHIPPED)) {
|
|
2919
|
+
result.skipped.push({ check: stmt.check, issueId: stmt.issueId, reason: "An extension this server does not ship" });
|
|
2920
|
+
}
|
|
2921
|
+
unmet = unmet.filter((u) => u.why !== EXTENSION_NOT_SHIPPED);
|
|
2746
2922
|
for (const { stmt, err, why } of unmet) {
|
|
2747
2923
|
result.errors.push({
|
|
2748
2924
|
check: stmt.check,
|
|
2749
2925
|
issueId: stmt.issueId,
|
|
2750
|
-
error: `${errMsg(err)} \u2014 not applied: ${why}.
|
|
2926
|
+
error: `${errMsg(err)} \u2014 not applied: ${why}. Everything else was applied.`
|
|
2751
2927
|
});
|
|
2752
2928
|
}
|
|
2753
2929
|
return true;
|
|
@@ -3052,10 +3228,14 @@ async function sampleInto(psql, fromUrl, intoUrl, schemas, limit) {
|
|
|
3052
3228
|
}
|
|
3053
3229
|
return { sampled, unchecked };
|
|
3054
3230
|
}
|
|
3231
|
+
function withPinnedFormats(options) {
|
|
3232
|
+
const pinned = "-c DateStyle=ISO,MDY -c IntervalStyle=postgres -c extra_float_digits=3 -c bytea_output=hex";
|
|
3233
|
+
return options ? `${options} ${pinned}` : pinned;
|
|
3234
|
+
}
|
|
3055
3235
|
function pipeCopy(psql, fromUrl, intoUrl, out, into) {
|
|
3056
3236
|
return new Promise((resolve, reject) => {
|
|
3057
|
-
const reading = pgToolConnection(fromUrl);
|
|
3058
|
-
const writing = pgToolConnection(intoUrl);
|
|
3237
|
+
const reading = pgToolConnection(fromUrl, { ...process.env, PGOPTIONS: withPinnedFormats(process.env.PGOPTIONS) });
|
|
3238
|
+
const writing = pgToolConnection(intoUrl, { ...process.env, PGOPTIONS: withPinnedFormats(process.env.PGOPTIONS) });
|
|
3059
3239
|
const reader = spawn(psql, [reading.url, "-X", "-q", "-v", "ON_ERROR_STOP=1", "-c", out], { stdio: ["ignore", "pipe", "pipe"], env: reading.env });
|
|
3060
3240
|
const writer = spawn(psql, [writing.url, "-X", "-q", "-v", "ON_ERROR_STOP=1", "-f", "-"], { stdio: ["pipe", "pipe", "pipe"], env: writing.env });
|
|
3061
3241
|
let stderr = "";
|
|
@@ -3603,4 +3783,4 @@ export {
|
|
|
3603
3783
|
residualHeldBack,
|
|
3604
3784
|
proofScope
|
|
3605
3785
|
};
|
|
3606
|
-
//# sourceMappingURL=chunk-
|
|
3786
|
+
//# sourceMappingURL=chunk-VCNTXXEC.js.map
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
migrationsDir,
|
|
3
3
|
writeMigrationFile
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JPZZL3KJ.js";
|
|
5
5
|
import {
|
|
6
6
|
createDefaultRegistry,
|
|
7
7
|
proveBeforeApply,
|
|
8
8
|
scan
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JLY4IG73.js";
|
|
10
10
|
import {
|
|
11
11
|
CHECK_NAMES,
|
|
12
12
|
promote
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-VCNTXXEC.js";
|
|
14
14
|
import {
|
|
15
15
|
captureSnapshot,
|
|
16
16
|
unrestorableSchema
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-TREPSQWG.js";
|
|
18
18
|
import {
|
|
19
19
|
checkConnection
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-GKYJA56H.js";
|
|
21
21
|
import {
|
|
22
22
|
describeFailure,
|
|
23
23
|
redactUrls,
|
|
@@ -530,4 +530,4 @@ export {
|
|
|
530
530
|
clearLastScanResult,
|
|
531
531
|
createServer
|
|
532
532
|
};
|
|
533
|
-
//# sourceMappingURL=chunk-
|
|
533
|
+
//# sourceMappingURL=chunk-Y6JGEFSW.js.map
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
captureSnapshot,
|
|
3
3
|
findLatestSnapshot,
|
|
4
4
|
loadSnapshot
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-TREPSQWG.js";
|
|
6
6
|
import {
|
|
7
7
|
isCommentOnly,
|
|
8
8
|
slugify,
|
|
9
9
|
splitSqlStatements
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-56U2BYRZ.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-YCJXGDVL.js.map
|
package/dist/commands/clone.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "../chunk-RQCXGO37.js";
|
|
4
4
|
import {
|
|
5
5
|
BaseCommand
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-SQHEF5NQ.js";
|
|
7
7
|
import {
|
|
8
8
|
addBranchToManifest,
|
|
9
9
|
cloneRemoteToLocal,
|
|
@@ -13,21 +13,21 @@ import {
|
|
|
13
13
|
maintenanceUrl,
|
|
14
14
|
reconcileClones,
|
|
15
15
|
replaceDbName
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-EI7EP5IU.js";
|
|
17
17
|
import {
|
|
18
18
|
captureSnapshot,
|
|
19
19
|
formatSnapshotLayers
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-TREPSQWG.js";
|
|
21
21
|
import {
|
|
22
22
|
checkPgDumpCompat
|
|
23
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-56U2BYRZ.js";
|
|
24
24
|
import {
|
|
25
25
|
DEFAULT_LOCAL_PORT,
|
|
26
26
|
LOCAL_PG_PASSWORD,
|
|
27
27
|
LOCAL_PG_USER,
|
|
28
28
|
newPgClient,
|
|
29
29
|
startLocalPg
|
|
30
|
-
} from "../chunk-
|
|
30
|
+
} from "../chunk-GKYJA56H.js";
|
|
31
31
|
import "../chunk-KHXEES2M.js";
|
|
32
32
|
import {
|
|
33
33
|
CLONE_EXTRA_EXCLUDE_SCHEMAS,
|
package/dist/commands/diff.js
CHANGED
|
@@ -2,17 +2,17 @@ import {
|
|
|
2
2
|
Diff,
|
|
3
3
|
inertApplyFlags,
|
|
4
4
|
rollbackHint
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-56UP3KK3.js";
|
|
6
6
|
import "../chunk-Q43MN6NE.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-OZW36QCK.js";
|
|
8
|
+
import "../chunk-JLY4IG73.js";
|
|
9
|
+
import "../chunk-VCNTXXEC.js";
|
|
10
10
|
import "../chunk-RQCXGO37.js";
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-
|
|
15
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-SQHEF5NQ.js";
|
|
12
|
+
import "../chunk-EI7EP5IU.js";
|
|
13
|
+
import "../chunk-TREPSQWG.js";
|
|
14
|
+
import "../chunk-56U2BYRZ.js";
|
|
15
|
+
import "../chunk-GKYJA56H.js";
|
|
16
16
|
import "../chunk-KHXEES2M.js";
|
|
17
17
|
import "../chunk-SQ52YBKK.js";
|
|
18
18
|
export {
|
package/dist/commands/hukam.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Diff
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-56UP3KK3.js";
|
|
4
4
|
import "../chunk-Q43MN6NE.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-OZW36QCK.js";
|
|
6
|
+
import "../chunk-JLY4IG73.js";
|
|
7
|
+
import "../chunk-VCNTXXEC.js";
|
|
8
8
|
import "../chunk-RQCXGO37.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-SQHEF5NQ.js";
|
|
10
|
+
import "../chunk-EI7EP5IU.js";
|
|
11
|
+
import "../chunk-TREPSQWG.js";
|
|
12
|
+
import "../chunk-56U2BYRZ.js";
|
|
13
|
+
import "../chunk-GKYJA56H.js";
|
|
14
14
|
import "../chunk-KHXEES2M.js";
|
|
15
15
|
import "../chunk-SQ52YBKK.js";
|
|
16
16
|
|
package/dist/commands/mcp.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createServer
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-Y6JGEFSW.js";
|
|
4
|
+
import "../chunk-JPZZL3KJ.js";
|
|
5
|
+
import "../chunk-EJMRK6LG.js";
|
|
6
|
+
import "../chunk-JLY4IG73.js";
|
|
7
|
+
import "../chunk-VCNTXXEC.js";
|
|
8
|
+
import "../chunk-TREPSQWG.js";
|
|
9
|
+
import "../chunk-56U2BYRZ.js";
|
|
10
|
+
import "../chunk-GKYJA56H.js";
|
|
11
11
|
import {
|
|
12
12
|
installProcessGuard,
|
|
13
13
|
keepRunningOnStrayErrors
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
baselineMigrations
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-4EEDB7Q3.js";
|
|
4
4
|
import {
|
|
5
5
|
BaseCommand
|
|
6
|
-
} from "../../chunk-
|
|
7
|
-
import "../../chunk-
|
|
6
|
+
} from "../../chunk-SQHEF5NQ.js";
|
|
7
|
+
import "../../chunk-GKYJA56H.js";
|
|
8
8
|
import "../../chunk-KHXEES2M.js";
|
|
9
9
|
import {
|
|
10
10
|
bold,
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
truncateSql
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-P66NJJ6I.js";
|
|
4
4
|
import {
|
|
5
5
|
generateTimestamp,
|
|
6
6
|
writeMigrationFile
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-JPZZL3KJ.js";
|
|
8
|
+
import "../../chunk-EJMRK6LG.js";
|
|
9
|
+
import "../../chunk-4EEDB7Q3.js";
|
|
10
|
+
import "../../chunk-VCNTXXEC.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseCommand
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-SQHEF5NQ.js";
|
|
14
14
|
import {
|
|
15
15
|
slugify
|
|
16
|
-
} from "../../chunk-
|
|
17
|
-
import "../../chunk-
|
|
16
|
+
} from "../../chunk-56U2BYRZ.js";
|
|
17
|
+
import "../../chunk-GKYJA56H.js";
|
|
18
18
|
import "../../chunk-KHXEES2M.js";
|
|
19
19
|
import {
|
|
20
20
|
bold,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getAppliedVersions
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-4EEDB7Q3.js";
|
|
4
4
|
import {
|
|
5
5
|
BaseCommand
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-SQHEF5NQ.js";
|
|
7
7
|
import {
|
|
8
8
|
pgQuery,
|
|
9
9
|
readLocalMigrations
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-GKYJA56H.js";
|
|
11
11
|
import "../../chunk-KHXEES2M.js";
|
|
12
12
|
import {
|
|
13
13
|
bold,
|
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
MigrateRun,
|
|
3
3
|
findDestructiveStatements,
|
|
4
4
|
truncateSql
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import "../../chunk-
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
11
|
-
import "../../chunk-
|
|
5
|
+
} from "../../chunk-P66NJJ6I.js";
|
|
6
|
+
import "../../chunk-EJMRK6LG.js";
|
|
7
|
+
import "../../chunk-4EEDB7Q3.js";
|
|
8
|
+
import "../../chunk-VCNTXXEC.js";
|
|
9
|
+
import "../../chunk-SQHEF5NQ.js";
|
|
10
|
+
import "../../chunk-56U2BYRZ.js";
|
|
11
|
+
import "../../chunk-GKYJA56H.js";
|
|
12
12
|
import "../../chunk-KHXEES2M.js";
|
|
13
13
|
import "../../chunk-SQ52YBKK.js";
|
|
14
14
|
export {
|
package/dist/commands/report.js
CHANGED