@akal/supaforge 0.0.47 → 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 +54 -19
- package/dist/base-command.js +2 -2
- package/dist/{chunk-HWRRFF55.js → chunk-4EEDB7Q3.js} +4 -3
- package/dist/{chunk-YYS4FJ23.js → chunk-56U2BYRZ.js} +2 -2
- package/dist/{chunk-CUGDLO2L.js → chunk-56UP3KK3.js} +17 -10
- package/dist/{chunk-2XMRTAFX.js → chunk-EI7EP5IU.js} +8 -7
- package/dist/{chunk-KBZUTGGF.js → chunk-EJBEEWGI.js} +7 -7
- package/dist/{chunk-YQLVRHJA.js → chunk-EJMRK6LG.js} +2 -2
- package/dist/{chunk-RC7ZU7OV.js → chunk-GKYJA56H.js} +15 -2
- package/dist/{chunk-EGXQ37PA.js → chunk-JLY4IG73.js} +56 -10
- package/dist/{chunk-CRUFF6K5.js → chunk-JPZZL3KJ.js} +5 -5
- package/dist/{chunk-EB6PCOIL.js → chunk-OZW36QCK.js} +2 -2
- package/dist/{chunk-UUDXVYEI.js → chunk-P66NJJ6I.js} +6 -6
- package/dist/{chunk-TU5UIODX.js → chunk-SQHEF5NQ.js} +2 -2
- package/dist/{chunk-3SEVACCT.js → chunk-TREPSQWG.js} +3 -3
- package/dist/{chunk-WNZCOYOK.js → chunk-VCNTXXEC.js} +214 -24
- package/dist/{chunk-XTSFAUXI.js → chunk-Y6JGEFSW.js} +6 -6
- package/dist/{chunk-4TBYWXUK.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 +23 -3
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
normalizeRoles,
|
|
6
6
|
pgToolConnection,
|
|
7
7
|
resolvePgDumpPath
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-56U2BYRZ.js";
|
|
9
9
|
import {
|
|
10
10
|
Check,
|
|
11
11
|
inRolledBackTransaction,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
quoteLiteral,
|
|
17
17
|
quoteName,
|
|
18
18
|
readOrAbsent
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-GKYJA56H.js";
|
|
20
20
|
import {
|
|
21
21
|
DEFAULT_IGNORE_SCHEMAS,
|
|
22
22
|
MIGRATIONS_SUBDIR,
|
|
@@ -1252,4 +1252,4 @@ export {
|
|
|
1252
1252
|
DEFAULT_KEEP_COUNT,
|
|
1253
1253
|
pruneSnapshots
|
|
1254
1254
|
};
|
|
1255
|
-
//# sourceMappingURL=chunk-
|
|
1255
|
+
//# sourceMappingURL=chunk-TREPSQWG.js.map
|
|
@@ -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,
|
|
@@ -157,9 +157,15 @@ var PLATFORM_ROLES = [
|
|
|
157
157
|
"supabase_functions_admin",
|
|
158
158
|
"supabase_realtime_admin",
|
|
159
159
|
"supabase_read_only_user",
|
|
160
|
-
"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"
|
|
161
166
|
];
|
|
162
167
|
var API_ROLES = ["anon", "authenticated", "service_role"];
|
|
168
|
+
var ROLE_NAMES_SQL = "SELECT rolname FROM pg_roles";
|
|
163
169
|
var quoted = (names2) => names2.map((n) => `'${n.replace(/'/g, "''")}'`).join(", ");
|
|
164
170
|
var ROLES_SQL = `
|
|
165
171
|
SELECT
|
|
@@ -370,7 +376,9 @@ var RolesCheck = class extends Check {
|
|
|
370
376
|
targetRoutines,
|
|
371
377
|
sourceSchemaGrants,
|
|
372
378
|
targetSchemaGrants,
|
|
373
|
-
sourceSchemas
|
|
379
|
+
sourceSchemas,
|
|
380
|
+
sourceRoleNames,
|
|
381
|
+
targetRoleNames
|
|
374
382
|
] = await Promise.all([
|
|
375
383
|
this.queryFn(ctx.source.dbUrl, ROLES_SQL),
|
|
376
384
|
this.queryFn(ctx.target.dbUrl, ROLES_SQL),
|
|
@@ -389,7 +397,9 @@ var RolesCheck = class extends Check {
|
|
|
389
397
|
this.queryFn(ctx.target.dbUrl, routinesSql(ignore)),
|
|
390
398
|
this.queryFn(ctx.source.dbUrl, schemaGrantsSql(ignore)),
|
|
391
399
|
this.queryFn(ctx.target.dbUrl, schemaGrantsSql(ignore)),
|
|
392
|
-
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)
|
|
393
403
|
]);
|
|
394
404
|
const sourceObjects = [...sourceRelations ?? [], ...sourceRoutines ?? [], ...sourceSchemas ?? []];
|
|
395
405
|
const targetObjects = [...targetRelations ?? [], ...targetRoutines ?? []];
|
|
@@ -403,7 +413,9 @@ var RolesCheck = class extends Check {
|
|
|
403
413
|
...diffGrants(
|
|
404
414
|
[...sourceAll, ...sourceColumns ?? []].filter((g) => comparable(g) && !byDefault(g)),
|
|
405
415
|
[...targetAll, ...targetColumns ?? []].filter(comparable),
|
|
406
|
-
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
|
|
407
419
|
),
|
|
408
420
|
...defaultGrantsToRevoke(
|
|
409
421
|
sourceObjects,
|
|
@@ -466,7 +478,11 @@ function diffRoles(source, target) {
|
|
|
466
478
|
sql: {
|
|
467
479
|
up: `DROP ROLE IF EXISTS ${quoteName(name)};`,
|
|
468
480
|
down: `CREATE ROLE ${quoteName(name)} ${roleAttrs(tr)};`
|
|
469
|
-
}
|
|
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` } : {}
|
|
470
486
|
});
|
|
471
487
|
}
|
|
472
488
|
}
|
|
@@ -580,13 +596,41 @@ function grantsToMissingRoles(grants) {
|
|
|
580
596
|
};
|
|
581
597
|
});
|
|
582
598
|
}
|
|
583
|
-
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) {
|
|
584
625
|
const issues = [];
|
|
585
626
|
const sourceMap = new Map(source.map((g) => [grantKey(g), g]));
|
|
586
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);
|
|
587
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"));
|
|
588
632
|
issues.push(...grantsToMissingRoles(missing.filter((g) => missingRoles.has(g.grantee))));
|
|
589
|
-
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)))) {
|
|
590
634
|
const plural = gs.length > 1 ? "s" : "";
|
|
591
635
|
issues.push({
|
|
592
636
|
id: `roles-grant-missing-${groupKey(gs)}`,
|
|
@@ -618,7 +662,8 @@ function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set()) {
|
|
|
618
662
|
}
|
|
619
663
|
}
|
|
620
664
|
const extra = [...targetMap].filter(([key]) => !sourceMap.has(key)).map(([, g]) => g);
|
|
621
|
-
|
|
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)))) {
|
|
622
667
|
const plural = gs.length > 1 ? "s" : "";
|
|
623
668
|
issues.push({
|
|
624
669
|
id: `roles-grant-extra-${groupKey(gs)}`,
|
|
@@ -810,6 +855,8 @@ var PHASE = {
|
|
|
810
855
|
COMMENT: 95,
|
|
811
856
|
/** Row changes, once the structure holding them is in place. */
|
|
812
857
|
DATA: 100,
|
|
858
|
+
/** A sequence moved past the ids the row changes wrote — see checks/data-sequences. */
|
|
859
|
+
AFTER_DATA: 105,
|
|
813
860
|
DROP_TABLE: 110,
|
|
814
861
|
/**
|
|
815
862
|
* Routines, dropped once nothing calls them: the triggers, views and
|
|
@@ -854,7 +901,8 @@ var PHASE_RULES = [
|
|
|
854
901
|
[/^\s*DROP\s+(?:FUNCTION|PROCEDURE)\b/i, PHASE.DROP_ROUTINE],
|
|
855
902
|
[/^\s*DROP\s+TABLE\b/i, PHASE.DROP_TABLE],
|
|
856
903
|
[/^\s*DROP\s+(?:TYPE|DOMAIN|SEQUENCE)\b/i, PHASE.DROP_BASE],
|
|
857
|
-
[/^\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]
|
|
858
906
|
];
|
|
859
907
|
function statementPhase(sql) {
|
|
860
908
|
const skeleton = sqlSkeleton(sql);
|
|
@@ -1319,7 +1367,7 @@ function buildDbDiffArgs(options, outputFile) {
|
|
|
1319
1367
|
if (memoryLimit) {
|
|
1320
1368
|
args.push(`--memory-limit=${memoryLimit}`);
|
|
1321
1369
|
}
|
|
1322
|
-
if (options.type === "schema"
|
|
1370
|
+
if (options.ignoreSchemas && (options.type === "schema" || options.type === "data")) {
|
|
1323
1371
|
args.push(`--ignore-schemas=${schemaDiffIgnores(options.ignoreSchemas).join(",")}`);
|
|
1324
1372
|
}
|
|
1325
1373
|
const ignore = options.ignoreTables ?? [];
|
|
@@ -1331,6 +1379,10 @@ function buildDbDiffArgs(options, outputFile) {
|
|
|
1331
1379
|
}
|
|
1332
1380
|
return args;
|
|
1333
1381
|
}
|
|
1382
|
+
function dataScope(tables, ignoreSchemas) {
|
|
1383
|
+
if (!tables.some((t) => t.includes("."))) return { tables };
|
|
1384
|
+
return { tables: tables.map((t) => t.includes(".") ? t : `public.${t}`), ignoreSchemas };
|
|
1385
|
+
}
|
|
1334
1386
|
function dbdiffUrlEnv(options) {
|
|
1335
1387
|
if (options.urlsOnCommandLine) return {};
|
|
1336
1388
|
return { DBDIFF_SERVER1_URL: options.sourceUrl, DBDIFF_SERVER2_URL: options.targetUrl };
|
|
@@ -2432,7 +2484,91 @@ function lockBudgetWarning(needed, budget, what) {
|
|
|
2432
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.`;
|
|
2433
2485
|
}
|
|
2434
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
|
+
|
|
2435
2570
|
// src/promote.ts
|
|
2571
|
+
var EXTENSION_NOT_SHIPPED = "this server does not ship it";
|
|
2436
2572
|
function outOfScopeReason(sql, filter) {
|
|
2437
2573
|
if (!isFiltered(filter)) return null;
|
|
2438
2574
|
const referenced = referencedTables(sql);
|
|
@@ -2456,6 +2592,13 @@ function withDefaultGrantRevokes(scanResult, only) {
|
|
|
2456
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);
|
|
2457
2593
|
return [...only, ...companions];
|
|
2458
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
|
+
}
|
|
2459
2602
|
function relationsCreatedBy(sql) {
|
|
2460
2603
|
const statements = parseStatements(sql);
|
|
2461
2604
|
if (!statements) return [];
|
|
@@ -2507,7 +2650,7 @@ function policiesCreatedBySelectedFixes(checks, options) {
|
|
|
2507
2650
|
return created;
|
|
2508
2651
|
}
|
|
2509
2652
|
function planWork(scanResult, options = {}) {
|
|
2510
|
-
options = { ...options, only: withDefaultGrantRevokes(scanResult, options.only) };
|
|
2653
|
+
options = { ...options, only: withSequenceFixes(scanResult, withDefaultGrantRevokes(scanResult, options.only)) };
|
|
2511
2654
|
const plan = { sqlStatements: [], apiActions: [], skipped: [] };
|
|
2512
2655
|
const relevant = scanResult.checks.filter(
|
|
2513
2656
|
(c) => c.status === "drifted" && (!options.checks || options.checks.includes(c.check))
|
|
@@ -2621,7 +2764,12 @@ async function executeSql(dbUrl, statements, result, transactional, sourceMajor)
|
|
|
2621
2764
|
try {
|
|
2622
2765
|
const olderTarget = sourceMajor !== void 0 && await majorOf(client) < sourceMajor;
|
|
2623
2766
|
if (transactional) await runInTransaction(client, statements, result, olderTarget);
|
|
2624
|
-
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
|
+
}
|
|
2625
2773
|
} finally {
|
|
2626
2774
|
await client.end();
|
|
2627
2775
|
}
|
|
@@ -2676,7 +2824,7 @@ function unmetDependency(sql, err, olderTarget = false) {
|
|
|
2676
2824
|
return "the target's PostgreSQL is older than the source's and does not support it";
|
|
2677
2825
|
}
|
|
2678
2826
|
if (/(?:^|;)\s*CREATE\s+EXTENSION\b/i.test(sqlSkeleton(sql))) {
|
|
2679
|
-
return EXTENSION_UNAVAILABLE.has(code) ?
|
|
2827
|
+
return EXTENSION_UNAVAILABLE.has(code) ? EXTENSION_NOT_SHIPPED : void 0;
|
|
2680
2828
|
}
|
|
2681
2829
|
if (ABSENT_ON_TARGET.has(code) || code === UNDEFINED_COLUMN) {
|
|
2682
2830
|
return "it needs something the target does not have";
|
|
@@ -2697,15 +2845,41 @@ function revokesFromAbsent(sql) {
|
|
|
2697
2845
|
}
|
|
2698
2846
|
return targets.size === 1;
|
|
2699
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
|
+
}
|
|
2700
2859
|
async function runBatch(client, statements, result, olderTarget = false) {
|
|
2701
2860
|
if (statements.length === 0) return true;
|
|
2702
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
|
+
};
|
|
2703
2870
|
await client.query("BEGIN");
|
|
2704
2871
|
let pending = statements;
|
|
2705
2872
|
let unmet = [];
|
|
2706
2873
|
while (pending.length > 0) {
|
|
2707
2874
|
unmet = [];
|
|
2708
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
|
+
}
|
|
2709
2883
|
await client.query("SAVEPOINT sf_fix");
|
|
2710
2884
|
try {
|
|
2711
2885
|
await client.query(stmt.sql);
|
|
@@ -2717,11 +2891,11 @@ async function runBatch(client, statements, result, olderTarget = false) {
|
|
|
2717
2891
|
unmet.push({ stmt, err, why });
|
|
2718
2892
|
continue;
|
|
2719
2893
|
}
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
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);
|
|
2725
2899
|
}
|
|
2726
2900
|
}
|
|
2727
2901
|
if (unmet.length === pending.length) break;
|
|
@@ -2732,13 +2906,24 @@ async function runBatch(client, statements, result, olderTarget = false) {
|
|
|
2732
2906
|
for (const { stmt } of gone) {
|
|
2733
2907
|
done.push({ check: stmt.check, issueId: stmt.issueId, sql: stmt.sql, note: "nothing to revoke: the object is not on the target" });
|
|
2734
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];
|
|
2735
2916
|
await client.query("COMMIT");
|
|
2736
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);
|
|
2737
2922
|
for (const { stmt, err, why } of unmet) {
|
|
2738
2923
|
result.errors.push({
|
|
2739
2924
|
check: stmt.check,
|
|
2740
2925
|
issueId: stmt.issueId,
|
|
2741
|
-
error: `${errMsg(err)} \u2014 not applied: ${why}.
|
|
2926
|
+
error: `${errMsg(err)} \u2014 not applied: ${why}. Everything else was applied.`
|
|
2742
2927
|
});
|
|
2743
2928
|
}
|
|
2744
2929
|
return true;
|
|
@@ -3043,10 +3228,14 @@ async function sampleInto(psql, fromUrl, intoUrl, schemas, limit) {
|
|
|
3043
3228
|
}
|
|
3044
3229
|
return { sampled, unchecked };
|
|
3045
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
|
+
}
|
|
3046
3235
|
function pipeCopy(psql, fromUrl, intoUrl, out, into) {
|
|
3047
3236
|
return new Promise((resolve, reject) => {
|
|
3048
|
-
const reading = pgToolConnection(fromUrl);
|
|
3049
|
-
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) });
|
|
3050
3239
|
const reader = spawn(psql, [reading.url, "-X", "-q", "-v", "ON_ERROR_STOP=1", "-c", out], { stdio: ["ignore", "pipe", "pipe"], env: reading.env });
|
|
3051
3240
|
const writer = spawn(psql, [writing.url, "-X", "-q", "-v", "ON_ERROR_STOP=1", "-f", "-"], { stdio: ["pipe", "pipe", "pipe"], env: writing.env });
|
|
3052
3241
|
let stderr = "";
|
|
@@ -3565,6 +3754,7 @@ export {
|
|
|
3565
3754
|
PLATFORM_ROLES,
|
|
3566
3755
|
RolesCheck,
|
|
3567
3756
|
ExtensionsCheck,
|
|
3757
|
+
dataScope,
|
|
3568
3758
|
runDbDiff,
|
|
3569
3759
|
isDestructiveSql,
|
|
3570
3760
|
destructiveReason,
|
|
@@ -3593,4 +3783,4 @@ export {
|
|
|
3593
3783
|
residualHeldBack,
|
|
3594
3784
|
proofScope
|
|
3595
3785
|
};
|
|
3596
|
-
//# 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,
|