@akal/supaforge 0.0.44 → 0.0.45

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.
@@ -6,13 +6,13 @@ import {
6
6
  formatSkips,
7
7
  renderDetailed,
8
8
  renderSummary
9
- } from "./chunk-WZALUV4T.js";
9
+ } from "./chunk-EMRM4RIV.js";
10
10
  import {
11
11
  createDefaultRegistry,
12
12
  proveBeforeApply,
13
13
  scan,
14
14
  summarizeByKind
15
- } from "./chunk-ZJPJTC6R.js";
15
+ } from "./chunk-DUTPOR7P.js";
16
16
  import {
17
17
  CHECK_META,
18
18
  CHECK_NAMES,
@@ -24,7 +24,7 @@ import {
24
24
  psqlBeside,
25
25
  resolveTableFilter,
26
26
  withDatabase
27
- } from "./chunk-FXBTUJON.js";
27
+ } from "./chunk-YABERWV7.js";
28
28
  import {
29
29
  isCommentOnly,
30
30
  splitSqlStatements
@@ -756,4 +756,4 @@ export {
756
756
  inertApplyFlags,
757
757
  Diff
758
758
  };
759
- //# sourceMappingURL=chunk-DLTCJNJI.js.map
759
+ //# sourceMappingURL=chunk-4RD66RHF.js.map
@@ -8,6 +8,7 @@ import {
8
8
  isComparisonCheck,
9
9
  parseStatements,
10
10
  planWork,
11
+ platformExtensionMoves,
11
12
  policyOnlyKeys,
12
13
  proofScope,
13
14
  proveConvergence,
@@ -18,8 +19,9 @@ import {
18
19
  schemaNotices,
19
20
  sqlSkeleton,
20
21
  sqlToIssues,
22
+ withPlatformExtensionCalls,
21
23
  withoutAbsentRoles
22
- } from "./chunk-FXBTUJON.js";
24
+ } from "./chunk-YABERWV7.js";
23
25
  import {
24
26
  splitSqlStatements
25
27
  } from "./chunk-WK5YTINL.js";
@@ -413,7 +415,11 @@ var SchemaCheck = class extends Check {
413
415
  this.fetchIgnoredSchemaTables(ctx.target.dbUrl, ignoreSchemas)
414
416
  ]);
415
417
  for (const notice of schemaNotices(result.notices ?? [])) ctx.onNotice?.(notice);
416
- const issues = sqlToIssues(result, "schema", ignoreSchemas, ignoredSchemaTables);
418
+ let issues = sqlToIssues(result, "schema", ignoreSchemas, ignoredSchemaTables);
419
+ const moves = platformExtensionMoves(issues);
420
+ if (moves.length) {
421
+ issues = withPlatformExtensionCalls(issues, moves, await this.extensionFunctions(ctx.target.dbUrl, moves));
422
+ }
417
423
  const roles = await this.targetRoles(ctx.target.dbUrl);
418
424
  return roles?.size ? withoutAbsentRoles(issues, roles) : issues;
