@akal/supaforge 0.0.42 → 0.0.44

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-UEF2NY7H.js";
9
+ } from "./chunk-WZALUV4T.js";
10
10
  import {
11
11
  createDefaultRegistry,
12
12
  proveBeforeApply,
13
13
  scan,
14
14
  summarizeByKind
15
- } from "./chunk-UH4G2KRR.js";
15
+ } from "./chunk-ZJPJTC6R.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-TES62VLH.js";
27
+ } from "./chunk-FXBTUJON.js";
28
28
  import {
29
29
  isCommentOnly,
30
30
  splitSqlStatements
@@ -38,13 +38,13 @@ import {
38
38
  import {
39
39
  isCloneDatabase,
40
40
  sourceLooksLikeCloneOf
41
- } from "./chunk-Q4YNLGV4.js";
41
+ } from "./chunk-KTATU64Y.js";
42
42
  import {
43
43
  describeMissingPgDump,
44
44
  getServerMajorVersion,
45
45
  parseFlagList,
46
46
  resolvePgDumpPath
47
- } from "./chunk-X3QQ64TU.js";
47
+ } from "./chunk-USIOUMYL.js";
48
48
  import {
49
49
  Preflight,
50
50
  pgQuery,
@@ -756,4 +756,4 @@ export {
756
756
  inertApplyFlags,
757
757
  Diff
758
758
  };
759
- //# sourceMappingURL=chunk-QIJLIKB3.js.map
759
+ //# sourceMappingURL=chunk-DLTCJNJI.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  targetFingerprint,
3
3
  writtenAgainst
4
- } from "./chunk-46QUNEET.js";
4
+ } from "./chunk-UC2Z5ISB.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-TES62VLH.js";
13
+ } from "./chunk-FXBTUJON.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-UWFICLWO.js.map
183
+ //# sourceMappingURL=chunk-DTTQWSSU.js.map
@@ -3,6 +3,7 @@ import {
3
3
  splitSqlStatements
4
4
  } from "./chunk-WK5YTINL.js";
5
5
  import {
6
+ dbdiffPgToolsEnv,
6
7
  describeMissingPgDump,
7
8
  escapeRegex,
8
9
  getServerMajorVersion,
@@ -10,7 +11,7 @@ import {
10
11
  matchesGlob,
11
12
  parseFlagList,
12
13
  resolvePgDumpPath
13
- } from "./chunk-X3QQ64TU.js";
14
+ } from "./chunk-USIOUMYL.js";
14
15
  import {
15
16
  Check,
16
17
  heldSnapshot,
@@ -636,6 +637,127 @@ function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set()) {
636
637
  return issues;
637
638
  }
638
639
 
