@akal/supaforge 0.0.43 → 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.
- package/dist/{chunk-F2NXGOF3.js → chunk-4RD66RHF.js} +4 -4
- package/dist/{chunk-L72FDQ3K.js → chunk-DUTPOR7P.js} +31 -124
- package/dist/{chunk-45UBDKAH.js → chunk-EMRM4RIV.js} +2 -2
- package/dist/{chunk-GUNQ5FFO.js → chunk-HGCTVCLV.js} +3 -3
- package/dist/{chunk-4PO4VB4C.js → chunk-J64XMOXU.js} +4 -4
- package/dist/{chunk-FGHBEOUV.js → chunk-JVZYVZUH.js} +3 -3
- package/dist/{chunk-HP4IDUCN.js → chunk-R4FSOTB6.js} +2 -2
- package/dist/{chunk-DTLEH6LL.js → chunk-UPWUXQ24.js} +2 -2
- package/dist/{chunk-M2OYKG65.js → chunk-YABERWV7.js} +195 -1
- package/dist/commands/diff.js +4 -4
- package/dist/commands/hukam.js +4 -4
- package/dist/commands/mcp.js +5 -5
- package/dist/commands/migrate/create.js +4 -4
- package/dist/commands/migrate/run.js +3 -3
- package/dist/commands/restore.js +2 -2
- package/dist/commands/sync.js +4 -4
- package/dist/index.js +7 -7
- package/package.json +2 -2
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
formatSkips,
|
|
7
7
|
renderDetailed,
|
|
8
8
|
renderSummary
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EMRM4RIV.js";
|
|
10
10
|
import {
|
|
11
11
|
createDefaultRegistry,
|
|
12
12
|
proveBeforeApply,
|
|
13
13
|
scan,
|
|
14
14
|
summarizeByKind
|
|
15
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
759
|
+
//# sourceMappingURL=chunk-4RD66RHF.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHECK_NAMES,
|
|
3
|
+
ExtensionsCheck,
|
|
3
4
|
RolesCheck,
|
|
4
5
|
applyTableFilter,
|
|
5
6
|
comparedSchemas,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
isComparisonCheck,
|
|
8
9
|
parseStatements,
|
|
9
10
|
planWork,
|
|
11
|
+
platformExtensionMoves,
|
|
10
12
|
policyOnlyKeys,
|
|
11
13
|
proofScope,
|
|
12
14
|
proveConvergence,
|
|
@@ -17,8 +19,9 @@ import {
|
|
|
17
19
|
schemaNotices,
|
|
18
20
|
sqlSkeleton,
|
|
19
21
|
sqlToIssues,
|
|
22
|
+
withPlatformExtensionCalls,
|
|
20
23
|
withoutAbsentRoles
|
|
21
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-YABERWV7.js";
|
|
22
25
|
import {
|
|
23
26
|
splitSqlStatements
|
|
24
27
|
} from "./chunk-WK5YTINL.js";
|
|
@@ -412,7 +415,11 @@ var SchemaCheck = class extends Check {
|
|
|
412
415
|
this.fetchIgnoredSchemaTables(ctx.target.dbUrl, ignoreSchemas)
|
|
413
416
|
]);
|
|
414
417
|
for (const notice of schemaNotices(result.notices ?? [])) ctx.onNotice?.(notice);
|
|
415
|
-
|
|
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
|
+
}
|
|
416
423
|
const roles = await this.targetRoles(ctx.target.dbUrl);
|
|
417
424
|
return roles?.size ? withoutAbsentRoles(issues, roles) : issues;
|
|
418
425
|
} catch (err) {
|
|
@@ -432,6 +439,27 @@ var SchemaCheck = class extends Check {
|
|
|
432
439
|
* Returns a Set of lowercase table names, bare and schema-qualified. Fails silently so that a transient
|
|
433
440
|
* DB error here never blocks the main schema diff.
|
|
434
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
|
+
}
|
|
435
463
|
/** The target's roles, or undefined when they cannot be read. */
|
|
436
464
|
async targetRoles(dbUrl) {
|
|
437
465
|
try {
|
|
@@ -2124,127 +2152,6 @@ ${diffs.join("\n")}`,
|
|
|
2124
2152
|
return issues;
|
|
2125
2153
|
}
|
|
2126
2154
|
|
|
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
|
-
var SUPABASE_PLATFORM_EXTENSIONS = [
|
|
2174
|
-
{ name: "pg_graphql", schemas: ["graphql"] },
|
|
2175
|
-
{ name: "supabase_vault", schemas: ["vault"] },
|
|
2176
|
-
{ name: "pgsodium", schemas: ["pgsodium"] },
|
|
2177
|
-
{ name: "pg_stat_statements", schemas: ["extensions"] },
|
|
2178
|
-
{ name: "pgcrypto", schemas: ["extensions"] },
|
|
2179
|
-
{ name: "pgjwt", schemas: ["extensions"] },
|
|
2180
|
-
{ name: "uuid-ossp", schemas: ["extensions"] }
|
|
2181
|
-
];
|
|
2182
|
-
function isPlatformExtension(ext) {
|
|
2183
|
-
return SUPABASE_PLATFORM_EXTENSIONS.some((p) => p.name === ext.name && p.schemas.includes(ext.schema));
|
|
2184
|
-
}
|
|
2185
|
-
function diffExtensions(source, target, reachable) {
|
|
2186
|
-
const issues = [];
|
|
2187
|
-
const sourceMap = new Map(source.map((e) => [e.name, e]));
|
|
2188
|
-
const targetMap = new Map(target.map((e) => [e.name, e]));
|
|
2189
|
-
for (const [name, ext] of sourceMap) {
|
|
2190
|
-
if (!targetMap.has(name)) {
|
|
2191
|
-
issues.push({
|
|
2192
|
-
id: `ext-missing-${name}`,
|
|
2193
|
-
check: "extensions",
|
|
2194
|
-
severity: "warning",
|
|
2195
|
-
title: `Missing extension: ${name}`,
|
|
2196
|
-
description: `Extension "${name}" (v${ext.version}) is enabled in source (schema: ${ext.schema}) but not in target.`,
|
|
2197
|
-
sourceValue: ext,
|
|
2198
|
-
sql: {
|
|
2199
|
-
// Into the schema it is in on the source, which plain PostgreSQL
|
|
2200
|
-
// may not have — Supabase's `extensions`. Made first; if the server
|
|
2201
|
-
// does not ship the extension, the fix is left out with it. A
|
|
2202
|
-
// system schema (pg_cron's pg_catalog) is always there, and cannot
|
|
2203
|
-
// be made.
|
|
2204
|
-
up: ext.schema === "public" ? `CREATE EXTENSION IF NOT EXISTS ${quoteName(name)};` : `${ext.schema.startsWith("pg_") ? "" : `CREATE SCHEMA IF NOT EXISTS ${quoteName(ext.schema)};
|
|
2205
|
-
`}CREATE EXTENSION IF NOT EXISTS ${quoteName(name)} SCHEMA ${quoteName(ext.schema)};`,
|
|
2206
|
-
down: `DROP EXTENSION IF EXISTS ${quoteName(name)};`
|
|
2207
|
-
}
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
for (const [name, ext] of targetMap) {
|
|
2212
|
-
if (!sourceMap.has(name) && !isPlatformExtension(ext)) {
|
|
2213
|
-
issues.push({
|
|
2214
|
-
id: `ext-extra-${name}`,
|
|
2215
|
-
check: "extensions",
|
|
2216
|
-
severity: "info",
|
|
2217
|
-
title: `Extra extension: ${name}`,
|
|
2218
|
-
description: `Extension "${name}" (v${ext.version}) is enabled in target (schema: ${ext.schema}) but not in source.`,
|
|
2219
|
-
targetValue: ext
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
for (const [name, srcExt] of sourceMap) {
|
|
2224
|
-
const tgtExt = targetMap.get(name);
|
|
2225
|
-
if (!tgtExt) continue;
|
|
2226
|
-
if (srcExt.version !== tgtExt.version) {
|
|
2227
|
-
const updatable = !reachable || reachable.get(name)?.has(srcExt.version);
|
|
2228
|
-
issues.push({
|
|
2229
|
-
id: `ext-version-${name}`,
|
|
2230
|
-
check: "extensions",
|
|
2231
|
-
severity: "info",
|
|
2232
|
-
title: `Extension version mismatch: ${name}`,
|
|
2233
|
-
description: `Extension "${name}" is v${srcExt.version} in source but v${tgtExt.version} in target.`,
|
|
2234
|
-
sourceValue: srcExt,
|
|
2235
|
-
targetValue: tgtExt,
|
|
2236
|
-
...updatable ? {
|
|
2237
|
-
sql: {
|
|
2238
|
-
up: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(srcExt.version)};`,
|
|
2239
|
-
down: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(tgtExt.version)};`
|
|
2240
|
-
}
|
|
2241
|
-
} : { 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)` }
|
|
2242
|
-
});
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
return issues;
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2248
2155
|
// src/checks/queues.ts
|
|
2249
2156
|
var QueuesCheck = class extends Check {
|
|
2250
2157
|
constructor(queryFn = pgQuery) {
|
|
@@ -2537,4 +2444,4 @@ export {
|
|
|
2537
2444
|
createDefaultRegistry,
|
|
2538
2445
|
proveBeforeApply
|
|
2539
2446
|
};
|
|
2540
|
-
//# sourceMappingURL=chunk-
|
|
2447
|
+
//# sourceMappingURL=chunk-DUTPOR7P.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHECK_META,
|
|
3
3
|
isComparisonCheck
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
244
|
+
//# sourceMappingURL=chunk-EMRM4RIV.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
targetFingerprint,
|
|
3
3
|
writtenAgainst
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
183
|
+
//# sourceMappingURL=chunk-HGCTVCLV.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
migrationsDir,
|
|
3
3
|
writeMigrationFile
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JVZYVZUH.js";
|
|
5
5
|
import {
|
|
6
6
|
createDefaultRegistry,
|
|
7
7
|
proveBeforeApply,
|
|
8
8
|
scan
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-DUTPOR7P.js";
|
|
10
10
|
import {
|
|
11
11
|
CHECK_NAMES,
|
|
12
12
|
promote
|
|
13
|
-
} from "./chunk-
|
|
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-
|
|
533
|
+
//# sourceMappingURL=chunk-J64XMOXU.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
targetFingerprint,
|
|
3
3
|
writtenAgainstLine
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UPWUXQ24.js";
|
|
5
5
|
import {
|
|
6
6
|
RolesCheck,
|
|
7
7
|
isDestructiveSql,
|
|
8
8
|
runDbDiff
|
|
9
|
-
} from "./chunk-
|
|
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-
|
|
94
|
+
//# sourceMappingURL=chunk-JVZYVZUH.js.map
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
rolesNamedBy,
|
|
19
19
|
sqlSkeleton,
|
|
20
20
|
statementSubject
|
|
21
|
-
} from "./chunk-
|
|
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-
|
|
903
|
+
//# sourceMappingURL=chunk-R4FSOTB6.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
comparedSchemas,
|
|
3
3
|
fingerprint
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
27
|
+
//# sourceMappingURL=chunk-UPWUXQ24.js.map
|
|
@@ -637,6 +637,127 @@ function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set()) {
|
|
|
637
637
|
return issues;
|
|
638
638
|
}
|
|
639
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
|
+
|
|
640
761
|
// src/sql-ast.ts
|
|
641
762
|
import { loadModule, parseSync } from "libpg-query";
|
|
642
763
|
await loadModule();
|
|
@@ -750,6 +871,10 @@ var BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
|
750
871
|
function sqlSkeleton(sql) {
|
|
751
872
|
return sql.replace(DOLLAR_BODY, " ").replace(STRING_LITERAL, " '' ").replace(LINE_COMMENT, " ").replace(BLOCK_COMMENT, " ");
|
|
752
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
|
+
}
|
|
753
878
|
var NAME_PART = String.raw`"(?:[^"]|"")+"|[\w$]+`;
|
|
754
879
|
var IDENT = String.raw`(?:${NAME_PART})(?:\s*\.\s*(?:${NAME_PART}))?`;
|
|
755
880
|
function bareName(identifier) {
|
|
@@ -1397,11 +1522,76 @@ function platformDefaultPrivileges(sql) {
|
|
|
1397
1522
|
const name = role.startsWith('"') ? role.slice(1, -1).replace(/""/g, '"') : role.toLowerCase();
|
|
1398
1523
|
return name !== "postgres" && PLATFORM_ROLES.includes(name);
|
|
1399
1524
|
}
|
|
1525
|
+
function platformExtensionMove(upSql, downSql) {
|
|
1526
|
+
const re = /^\s*ALTER\s+EXTENSION\s+("(?:[^"]|"")+"|[\w$-]+)\s+SET\s+SCHEMA\s+("(?:[^"]|"")+"|[\w$]+)\s*;?\s*$/i;
|
|
1527
|
+
const up = re.exec(upSql);
|
|
1528
|
+
const down = re.exec(downSql);
|
|
1529
|
+
if (!up || !down) return void 0;
|
|
1530
|
+
const name = unquoted(up[1]);
|
|
1531
|
+
const targetSchema = unquoted(down[2]);
|
|
1532
|
+
if (unquoted(down[1]) !== name || !isPlatformExtension({ name, schema: targetSchema })) return void 0;
|
|
1533
|
+
return { name, sourceSchema: unquoted(up[2]), targetSchema };
|
|
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
|
+
}
|
|
1400
1578
|
function issuesFromUnits(upUnits, downUnits, check, ignoreSchemas, ignoredSchemaTables) {
|
|
1401
1579
|
const pairs = pairUnits(upUnits, downUnits).filter(({ up, down }) => !(ignoreSchemas?.length && isCrossSchemaFkUnit(up, down, ignoreSchemas, ignoredSchemaTables)) && !platformDefaultPrivileges(up.sql));
|
|
1402
1580
|
return pairs.map(({ up, down }, i) => {
|
|
1403
1581
|
const upSql = up.sql;
|
|
1404
1582
|
const downSql = down?.sql ?? "";
|
|
1583
|
+
const platform = platformExtensionMove(upSql, downSql);
|
|
1584
|
+
if (platform) {
|
|
1585
|
+
return {
|
|
1586
|
+
id: `${check}-extension-schema-${i + 1}`,
|
|
1587
|
+
check,
|
|
1588
|
+
severity: "info",
|
|
1589
|
+
title: `Extension in another schema: ${platform.name}`,
|
|
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 }
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1405
1595
|
const statements = splitStatements(upSql);
|
|
1406
1596
|
const replaced = replacedObject(up, statements);
|
|
1407
1597
|
const manualOnly = manualEnumChange(up);
|
|
@@ -1908,6 +2098,7 @@ var SCHEMA_RULES = [
|
|
|
1908
2098
|
{ match: /^\s*COMMENT\s+ON\b/i, label: "Comment changed", name: commentLabel },
|
|
1909
2099
|
{ match: /^\s*CREATE\s+EXTENSION\b/i, label: "Extension missing", name: extensionLabel },
|
|
1910
2100
|
{ match: /^\s*DROP\s+EXTENSION\b/i, label: "Extra extension", name: extensionLabel },
|
|
2101
|
+
{ match: /^\s*ALTER\s+EXTENSION\b[^;]*\bSET\s+SCHEMA\b/is, label: "Extension in another schema", name: extensionLabel },
|
|
1911
2102
|
{ match: /^\s*CREATE\s+COLLATION\b/i, label: "Collation missing", name: named(AFTER.collation) },
|
|
1912
2103
|
{ match: /^\s*ALTER\s+COLLATION\b/i, label: "Collation altered", name: named(AFTER.collation) },
|
|
1913
2104
|
{ match: /^\s*DROP\s+COLLATION\b/i, label: "Extra collation", name: named(AFTER.collation) },
|
|
@@ -3243,11 +3434,14 @@ export {
|
|
|
3243
3434
|
isComparisonCheck,
|
|
3244
3435
|
PLATFORM_ROLES,
|
|
3245
3436
|
RolesCheck,
|
|
3437
|
+
ExtensionsCheck,
|
|
3246
3438
|
runDbDiff,
|
|
3247
3439
|
isDestructiveSql,
|
|
3248
3440
|
destructiveReason,
|
|
3249
3441
|
sqlToIssues,
|
|
3250
3442
|
schemaNotices,
|
|
3443
|
+
platformExtensionMoves,
|
|
3444
|
+
withPlatformExtensionCalls,
|
|
3251
3445
|
withoutAbsentRoles,
|
|
3252
3446
|
ABSENT_ON_TARGET,
|
|
3253
3447
|
EXTENSION_UNAVAILABLE,
|
|
@@ -3269,4 +3463,4 @@ export {
|
|
|
3269
3463
|
residualHeldBack,
|
|
3270
3464
|
proofScope
|
|
3271
3465
|
};
|
|
3272
|
-
//# sourceMappingURL=chunk-
|
|
3466
|
+
//# sourceMappingURL=chunk-YABERWV7.js.map
|
package/dist/commands/diff.js
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
Diff,
|
|
3
3
|
inertApplyFlags,
|
|
4
4
|
rollbackHint
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-4RD66RHF.js";
|
|
6
6
|
import "../chunk-Q43MN6NE.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
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";
|
package/dist/commands/hukam.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Diff
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-4RD66RHF.js";
|
|
4
4
|
import "../chunk-Q43MN6NE.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
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/commands/mcp.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createServer
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
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-
|
|
3
|
+
} from "../../chunk-HGCTVCLV.js";
|
|
4
4
|
import {
|
|
5
5
|
generateTimestamp,
|
|
6
6
|
writeMigrationFile
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-JVZYVZUH.js";
|
|
8
|
+
import "../../chunk-UPWUXQ24.js";
|
|
9
9
|
import "../../chunk-HWRRFF55.js";
|
|
10
|
-
import "../../chunk-
|
|
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-
|
|
6
|
-
import "../../chunk-
|
|
5
|
+
} from "../../chunk-HGCTVCLV.js";
|
|
6
|
+
import "../../chunk-UPWUXQ24.js";
|
|
7
7
|
import "../../chunk-HWRRFF55.js";
|
|
8
|
-
import "../../chunk-
|
|
8
|
+
import "../../chunk-YABERWV7.js";
|
|
9
9
|
import "../../chunk-WK5YTINL.js";
|
|
10
10
|
import "../../chunk-CKH6J7DI.js";
|
|
11
11
|
import "../../chunk-USIOUMYL.js";
|
package/dist/commands/restore.js
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
restoreFromMigrations,
|
|
6
6
|
restoreFromSnapshot,
|
|
7
7
|
summarizeStatement
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-R4FSOTB6.js";
|
|
9
9
|
import "../chunk-KPU6G6BO.js";
|
|
10
10
|
import "../chunk-HWRRFF55.js";
|
|
11
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-YABERWV7.js";
|
|
12
12
|
import "../chunk-WK5YTINL.js";
|
|
13
13
|
import {
|
|
14
14
|
renderTip
|
package/dist/commands/sync.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Diff
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-4RD66RHF.js";
|
|
4
4
|
import "../chunk-Q43MN6NE.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
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-
|
|
6
|
+
} from "./chunk-J64XMOXU.js";
|
|
7
7
|
import {
|
|
8
8
|
previewMigrationRestore,
|
|
9
9
|
previewSnapshotRestore,
|
|
10
10
|
restoreFromMigrations,
|
|
11
11
|
restoreFromSnapshot
|
|
12
|
-
} from "./chunk-
|
|
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-
|
|
19
|
-
import "./chunk-
|
|
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-
|
|
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-
|
|
31
|
+
} from "./chunk-DUTPOR7P.js";
|
|
32
32
|
import {
|
|
33
33
|
CHECK_META,
|
|
34
34
|
CHECK_NAMES,
|
|
35
35
|
promote
|
|
36
|
-
} from "./chunk-
|
|
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.
|
|
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.
|
|
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",
|