419
425
  } catch (err) {
@@ -433,6 +439,27 @@ var SchemaCheck = class extends Check {
433
439
  * Returns a Set of lowercase table names, bare and schema-qualified. Fails silently so that a transient
434
440
  * DB error here never blocks the main schema diff.
435
441
  */
442
+ /**
443
+ * The functions each extension owns on the target, by name. Unreadable,
444
+ * none: the calls are then left as the source wrote them.
445
+ */
446
+ async extensionFunctions(dbUrl, moves) {
447
+ const owned = /* @__PURE__ */ new Map();
448
+ try {
449
+ const rows = await this.queryFn(dbUrl, `SELECT e.extname, p.proname
450
+ FROM pg_depend d
451
+ JOIN pg_extension e ON e.oid = d.refobjid
452
+ JOIN pg_proc p ON p.oid = d.objid
453
+ WHERE d.classid = 'pg_proc'::regclass AND d.refclassid = 'pg_extension'::regclass
454
+ AND d.deptype = 'e' AND e.extname = ANY($1)`, [moves.map((m) => m.name)]);
455
+ for (const { extname, proname } of rows) {
456
+ if (!owned.has(extname)) owned.set(extname, /* @__PURE__ */ new Set());
457
+ owned.get(extname).add(proname);
458
+ }
459
+ } catch {
460
+ }
461
+ return owned;
462
+ }
436
463
  /** The target's roles, or undefined when they cannot be read. */
437
464
  async targetRoles(dbUrl) {
438
465
  try {
@@ -2417,4 +2444,4 @@ export {
2417
2444
  createDefaultRegistry,
2418
2445
  proveBeforeApply
2419
2446
  };
2420
- //# sourceMappingURL=chunk-ZJPJTC6R.js.map
2447
+ //# sourceMappingURL=chunk-DUTPOR7P.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CHECK_META,
3
3
  isComparisonCheck
4
- } from "./chunk-FXBTUJON.js";
4
+ } from "./chunk-YABERWV7.js";
5
5
  import {
6
6
  CHECK_LINE_PADDING,
7
7
  bold,
@@ -241,4 +241,4 @@ export {
241
241
  renderDetailed,
242
242
  formatSkips
243
243
  };
244
- //# sourceMappingURL=chunk-WZALUV4T.js.map
244
+ //# sourceMappingURL=chunk-EMRM4RIV.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  targetFingerprint,
3
3
  writtenAgainst
4
- } from "./chunk-UC2Z5ISB.js";
4
+ } from "./chunk-UPWUXQ24.js";
5
5
  import {
6
6
  ensureMigrationsTable,
7
7
  getAppliedVersions,
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-HWRRFF55.js";
11
11
  import {
12
12
  isDestructiveSql
13
- } from "./chunk-FXBTUJON.js";
13
+ } from "./chunk-YABERWV7.js";
14
14
  import {
15
15
  splitSqlStatements
16
16
  } from "./chunk-WK5YTINL.js";
@@ -180,4 +180,4 @@ export {
180
180
  findDestructiveStatements,
181
181
  truncateSql
182
182
  };
183
- //# sourceMappingURL=chunk-DTTQWSSU.js.map
183
+ //# sourceMappingURL=chunk-HGCTVCLV.js.map
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  migrationsDir,
3
3
  writeMigrationFile
4
- } from "./chunk-HMTFOYDT.js";
4
+ } from "./chunk-JVZYVZUH.js";
5
5
  import {
6
6
  createDefaultRegistry,
7
7
  proveBeforeApply,
8
8
  scan
9
- } from "./chunk-ZJPJTC6R.js";
9
+ } from "./chunk-DUTPOR7P.js";
10
10
  import {
11
11
  CHECK_NAMES,
12
12
  promote
13
- } from "./chunk-FXBTUJON.js";
13
+ } from "./chunk-YABERWV7.js";
14
14
  import {
15
15
  captureSnapshot,
16
16
  unrestorableSchema
@@ -530,4 +530,4 @@ export {
530
530
  clearLastScanResult,
531
531
  createServer
532
532
  };
533
- //# sourceMappingURL=chunk-HHM37KPD.js.map
533
+ //# sourceMappingURL=chunk-J64XMOXU.js.map
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  targetFingerprint,
3
3
  writtenAgainstLine
4
- } from "./chunk-UC2Z5ISB.js";
4
+ } from "./chunk-UPWUXQ24.js";
5
5
  import {
6
6
  RolesCheck,
7
7
  isDestructiveSql,
8
8
  runDbDiff
9
- } from "./chunk-FXBTUJON.js";
9
+ } from "./chunk-YABERWV7.js";
10
10
  import {
11
11
  splitSqlStatements
12
12
  } from "./chunk-WK5YTINL.js";
@@ -91,4 +91,4 @@ export {
91
91
  writeMigrationFile,
92
92
  generateTimestamp
93
93
  };
94
- //# sourceMappingURL=chunk-HMTFOYDT.js.map
94
+ //# sourceMappingURL=chunk-JVZYVZUH.js.map
@@ -18,7 +18,7 @@ import {
18
18
  rolesNamedBy,
19
19
  sqlSkeleton,
20
20
  statementSubject
21
- } from "./chunk-FXBTUJON.js";
21
+ } from "./chunk-YABERWV7.js";
22
22
  import {
23
23
  isCommentOnly,
24
24
  isPsqlMetaCommand,
@@ -900,4 +900,4 @@ export {
900
900
  previewMigrationRestore,
901
901
  summarizeStatement
902
902
  };
903
- //# sourceMappingURL=chunk-IHGINEPX.js.map
903
+ //# sourceMappingURL=chunk-R4FSOTB6.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  comparedSchemas,
3
3
  fingerprint
4
- } from "./chunk-FXBTUJON.js";
4
+ } from "./chunk-YABERWV7.js";
5
5
 
6
6
  // src/written-against.ts
7
7
  import { createHash } from "crypto";
@@ -24,4 +24,4 @@ export {
24
24
  writtenAgainstLine,
25
25
  writtenAgainst
26
26
  };