640
+ // src/checks/extensions.ts
641
+ var ExtensionsCheck = class extends Check {
642
+ constructor(queryFn = pgQuery) {
643
+ super();
644
+ this.queryFn = queryFn;
645
+ }
646
+ queryFn;
647
+ name = "extensions";
648
+ async scan(ctx) {
649
+ const [source, target, reachable] = await Promise.all([
650
+ this.fetchExtensions(ctx.source.dbUrl),
651
+ this.fetchExtensions(ctx.target.dbUrl),
652
+ this.fetchUpdates(ctx.target.dbUrl)
653
+ ]);
654
+ const ignored = new Set(ctx.config.ignoreExtensions ?? []);
655
+ return diffExtensions(source, target.filter((e) => !ignored.has(e.name) || source.some((s) => s.name === e.name)), reachable);
656
+ }
657
+ /** The versions each installed extension can be updated to on this server. */
658
+ async fetchUpdates(dbUrl) {
659
+ try {
660
+ const rows = await this.queryFn(dbUrl, UPDATES_SQL);
661
+ const out = /* @__PURE__ */ new Map();
662
+ for (const r of rows) out.set(r.name, (out.get(r.name) ?? /* @__PURE__ */ new Set()).add(r.version));
663
+ return out;
664
+ } catch {
665
+ return void 0;
666
+ }
667
+ }
668
+ async fetchExtensions(dbUrl) {
669
+ return await this.queryFn(dbUrl, EXTENSIONS_SQL);
670
+ }
671
+ };
672
+ var EXTENSIONS_SQL = `
673
+ SELECT e.extname AS name,
674
+ e.extversion AS version,
675
+ n.nspname AS schema
676
+ FROM pg_extension e
677
+ JOIN pg_namespace n ON n.oid = e.extnamespace
678
+ ORDER BY e.extname
679
+ `;
680
+ var UPDATES_SQL = `
681
+ SELECT e.extname AS name, p.target AS version
682
+ FROM pg_extension e
683
+ CROSS JOIN LATERAL pg_extension_update_paths(e.extname) p
684
+ WHERE p.source = e.extversion AND p.path IS NOT NULL
685
+ `;
686
+ var SUPABASE_PLATFORM_EXTENSIONS = [
687
+ { name: "pg_graphql", schemas: ["graphql"] },
688
+ { name: "supabase_vault", schemas: ["vault"] },
689
+ { name: "pgsodium", schemas: ["pgsodium"] },
690
+ { name: "pg_stat_statements", schemas: ["extensions"] },
691
+ { name: "pgcrypto", schemas: ["extensions"] },
692
+ { name: "pgjwt", schemas: ["extensions"] },
693
+ { name: "uuid-ossp", schemas: ["extensions"] }
694
+ ];
695
+ function isPlatformExtension(ext) {
696
+ return SUPABASE_PLATFORM_EXTENSIONS.some((p) => p.name === ext.name && p.schemas.includes(ext.schema));
697
+ }
698
+ function diffExtensions(source, target, reachable) {
699
+ const issues = [];
700
+ const sourceMap = new Map(source.map((e) => [e.name, e]));
701
+ const targetMap = new Map(target.map((e) => [e.name, e]));
702
+ for (const [name, ext] of sourceMap) {
703
+ if (!targetMap.has(name)) {
704
+ issues.push({
705
+ id: `ext-missing-${name}`,
706
+ check: "extensions",
707
+ severity: "warning",
708
+ title: `Missing extension: ${name}`,
709
+ description: `Extension "${name}" (v${ext.version}) is enabled in source (schema: ${ext.schema}) but not in target.`,
710
+ sourceValue: ext,
711
+ sql: {
712
+ // Into the schema it is in on the source, which plain PostgreSQL
713
+ // may not have — Supabase's `extensions`. Made first; if the server
714
+ // does not ship the extension, the fix is left out with it. A
715
+ // system schema (pg_cron's pg_catalog) is always there, and cannot
716
+ // be made.
717
+ up: ext.schema === "public" ? `CREATE EXTENSION IF NOT EXISTS ${quoteName(name)};` : `${ext.schema.startsWith("pg_") ? "" : `CREATE SCHEMA IF NOT EXISTS ${quoteName(ext.schema)};
718
+ `}CREATE EXTENSION IF NOT EXISTS ${quoteName(name)} SCHEMA ${quoteName(ext.schema)};`,
719
+ down: `DROP EXTENSION IF EXISTS ${quoteName(name)};`
720
+ }
721
+ });
722
+ }
723
+ }
724
+ for (const [name, ext] of targetMap) {
725
+ if (!sourceMap.has(name) && !isPlatformExtension(ext)) {
726
+ issues.push({
727
+ id: `ext-extra-${name}`,
728
+ check: "extensions",
729
+ severity: "info",
730
+ title: `Extra extension: ${name}`,
731
+ description: `Extension "${name}" (v${ext.version}) is enabled in target (schema: ${ext.schema}) but not in source.`,
732
+ targetValue: ext
733
+ });
734
+ }
735
+ }
736
+ for (const [name, srcExt] of sourceMap) {
737
+ const tgtExt = targetMap.get(name);
738
+ if (!tgtExt) continue;
739
+ if (srcExt.version !== tgtExt.version) {
740
+ const updatable = !reachable || reachable.get(name)?.has(srcExt.version);
741
+ issues.push({
742
+ id: `ext-version-${name}`,
743
+ check: "extensions",
744
+ severity: "info",
745
+ title: `Extension version mismatch: ${name}`,
746
+ description: `Extension "${name}" is v${srcExt.version} in source but v${tgtExt.version} in target.`,
747
+ sourceValue: srcExt,
748
+ targetValue: tgtExt,
749
+ ...updatable ? {
750
+ sql: {
751
+ up: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(srcExt.version)};`,
752
+ down: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(tgtExt.version)};`
753
+ }
754
+ } : { manualOnly: `the target cannot go from v${tgtExt.version} to v${srcExt.version}: its server has no update path there (an extension cannot be moved down a version)` }
755
+ });
756
+ }
757
+ }
758
+ return issues;
759
+ }
760
+
639
761
  // src/sql-ast.ts
640
762
  import { loadModule, parseSync } from "libpg-query";
641
763
  await loadModule();