27
- //# sourceMappingURL=chunk-UC2Z5ISB.js.map
27
+ //# sourceMappingURL=chunk-UPWUXQ24.js.map
@@ -871,6 +871,10 @@ var BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
871
871
  function sqlSkeleton(sql) {
872
872
  return sql.replace(DOLLAR_BODY, " ").replace(STRING_LITERAL, " '' ").replace(LINE_COMMENT, " ").replace(BLOCK_COMMENT, " ");
873
873
  }
874
+ function codeMask(sql) {
875
+ const blank = (m) => m.replace(/[^\n]/g, " ");
876
+ return sql.replace(DOLLAR_BODY, blank).replace(STRING_LITERAL, blank).replace(LINE_COMMENT, blank).replace(BLOCK_COMMENT, blank);
877
+ }
874
878
  var NAME_PART = String.raw`"(?:[^"]|"")+"|[\w$]+`;
875
879
  var IDENT = String.raw`(?:${NAME_PART})(?:\s*\.\s*(?:${NAME_PART}))?`;
876
880
  function bareName(identifier) {
@@ -1528,6 +1532,49 @@ function platformExtensionMove(upSql, downSql) {
1528
1532
  if (unquoted(down[1]) !== name || !isPlatformExtension({ name, schema: targetSchema })) return void 0;
1529
1533
  return { name, sourceSchema: unquoted(up[2]), targetSchema };
1530
1534
  }
1535
+ function platformExtensionMoves(issues) {
1536
+ return issues.flatMap((issue) => {
1537
+ if (!/-extension-schema-\d+$/.test(issue.id) || issue.sql) return [];
1538
+ const source = issue.sourceValue;
1539
+ const target = issue.targetValue;
1540
+ return source?.name && source.schema && target?.schema ? [{ name: source.name, sourceSchema: source.schema, targetSchema: target.schema }] : [];
1541
+ });
1542
+ }
1543
+ var quoteIdent2 = (name) => /^[a-z_][a-z0-9_$]*$/.test(name) ? name : `"${name.replace(/"/g, '""')}"`;
1544
+ function withPlatformExtensionCalls(issues, moves, functions) {
1545
+ const rules = moves.flatMap((move) => [...functions.get(move.name) ?? []].map((fn) => ({ move, fn })));
1546
+ if (!rules.length) return issues;
1547
+ const nameRe = String.raw`("(?:[^"]|"")+"|[\w$]+)`;
1548
+ const call = new RegExp(String.raw`${nameRe}(\s*\.\s*)${nameRe}(?=\s*\()`, "g");
1549
+ const unq = (part) => part.startsWith('"') ? part.slice(1, -1).replace(/""/g, '"') : part.toLowerCase();
1550
+ const rewrite = (sql, seen) => {
1551
+ const mask = codeMask(sql);
1552
+ let out = "";
1553
+ let at = 0;
1554
+ for (const m of mask.matchAll(call)) {
1555
+ const schema = unq(m[1]);
1556
+ const fn = unq(m[3]);
1557
+ const rule = rules.find((r) => r.move.sourceSchema === schema && r.fn === fn);
1558
+ if (!rule) continue;
1559
+ out += sql.slice(at, m.index) + quoteIdent2(rule.move.targetSchema) + m[2] + sql.slice(m.index + m[1].length + m[2].length, m.index + m[0].length);
1560
+ at = m.index + m[0].length;
1561
+ seen.add(`${quoteIdent2(schema)}.${quoteIdent2(fn)}() \u2192 ${quoteIdent2(rule.move.targetSchema)}.${quoteIdent2(fn)}()`);
1562
+ }
1563
+ return out + sql.slice(at);
1564
+ };
1565
+ return issues.map((issue) => {
1566
+ if (!issue.sql) return issue;
1567
+ const seen = /* @__PURE__ */ new Set();
1568
+ const up = rewrite(issue.sql.up, seen);
1569
+ const down = rewrite(issue.sql.down, seen);
1570
+ if (!seen.size) return issue;
1571
+ return {
1572
+ ...issue,
1573
+ description: `${issue.description} Calls written for where the target keeps a Supabase extension: ${[...seen].join(", ")}.`,
1574
+ sql: { ...issue.sql, up, down }
1575
+ };
1576
+ });
1577
+ }
1531
1578
  function issuesFromUnits(upUnits, downUnits, check, ignoreSchemas, ignoredSchemaTables) {
1532
1579
  const pairs = pairUnits(upUnits, downUnits).filter(({ up, down }) => !(ignoreSchemas?.length && isCrossSchemaFkUnit(up, down, ignoreSchemas, ignoredSchemaTables)) && !platformDefaultPrivileges(up.sql));
1533
1580
  return pairs.map(({ up, down }, i) => {
@@ -1540,7 +1587,9 @@ function issuesFromUnits(upUnits, downUnits, check, ignoreSchemas, ignoredSchema
1540
1587
  check,
1541
1588
  severity: "info",
1542
1589
  title: `Extension in another schema: ${platform.name}`,
1543
- description: `Extension "${platform.name}" is in schema ${platform.sourceSchema} on the source and in ${platform.targetSchema} on the target, where Supabase installs it. It is the same extension, and what uses it works either way; nothing to apply.`
1590
+ description: `Extension "${platform.name}" is in schema ${platform.sourceSchema} on the source and in ${platform.targetSchema} on the target, where Supabase installs it. It is the same extension, and what uses it works either way; nothing to apply.`,
1591
+ sourceValue: { name: platform.name, schema: platform.sourceSchema },
1592
+ targetValue: { name: platform.name, schema: platform.targetSchema }
1544
1593
  };
1545
1594
  }
1546
1595
  const statements = splitStatements(upSql);
@@ -3391,6 +3440,8 @@ export {
3391
3440
  destructiveReason,
3392
3441
  sqlToIssues,
3393
3442
  schemaNotices,
3443
+ platformExtensionMoves,
3444
+ withPlatformExtensionCalls,
3394
3445
  withoutAbsentRoles,
3395
3446
  ABSENT_ON_TARGET,
3396
3447
  EXTENSION_UNAVAILABLE,
@@ -3412,4 +3463,4 @@ export {
3412
3463
  residualHeldBack,
3413
3464
  proofScope
3414
3465
  };
3415
- //# sourceMappingURL=chunk-FXBTUJON.js.map
3466
+ //# sourceMappingURL=chunk-YABERWV7.js.map
@@ -2,11 +2,11 @@ import {
2
2
  Diff,
3
3
  inertApplyFlags,
4
4
  rollbackHint
5
- } from "../chunk-DLTCJNJI.js";
5
+ } from "../chunk-4RD66RHF.js";
6
6
  import "../chunk-Q43MN6NE.js";
7
- import "../chunk-WZALUV4T.js";
8
- import "../chunk-ZJPJTC6R.js";
9
- import "../chunk-FXBTUJON.js";
7
+ import "../chunk-EMRM4RIV.js";
8
+ import "../chunk-DUTPOR7P.js";
9
+ import "../chunk-YABERWV7.js";
10
10
  import "../chunk-WK5YTINL.js";
11
11
  import "../chunk-RQCXGO37.js";
12
12
  import "../chunk-CKH6J7DI.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-DLTCJNJI.js";
3
+ } from "../chunk-4RD66RHF.js";
4
4
  import "../chunk-Q43MN6NE.js";
5
- import "../chunk-WZALUV4T.js";
6
- import "../chunk-ZJPJTC6R.js";
7
- import "../chunk-FXBTUJON.js";
5
+ import "../chunk-EMRM4RIV.js";
6
+ import "../chunk-DUTPOR7P.js";
7
+ import "../chunk-YABERWV7.js";
8
8
  import "../chunk-WK5YTINL.js";
9
9
  import "../chunk-RQCXGO37.js";
10
10
  import "../chunk-CKH6J7DI.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createServer
3
- } from "../chunk-HHM37KPD.js";
4
- import "../chunk-HMTFOYDT.js";
5
- import "../chunk-UC2Z5ISB.js";
6
- import "../chunk-ZJPJTC6R.js";
7
- import "../chunk-FXBTUJON.js";
3
+ } from "../chunk-J64XMOXU.js";
4
+ import "../chunk-JVZYVZUH.js";
5
+ import "../chunk-UPWUXQ24.js";
6
+ import "../chunk-DUTPOR7P.js";
7
+ import "../chunk-YABERWV7.js";
8
8
  import "../chunk-WK5YTINL.js";