@@ -1162,9 +1284,11 @@ async function runDbDiff(options) {
1162
1284
  const args = [...prefixArgs, ...buildDbDiffArgs(options, outputFile)];
1163
1285
  const timeoutMs = resolveDbDiffTimeoutMs(options.timeoutSeconds);
1164
1286
  try {
1287
+ const pgTools = options.type === "schema" ? await dbdiffPgToolsEnv([options.sourceUrl, options.targetUrl]) : {};
1165
1288
  const running = execFileAsync(command, args, {
1166
1289
  timeout: timeoutMs,
1167
- maxBuffer: DBDIFF_MAX_BUFFER
1290
+ maxBuffer: DBDIFF_MAX_BUFFER,
1291
+ ...Object.keys(pgTools).length ? { env: { ...process.env, ...pgTools } } : {}
1168
1292
  });
1169
1293
  attachProgress(running, options.onProgress);
1170
1294
  const { stdout } = await running;
@@ -1394,11 +1518,31 @@ function platformDefaultPrivileges(sql) {
1394
1518
  const name = role.startsWith('"') ? role.slice(1, -1).replace(/""/g, '"') : role.toLowerCase();
1395
1519
  return name !== "postgres" && PLATFORM_ROLES.includes(name);
1396
1520
  }
1521
+ function platformExtensionMove(upSql, downSql) {
1522
+ const re = /^\s*ALTER\s+EXTENSION\s+("(?:[^"]|"")+"|[\w$-]+)\s+SET\s+SCHEMA\s+("(?:[^"]|"")+"|[\w$]+)\s*;?\s*$/i;
1523
+ const up = re.exec(upSql);
1524
+ const down = re.exec(downSql);
1525
+ if (!up || !down) return void 0;
1526
+ const name = unquoted(up[1]);
1527
+ const targetSchema = unquoted(down[2]);
1528
+ if (unquoted(down[1]) !== name || !isPlatformExtension({ name, schema: targetSchema })) return void 0;
1529
+ return { name, sourceSchema: unquoted(up[2]), targetSchema };
1530
+ }
1397
1531
  function issuesFromUnits(upUnits, downUnits, check, ignoreSchemas, ignoredSchemaTables) {
1398
1532
  const pairs = pairUnits(upUnits, downUnits).filter(({ up, down }) => !(ignoreSchemas?.length && isCrossSchemaFkUnit(up, down, ignoreSchemas, ignoredSchemaTables)) && !platformDefaultPrivileges(up.sql));
1399
1533
  return pairs.map(({ up, down }, i) => {
1400
1534
  const upSql = up.sql;
1401
1535
  const downSql = down?.sql ?? "";
1536
+ const platform = platformExtensionMove(upSql, downSql);
1537
+ if (platform) {
1538
+ return {
1539
+ id: `${check}-extension-schema-${i + 1}`,
1540
+ check,
1541
+ severity: "info",
1542
+ 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.`
1544
+ };
1545
+ }
1402
1546
  const statements = splitStatements(upSql);
1403
1547
  const replaced = replacedObject(up, statements);
1404
1548
  const manualOnly = manualEnumChange(up);
@@ -1905,6 +2049,7 @@ var SCHEMA_RULES = [
1905
2049
  { match: /^\s*COMMENT\s+ON\b/i, label: "Comment changed", name: commentLabel },
1906
2050
  { match: /^\s*CREATE\s+EXTENSION\b/i, label: "Extension missing", name: extensionLabel },
1907
2051
  { match: /^\s*DROP\s+EXTENSION\b/i, label: "Extra extension", name: extensionLabel },
2052
+ { match: /^\s*ALTER\s+EXTENSION\b[^;]*\bSET\s+SCHEMA\b/is, label: "Extension in another schema", name: extensionLabel },
1908
2053
  { match: /^\s*CREATE\s+COLLATION\b/i, label: "Collation missing", name: named(AFTER.collation) },
1909
2054
  { match: /^\s*ALTER\s+COLLATION\b/i, label: "Collation altered", name: named(AFTER.collation) },
1910
2055
  { match: /^\s*DROP\s+COLLATION\b/i, label: "Extra collation", name: named(AFTER.collation) },
@@ -3240,6 +3385,7 @@ export {
3240
3385
  isComparisonCheck,
3241
3386
  PLATFORM_ROLES,
3242
3387
  RolesCheck,
3388
+ ExtensionsCheck,
3243
3389
  runDbDiff,
3244
3390
  isDestructiveSql,
3245
3391
  destructiveReason,
@@ -3266,4 +3412,4 @@ export {
3266
3412
  residualHeldBack,
3267
3413
  proofScope
3268
3414
  };
3269
- //# sourceMappingURL=chunk-TES62VLH.js.map
3415
+ //# sourceMappingURL=chunk-FXBTUJON.js.map
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  migrationsDir,
3
3
  writeMigrationFile
4
- } from "./chunk-A5QPF4KH.js";
4
+ } from "./chunk-HMTFOYDT.js";
5
5
  import {
6
6
  createDefaultRegistry,
7
7
  proveBeforeApply,
8
8
  scan
9
- } from "./chunk-UH4G2KRR.js";
9
+ } from "./chunk-ZJPJTC6R.js";
10
10
  import {
11
11
  CHECK_NAMES,
12
12
  promote
13
- } from "./chunk-TES62VLH.js";
13
+ } from "./chunk-FXBTUJON.js";
14
14
  import {
15
15
  captureSnapshot,
16
16
  unrestorableSchema
17
- } from "./chunk-QWGXUFUQ.js";
17
+ } from "./chunk-ZLNP3DUB.js";
18
18
  import {
19
19
  checkConnection
20
20
  } from "./chunk-RC7ZU7OV.js";
@@ -530,4 +530,4 @@ export {
530
530
  clearLastScanResult,
531
531
  createServer
532
532
  };
533
- //# sourceMappingURL=chunk-BYPLCJW3.js.map
533
+ //# sourceMappingURL=chunk-HHM37KPD.js.map
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  targetFingerprint,
3
3
  writtenAgainstLine
4
- } from "./chunk-46QUNEET.js";
4
+ } from "./chunk-UC2Z5ISB.js";
5
5
  import {
6
6
  RolesCheck,
7
7
  isDestructiveSql,
8
8
  runDbDiff
9
- } from "./chunk-TES62VLH.js";
9
+ } from "./chunk-FXBTUJON.js";
10
10
  import {
11
11
  splitSqlStatements
12
12
  } from "./chunk-WK5YTINL.js";
13
13
  import {
14
14
  slugify
15
- } from "./chunk-X3QQ64TU.js";
15
+ } from "./chunk-USIOUMYL.js";
16
16
  import {
17
17
  DEFAULT_MIGRATIONS_DIR,
18
18
  pgQuery
@@ -91,4 +91,4 @@ export {
91
91
  writeMigrationFile,
92
92
  generateTimestamp
93
93
  };
94
- //# sourceMappingURL=chunk-A5QPF4KH.js.map
94
+ //# sourceMappingURL=chunk-HMTFOYDT.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loadMigrations
3
- } from "./chunk-33DONN5N.js";
3
+ } from "./chunk-KPU6G6BO.js";
4
4
  import {
5
5
  ensureMigrationsTable,
6
6
  getAppliedVersions
@@ -18,7 +18,7 @@ import {
18
18
  rolesNamedBy,
19
19
  sqlSkeleton,
20
20
  statementSubject
21
- } from "./chunk-TES62VLH.js";
21
+ } from "./chunk-FXBTUJON.js";
22
22
  import {
23
23
  isCommentOnly,
24
24
  isPsqlMetaCommand,
@@ -27,7 +27,7 @@ import {
27
27
  } from "./chunk-WK5YTINL.js";
28
28
  import {
29
29
  loadSnapshot
30
- } from "./chunk-QWGXUFUQ.js";
30
+ } from "./chunk-ZLNP3DUB.js";
31
31
  import {
32
32
  newPgClient,
33
33
  pgQuery,
@@ -900,4 +900,4 @@ export {
900
900
  previewMigrationRestore,
901
901
  summarizeStatement
902
902
  };
903
- //# sourceMappingURL=chunk-HUR5UWQA.js.map
903
+ //# sourceMappingURL=chunk-IHGINEPX.js.map
@@ -6,10 +6,10 @@ import {
6
6
  captureSnapshot,
7
7
  findLatestSnapshot,
8
8
  loadSnapshot
9
- } from "./chunk-QWGXUFUQ.js";
9
+ } from "./chunk-ZLNP3DUB.js";
10
10
  import {
11
11
  slugify
12
- } from "./chunk-X3QQ64TU.js";
12
+ } from "./chunk-USIOUMYL.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-33DONN5N.js.map
248
+ //# sourceMappingURL=chunk-KPU6G6BO.js.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  captureSnapshot
3
- } from "./chunk-QWGXUFUQ.js";
3
+ } from "./chunk-ZLNP3DUB.js";
4
4
  import {
5
5
  checkPgDumpCompat
6
- } from "./chunk-X3QQ64TU.js";
6
+ } from "./chunk-USIOUMYL.js";
7
7
  import {
8
8
  newPgClient,
9
9
  pgQuery,
@@ -653,4 +653,4 @@ export {
653
653
  isCloneDatabase,
654
654
  sourceLooksLikeCloneOf
655
655
  };
656
- //# sourceMappingURL=chunk-Q4YNLGV4.js.map
656
+ //# sourceMappingURL=chunk-KTATU64Y.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  comparedSchemas,
3
3
  fingerprint
4
- } from "./chunk-TES62VLH.js";
4
+ } from "./chunk-FXBTUJON.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-46QUNEET.js.map
27
+ //# sourceMappingURL=chunk-UC2Z5ISB.js.map
@@ -61,6 +61,7 @@ function arrayLiteralElements(literal) {
61
61
  import { execFile } from "child_process";
62
62
  import { platform } from "os";
63
63
  import { existsSync } from "fs";
64
+ import { dirname, join } from "path";
64
65
  function parsePgDumpVersion(output) {
65
66
  const m = output.match(/(\d+)(?:\.\d+)?/);
66
67
  return m ? Number(m[1]) : null;
@@ -163,6 +164,19 @@ async function getServerMajorVersion(dbUrl) {
163
164
  await client.end();
164
165
  }
165
166
  }
167
+ async function dbdiffPgToolsEnv(dbUrls) {
168
+ if (process.env.DBDIFF_PG_DUMP || process.env.DBDIFF_PG_RESTORE) return {};
169
+ try {
170
+ const majors = await Promise.all(dbUrls.map((url) => getServerMajorVersion(url)));
171
+ const resolved = await resolvePgDumpPath(Math.max(...majors));
172
+ if (!resolved || resolved.path === "pg_dump") return {};
173
+ const pgRestore = join(dirname(resolved.path), "pg_restore");
174
+ if (!existsSync(pgRestore)) return {};
175
+ return { DBDIFF_PG_DUMP: resolved.path, DBDIFF_PG_RESTORE: pgRestore };
176
+ } catch {
177
+ return {};
178
+ }
179
+ }
166
180
  async function checkPgDumpCompat(dbUrl) {
167
181
  const serverMajor = await getServerMajorVersion(dbUrl);
168
182
  const resolved = await resolvePgDumpPath(serverMajor);
@@ -237,6 +251,7 @@ export {
237
251
  assertPgBinUsable,
238
252
  describeMissingPgDump,
239
253
  getServerMajorVersion,
254
+ dbdiffPgToolsEnv,
240
255
  checkPgDumpCompat
241
256
  };
242
- //# sourceMappingURL=chunk-X3QQ64TU.js.map
257
+ //# sourceMappingURL=chunk-USIOUMYL.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CHECK_META,
3
3
  isComparisonCheck
4
- } from "./chunk-TES62VLH.js";
4
+ } from "./chunk-FXBTUJON.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-UEF2NY7H.js.map
244
+ //# sourceMappingURL=chunk-WZALUV4T.js.map
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CHECK_NAMES,
3
+ ExtensionsCheck,
3
4
  RolesCheck,
4
5
  applyTableFilter,
5
6
  comparedSchemas,
@@ -18,7 +19,7 @@ import {
18
19
  sqlSkeleton,
19
20
  sqlToIssues,
20
21
  withoutAbsentRoles
21
- } from "./chunk-TES62VLH.js";
22
+ } from "./chunk-FXBTUJON.js";
22
23
  import {
23
24
  splitSqlStatements
24
25
  } from "./chunk-WK5YTINL.js";
@@ -33,7 +34,7 @@ import {
33
34
  readJsonArray,
34
35
  readJsonObject,
35
36
  schemaPolicySql
36
- } from "./chunk-QWGXUFUQ.js";
37
+ } from "./chunk-ZLNP3DUB.js";
37
38
  import {
38
39
  Check,
39
40
  CheckSkipped,
@@ -2124,115 +2125,6 @@ ${diffs.join("\n")}`,
2124
2125
  return issues;
2125
2126
  }
2126
2127
 
2127
- // src/checks/extensions.ts
2128
- var ExtensionsCheck = class extends Check {
2129
- constructor(queryFn = pgQuery) {
2130
- super();
2131
- this.queryFn = queryFn;
2132
- }
2133
- queryFn;
2134
- name = "extensions";
2135
- async scan(ctx) {
2136
- const [source, target, reachable] = await Promise.all([
2137
- this.fetchExtensions(ctx.source.dbUrl),
2138
- this.fetchExtensions(ctx.target.dbUrl),
2139
- this.fetchUpdates(ctx.target.dbUrl)
2140
- ]);
2141
- const ignored = new Set(ctx.config.ignoreExtensions ?? []);
2142
- return diffExtensions(source, target.filter((e) => !ignored.has(e.name) || source.some((s) => s.name === e.name)), reachable);
2143
- }
2144
- /** The versions each installed extension can be updated to on this server. */
2145
- async fetchUpdates(dbUrl) {
2146
- try {
2147
- const rows = await this.queryFn(dbUrl, UPDATES_SQL);
2148
- const out = /* @__PURE__ */ new Map();
2149
- for (const r of rows) out.set(r.name, (out.get(r.name) ?? /* @__PURE__ */ new Set()).add(r.version));
2150
- return out;
2151
- } catch {
2152
- return void 0;
2153
- }
2154
- }
2155
- async fetchExtensions(dbUrl) {
2156
- return await this.queryFn(dbUrl, EXTENSIONS_SQL);
2157
- }
2158
- };
2159
- var EXTENSIONS_SQL = `
2160
- SELECT e.extname AS name,
2161
- e.extversion AS version,
2162
- n.nspname AS schema
2163
- FROM pg_extension e
2164
- JOIN pg_namespace n ON n.oid = e.extnamespace
2165
- ORDER BY e.extname
2166
- `;
2167
- var UPDATES_SQL = `
2168
- SELECT e.extname AS name, p.target AS version
2169
- FROM pg_extension e
2170
- CROSS JOIN LATERAL pg_extension_update_paths(e.extname) p
2171
- WHERE p.source = e.extversion AND p.path IS NOT NULL
2172
- `;
2173
- function diffExtensions(source, target, reachable) {
2174
- const issues = [];
2175
- const sourceMap = new Map(source.map((e) => [e.name, e]));
2176
- const targetMap = new Map(target.map((e) => [e.name, e]));
2177
- for (const [name, ext] of sourceMap) {
2178
- if (!targetMap.has(name)) {
2179
- issues.push({
2180
- id: `ext-missing-${name}`,
2181
- check: "extensions",
2182
- severity: "warning",
2183
- title: `Missing extension: ${name}`,
2184
- description: `Extension "${name}" (v${ext.version}) is enabled in source (schema: ${ext.schema}) but not in target.`,
2185
- sourceValue: ext,
2186
- sql: {
2187
- // Into the schema it is in on the source, which plain PostgreSQL
2188
- // may not have — Supabase's `extensions`. Made first; if the server
2189
- // does not ship the extension, the fix is left out with it. A
2190
- // system schema (pg_cron's pg_catalog) is always there, and cannot
2191
- // be made.
2192
- up: ext.schema === "public" ? `CREATE EXTENSION IF NOT EXISTS ${quoteName(name)};` : `${ext.schema.startsWith("pg_") ? "" : `CREATE SCHEMA IF NOT EXISTS ${quoteName(ext.schema)};
2193
- `}CREATE EXTENSION IF NOT EXISTS ${quoteName(name)} SCHEMA ${quoteName(ext.schema)};`,
2194
- down: `DROP EXTENSION IF EXISTS ${quoteName(name)};`
2195
- }
2196
- });
2197
- }
2198
- }
2199
- for (const [name, ext] of targetMap) {
2200
- if (!sourceMap.has(name)) {
2201
- issues.push({
2202
- id: `ext-extra-${name}`,
2203
- check: "extensions",
2204
- severity: "info",
2205
- title: `Extra extension: ${name}`,
2206
- description: `Extension "${name}" (v${ext.version}) is enabled in target (schema: ${ext.schema}) but not in source.`,
2207
- targetValue: ext
2208
- });
2209
- }
2210
- }
2211
- for (const [name, srcExt] of sourceMap) {
2212
- const tgtExt = targetMap.get(name);
2213
- if (!tgtExt) continue;
2214
- if (srcExt.version !== tgtExt.version) {
2215
- const updatable = !reachable || reachable.get(name)?.has(srcExt.version);
2216
- issues.push({
2217
- id: `ext-version-${name}`,
2218
- check: "extensions",
2219
- severity: "info",
2220
- title: `Extension version mismatch: ${name}`,
2221
- description: `Extension "${name}" is v${srcExt.version} in source but v${tgtExt.version} in target.`,
2222
- sourceValue: srcExt,
2223
- targetValue: tgtExt,
2224
- ...updatable ? {
2225
- sql: {
2226
- up: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(srcExt.version)};`,
2227
- down: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(tgtExt.version)};`
2228
- }
2229
- } : { manualOnly: `the target cannot go from v${tgtExt.version} to v${srcExt.version}: its server has no update path there (an extension cannot be moved down a version)` }
2230
- });
2231
- }
2232
- }
2233
- return issues;
2234
- }
2235
-
2236
2128
  // src/checks/queues.ts
2237
2129
  var QueuesCheck = class extends Check {
2238
2130
  constructor(queryFn = pgQuery) {
@@ -2525,4 +2417,4 @@ export {
2525
2417
  createDefaultRegistry,
2526
2418
  proveBeforeApply
2527
2419
  };
2528
- //# sourceMappingURL=chunk-UH4G2KRR.js.map
2420
+ //# sourceMappingURL=chunk-ZJPJTC6R.js.map
@@ -4,7 +4,7 @@ import {
4
4
  getServerMajorVersion,
5
5
  normalizeRoles,
6
6
  resolvePgDumpPath
7
- } from "./chunk-X3QQ64TU.js";
7
+ } from "./chunk-USIOUMYL.js";
8
8
  import {
9
9
  Check,
10
10
  inRolledBackTransaction,
@@ -491,6 +491,23 @@ function diffPublications(source, target) {
491
491
  }
492
492
  for (const pubname of targetPubs) {
493
493
  if (!sourcePubs.has(pubname)) {
494
+ if (pubname === "supabase_realtime") {
495
+ for (const t of target.filter((p) => p.pubname === pubname && p.tablename)) {
496
+ const fqn = `${t.schemaname}.${t.tablename}`;
497
+ issues.push({
498
+ id: `realtime-extra-table-${pubname}-${fqn}`,
499
+ check: "realtime",
500
+ severity: "warning",
501
+ title: `Extra published table: ${fqn} in ${pubname}`,
502
+ description: `Table "${fqn}" streams its changes to Realtime clients in target, but source publishes nothing for Realtime.`,
503
+ sql: {
504
+ up: `ALTER PUBLICATION ${quoteName(pubname)} DROP TABLE ${quoteName(t.schemaname)}.${quoteName(t.tablename)};`,
505
+ down: `ALTER PUBLICATION ${quoteName(pubname)} ADD TABLE ${quoteName(t.schemaname)}.${quoteName(t.tablename)};`
506
+ }
507
+ });
508
+ }
509
+ continue;
510
+ }
494
511
  issues.push({
495
512
  id: `realtime-extra-pub-${pubname}`,
496
513
  check: "realtime",
@@ -1232,4 +1249,4 @@ export {
1232
1249
  DEFAULT_KEEP_COUNT,
1233
1250
  pruneSnapshots
1234
1251
  };
1235
- //# sourceMappingURL=chunk-QWGXUFUQ.js.map
1252
+ //# sourceMappingURL=chunk-ZLNP3DUB.js.map
@@ -13,14 +13,14 @@ import {
13
13
  maintenanceUrl,
14
14
  reconcileClones,
15
15
  replaceDbName
16
- } from "../chunk-Q4YNLGV4.js";
16
+ } from "../chunk-KTATU64Y.js";
17
17
  import {
18
18
  captureSnapshot,
19
19
  formatSnapshotLayers
20
- } from "../chunk-QWGXUFUQ.js";
20
+ } from "../chunk-ZLNP3DUB.js";
21
21
  import {
22
22
  checkPgDumpCompat
23
- } from "../chunk-X3QQ64TU.js";
23
+ } from "../chunk-USIOUMYL.js";
24
24
  import {
25
25
  DEFAULT_LOCAL_PORT,
26
26
  LOCAL_PG_PASSWORD,
@@ -2,17 +2,17 @@ import {
2
2
  Diff,
3
3
  inertApplyFlags,
4
4
  rollbackHint
5
- } from "../chunk-QIJLIKB3.js";
5
+ } from "../chunk-DLTCJNJI.js";
6
6
  import "../chunk-Q43MN6NE.js";
7
- import "../chunk-UEF2NY7H.js";
8
- import "../chunk-UH4G2KRR.js";
9
- import "../chunk-TES62VLH.js";
7
+ import "../chunk-WZALUV4T.js";
8
+ import "../chunk-ZJPJTC6R.js";
9
+ import "../chunk-FXBTUJON.js";
10
10
  import "../chunk-WK5YTINL.js";
11
11
  import "../chunk-RQCXGO37.js";
12
12
  import "../chunk-CKH6J7DI.js";
13
- import "../chunk-Q4YNLGV4.js";
14
- import "../chunk-QWGXUFUQ.js";
15
- import "../chunk-X3QQ64TU.js";
13
+ import "../chunk-KTATU64Y.js";
14
+ import "../chunk-ZLNP3DUB.js";
15
+ import "../chunk-USIOUMYL.js";
16
16
  import "../chunk-RC7ZU7OV.js";
17
17
  import "../chunk-KHXEES2M.js";
18
18
  import "../chunk-SQ52YBKK.js";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-QIJLIKB3.js";
3
+ } from "../chunk-DLTCJNJI.js";
4
4
  import "../chunk-Q43MN6NE.js";
5
- import "../chunk-UEF2NY7H.js";
6
- import "../chunk-UH4G2KRR.js";
7
- import "../chunk-TES62VLH.js";
5
+ import "../chunk-WZALUV4T.js";
6
+ import "../chunk-ZJPJTC6R.js";
7
+ import "../chunk-FXBTUJON.js";
8
8
  import "../chunk-WK5YTINL.js";
9
9
  import "../chunk-RQCXGO37.js";
10
10
  import "../chunk-CKH6J7DI.js";
11
- import "../chunk-Q4YNLGV4.js";
12
- import "../chunk-QWGXUFUQ.js";
13
- import "../chunk-X3QQ64TU.js";
11
+ import "../chunk-KTATU64Y.js";
12
+ import "../chunk-ZLNP3DUB.js";
13
+ import "../chunk-USIOUMYL.js";
14
14
  import "../chunk-RC7ZU7OV.js";
15
15
  import "../chunk-KHXEES2M.js";
16
16
  import "../chunk-SQ52YBKK.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  createServer
3
- } from "../chunk-BYPLCJW3.js";
4
- import "../chunk-A5QPF4KH.js";
5
- import "../chunk-46QUNEET.js";
6
- import "../chunk-UH4G2KRR.js";
7
- import "../chunk-TES62VLH.js";
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";
8
8
  import "../chunk-WK5YTINL.js";
9
- import "../chunk-QWGXUFUQ.js";
10
- import "../chunk-X3QQ64TU.js";
9
+ import "../chunk-ZLNP3DUB.js";
10
+ import "../chunk-USIOUMYL.js";
11
11
  import "../chunk-RC7ZU7OV.js";
12
12
  import {
13
13
  installProcessGuard,
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  truncateSql
3
- } from "../../chunk-UWFICLWO.js";
3
+ } from "../../chunk-DTTQWSSU.js";
4
4
  import {
5
5
  generateTimestamp,
6
6
  writeMigrationFile
7
- } from "../../chunk-A5QPF4KH.js";
8
- import "../../chunk-46QUNEET.js";
7
+ } from "../../chunk-HMTFOYDT.js";
8
+ import "../../chunk-UC2Z5ISB.js";
9
9
  import "../../chunk-HWRRFF55.js";
10
- import "../../chunk-TES62VLH.js";
10
+ import "../../chunk-FXBTUJON.js";
11
11
  import "../../chunk-WK5YTINL.js";
12
12
  import {
13
13
  BaseCommand
14
14
  } from "../../chunk-CKH6J7DI.js";
15
15
  import {
16
16
  slugify
17
- } from "../../chunk-X3QQ64TU.js";
17
+ } from "../../chunk-USIOUMYL.js";
18
18
  import "../../chunk-RC7ZU7OV.js";
19
19
  import "../../chunk-KHXEES2M.js";
20
20
  import {
@@ -2,13 +2,13 @@ import {
2
2
  MigrateRun,
3
3
  findDestructiveStatements,
4
4
  truncateSql
5
- } from "../../chunk-UWFICLWO.js";
6
- import "../../chunk-46QUNEET.js";
5
+ } from "../../chunk-DTTQWSSU.js";
6
+ import "../../chunk-UC2Z5ISB.js";
7
7
  import "../../chunk-HWRRFF55.js";
8
- import "../../chunk-TES62VLH.js";
8
+ import "../../chunk-FXBTUJON.js";
9
9
  import "../../chunk-WK5YTINL.js";
10
10
  import "../../chunk-CKH6J7DI.js";
11
- import "../../chunk-X3QQ64TU.js";
11
+ import "../../chunk-USIOUMYL.js";
12
12
  import "../../chunk-RC7ZU7OV.js";
13
13
  import "../../chunk-KHXEES2M.js";
14
14
  import "../../chunk-SQ52YBKK.js";
@@ -5,10 +5,10 @@ import {
5
5
  restoreFromMigrations,
6
6
  restoreFromSnapshot,
7
7
  summarizeStatement
8
- } from "../chunk-HUR5UWQA.js";
9
- import "../chunk-33DONN5N.js";
8
+ } from "../chunk-IHGINEPX.js";
9
+ import "../chunk-KPU6G6BO.js";
10
10
  import "../chunk-HWRRFF55.js";
11
- import "../chunk-TES62VLH.js";
11
+ import "../chunk-FXBTUJON.js";
12
12
  import "../chunk-WK5YTINL.js";
13
13
  import {
14
14
  renderTip
@@ -19,8 +19,8 @@ import {
19
19
  import {
20
20
  findLatestSnapshot,
21
21
  listSnapshots
22
- } from "../chunk-QWGXUFUQ.js";
23
- import "../chunk-X3QQ64TU.js";
22
+ } from "../chunk-ZLNP3DUB.js";
23
+ import "../chunk-USIOUMYL.js";
24
24
  import "../chunk-RC7ZU7OV.js";
25
25
  import "../chunk-KHXEES2M.js";
26
26
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  backup,
3
3
  listMigrationFiles
4
- } from "../chunk-33DONN5N.js";
4
+ } from "../chunk-KPU6G6BO.js";
5
5
  import "../chunk-WK5YTINL.js";
6
6
  import {
7
7
  renderTip
@@ -16,8 +16,8 @@ import {
16
16
  listSnapshots,
17
17
  pruneSnapshots,
18
18
  unrestorableSchema
19
- } from "../chunk-QWGXUFUQ.js";
20
- import "../chunk-X3QQ64TU.js";
19
+ } from "../chunk-ZLNP3DUB.js";
20
+ import "../chunk-USIOUMYL.js";
21
21
  import "../chunk-RC7ZU7OV.js";
22
22
  import "../chunk-KHXEES2M.js";
23
23
  import {
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-QIJLIKB3.js";
3
+ } from "../chunk-DLTCJNJI.js";
4
4
  import "../chunk-Q43MN6NE.js";
5
- import "../chunk-UEF2NY7H.js";
6
- import "../chunk-UH4G2KRR.js";
7
- import "../chunk-TES62VLH.js";
5
+ import "../chunk-WZALUV4T.js";
6
+ import "../chunk-ZJPJTC6R.js";
7
+ import "../chunk-FXBTUJON.js";
8
8
  import "../chunk-WK5YTINL.js";
9
9
  import "../chunk-RQCXGO37.js";
10
10
  import "../chunk-CKH6J7DI.js";
11
- import "../chunk-Q4YNLGV4.js";
12
- import "../chunk-QWGXUFUQ.js";
13
- import "../chunk-X3QQ64TU.js";
11
+ import "../chunk-KTATU64Y.js";
12
+ import "../chunk-ZLNP3DUB.js";
13
+ import "../chunk-USIOUMYL.js";
14
14
  import "../chunk-RC7ZU7OV.js";
15
15
  import "../chunk-KHXEES2M.js";
16
16
  import "../chunk-SQ52YBKK.js";
package/dist/index.js CHANGED
@@ -3,37 +3,37 @@ import {
3
3
  createServer,
4
4
  getLastScanResult,
5
5
  setLastScanResult
6
- } from "./chunk-BYPLCJW3.js";
6
+ } from "./chunk-HHM37KPD.js";
7
7
  import {
8
8
  previewMigrationRestore,
9
9
  previewSnapshotRestore,
10
10
  restoreFromMigrations,
11
11
  restoreFromSnapshot
12
- } from "./chunk-HUR5UWQA.js";
12
+ } from "./chunk-IHGINEPX.js";
13
13
  import {
14
14
  backup,
15
15
  listMigrationFiles,
16
16
  loadMigrations
17
- } from "./chunk-33DONN5N.js";
18
- import "./chunk-A5QPF4KH.js";
19
- import "./chunk-46QUNEET.js";
17
+ } from "./chunk-KPU6G6BO.js";
18
+ import "./chunk-HMTFOYDT.js";
19
+ import "./chunk-UC2Z5ISB.js";
20
20
  import "./chunk-HWRRFF55.js";