9
9
  import "../chunk-ZLNP3DUB.js";
10
10
  import "../chunk-USIOUMYL.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  truncateSql
3
- } from "../../chunk-DTTQWSSU.js";
3
+ } from "../../chunk-HGCTVCLV.js";
4
4
  import {
5
5
  generateTimestamp,
6
6
  writeMigrationFile
7
- } from "../../chunk-HMTFOYDT.js";
8
- import "../../chunk-UC2Z5ISB.js";
7
+ } from "../../chunk-JVZYVZUH.js";
8
+ import "../../chunk-UPWUXQ24.js";
9
9
  import "../../chunk-HWRRFF55.js";
10
- import "../../chunk-FXBTUJON.js";
10
+ import "../../chunk-YABERWV7.js";
11
11
  import "../../chunk-WK5YTINL.js";
12
12
  import {
13
13
  BaseCommand
@@ -2,10 +2,10 @@ import {
2
2
  MigrateRun,
3
3
  findDestructiveStatements,
4
4
  truncateSql
5
- } from "../../chunk-DTTQWSSU.js";
6
- import "../../chunk-UC2Z5ISB.js";
5
+ } from "../../chunk-HGCTVCLV.js";
6
+ import "../../chunk-UPWUXQ24.js";
7
7
  import "../../chunk-HWRRFF55.js";
8
- import "../../chunk-FXBTUJON.js";
8
+ import "../../chunk-YABERWV7.js";
9
9
  import "../../chunk-WK5YTINL.js";
10
10
  import "../../chunk-CKH6J7DI.js";
11
11
  import "../../chunk-USIOUMYL.js";
@@ -5,10 +5,10 @@ import {
5
5
  restoreFromMigrations,
6
6
  restoreFromSnapshot,
7
7
  summarizeStatement
8
- } from "../chunk-IHGINEPX.js";
8
+ } from "../chunk-R4FSOTB6.js";
9
9
  import "../chunk-KPU6G6BO.js";
10
10
  import "../chunk-HWRRFF55.js";
11
- import "../chunk-FXBTUJON.js";
11
+ import "../chunk-YABERWV7.js";
12
12
  import "../chunk-WK5YTINL.js";
13
13
  import {
14
14
  renderTip
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-DLTCJNJI.js";
3
+ } from "../chunk-4RD66RHF.js";
4
4
  import "../chunk-Q43MN6NE.js";
5
- import "../chunk-WZALUV4T.js";
6
- import "../chunk-ZJPJTC6R.js";
7
- import "../chunk-FXBTUJON.js";
5
+ import "../chunk-EMRM4RIV.js";
6
+ import "../chunk-DUTPOR7P.js";
7
+ import "../chunk-YABERWV7.js";
8
8
  import "../chunk-WK5YTINL.js";
9
9
  import "../chunk-RQCXGO37.js";
10
10
  import "../chunk-CKH6J7DI.js";
package/dist/index.js CHANGED
@@ -3,37 +3,37 @@ import {
3
3
  createServer,
4
4
  getLastScanResult,
5
5
  setLastScanResult
6
- } from "./chunk-HHM37KPD.js";
6
+ } from "./chunk-J64XMOXU.js";
7
7
  import {
8
8
  previewMigrationRestore,
9
9
  previewSnapshotRestore,
10
10
  restoreFromMigrations,
11
11
  restoreFromSnapshot
12
- } from "./chunk-IHGINEPX.js";
12
+ } from "./chunk-R4FSOTB6.js";
13
13
  import {
14
14
  backup,
15
15
  listMigrationFiles,
16
16
  loadMigrations
17
17
  } from "./chunk-KPU6G6BO.js";
18
- import "./chunk-HMTFOYDT.js";
19
- import "./chunk-UC2Z5ISB.js";
18
+ import "./chunk-JVZYVZUH.js";
19
+ import "./chunk-UPWUXQ24.js";
20
20
  import "./chunk-HWRRFF55.js";
21
21
  import {
22
22
  renderDetailed,
23
23
  renderSummary
24
- } from "./chunk-WZALUV4T.js";
24
+ } from "./chunk-EMRM4RIV.js";
25
25
  import {
26
26
  CheckRegistry,
27
27
  computeScore,
28
28
  createDefaultRegistry,
29
29
  scan,
30
30
  summarize
31
- } from "./chunk-ZJPJTC6R.js";
31
+ } from "./chunk-DUTPOR7P.js";
32
32
  import {
33
33
  CHECK_META,
34
34
  CHECK_NAMES,
35
35
  promote
36
- } from "./chunk-FXBTUJON.js";
36
+ } from "./chunk-YABERWV7.js";
37
37
  import "./chunk-WK5YTINL.js";
38
38
  import {
39
39
  BRANCH_DB_PREFIX,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akal/supaforge",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "mcpName": "io.github.akalsoftware/supaforge",
5
5
  "description": "Diff and sync your Supabase environments",
6
6
  "author": "Akal Software Ltd",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@akal/pg-conformance": "~0.0.19",
59
- "@dbdiff/cli": "3.0.0-rc.36",
59
+ "@dbdiff/cli": "3.0.0-rc.37",
60
60
  "@modelcontextprotocol/sdk": "^1.32.1",
61
61
  "@oclif/core": "^5.1.12",
62
62
  "@supabase/supabase-js": "^2.103.0",