21
21
  import {
22
22
  renderDetailed,
23
23
  renderSummary
24
- } from "./chunk-UEF2NY7H.js";
24
+ } from "./chunk-WZALUV4T.js";
25
25
  import {
26
26
  CheckRegistry,
27
27
  computeScore,
28
28
  createDefaultRegistry,
29
29
  scan,
30
30
  summarize
31
- } from "./chunk-UH4G2KRR.js";
31
+ } from "./chunk-ZJPJTC6R.js";
32
32
  import {
33
33
  CHECK_META,
34
34
  CHECK_NAMES,
35
35
  promote
36
- } from "./chunk-TES62VLH.js";
36
+ } from "./chunk-FXBTUJON.js";
37
37
  import "./chunk-WK5YTINL.js";
38
38
  import {
39
39
  BRANCH_DB_PREFIX,
@@ -43,14 +43,14 @@ import {
43
43
  listBranches,
44
44
  loadManifest,
45
45
  replaceDbName
46
- } from "./chunk-Q4YNLGV4.js";
46
+ } from "./chunk-KTATU64Y.js";
47
47
  import {
48
48
  captureSnapshot,
49
49
  findLatestSnapshot,
50
50
  listSnapshots,
51
51
  loadSnapshot
52
- } from "./chunk-QWGXUFUQ.js";
53
- import "./chunk-X3QQ64TU.js";
52
+ } from "./chunk-ZLNP3DUB.js";
53
+ import "./chunk-USIOUMYL.js";
54
54
  import {
55
55
  Check
56
56
  } from "./chunk-RC7ZU7OV.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akal/supaforge",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
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.34",
59
+ "@dbdiff/cli": "3.0.0-rc.36",
60
60
  "@modelcontextprotocol/sdk": "^1.32.1",
61
61
  "@oclif/core": "^5.1.12",
62
62
  "@supabase/supabase-js": "^2.103.0",