@akal/supaforge 0.0.35 → 0.0.36
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 +4 -1
- package/dist/base-command.js +4 -4
- package/dist/{chunk-SM7HP6EP.js → chunk-5UHIWFQG.js} +69 -9
- package/dist/{chunk-O5ERC2SE.js → chunk-AL6INEFX.js} +3 -3
- package/dist/{chunk-4AGJRRBT.js → chunk-CAQ3QQFP.js} +70 -22
- package/dist/{chunk-5Q6LSLA3.js → chunk-CCB7ARZU.js} +6 -6
- package/dist/{chunk-YZM76W22.js → chunk-EWNZIRCD.js} +4 -4
- package/dist/{chunk-YWERIWFD.js → chunk-FD2JKEJA.js} +5 -5
- package/dist/{chunk-NEM5AEPQ.js → chunk-GGZ7YWBZ.js} +24 -15
- package/dist/{chunk-7N63OPFN.js → chunk-JX5L253P.js} +46 -16
- package/dist/{chunk-GQPGH6YR.js → chunk-KHXEES2M.js} +2 -2
- package/dist/{chunk-4M6OQLPO.js → chunk-KT7NMELZ.js} +77 -7
- package/dist/{chunk-44UVQJV2.js → chunk-M2564IGT.js} +22 -15
- package/dist/{chunk-H2D3YSKM.js → chunk-MRXIE55Y.js} +3 -3
- package/dist/{chunk-NX2KKUS7.js → chunk-MZPWRWBL.js} +7 -7
- package/dist/{chunk-XLZCX6R2.js → chunk-OXS42LJH.js} +4 -4
- package/dist/{chunk-HNJ6BNNZ.js → chunk-Q43MN6NE.js} +2 -2
- package/dist/{chunk-ZI435CAU.js → chunk-RQCXGO37.js} +2 -2
- package/dist/{chunk-KNXHLVF7.js → chunk-SQ52YBKK.js} +3 -2
- package/dist/{chunk-T7GMPGUO.js → chunk-YUJ2MHLM.js} +674 -22
- package/dist/{chunk-AGONS5JJ.js → chunk-Z2YUOA4W.js} +2 -2
- package/dist/commands/clone.js +8 -8
- package/dist/commands/diff.d.ts +1 -0
- package/dist/commands/diff.js +14 -15
- package/dist/commands/hukam.js +14 -15
- package/dist/commands/init.js +2 -2
- package/dist/commands/mcp.js +9 -10
- package/dist/commands/migrate/baseline.js +5 -5
- package/dist/commands/migrate/create.js +22 -13
- package/dist/commands/migrate/list.js +5 -5
- package/dist/commands/migrate/run.js +9 -9
- package/dist/commands/report.js +5 -5
- package/dist/commands/restore.js +14 -13
- package/dist/commands/snapshot.js +8 -8
- package/dist/commands/sync.js +14 -15
- package/dist/index.d.ts +17 -0
- package/dist/index.js +13 -14
- package/package.json +2 -2
- package/dist/chunk-WNTCZM2J.js +0 -468
package/README.md
CHANGED
|
@@ -125,6 +125,7 @@ Useful `diff` flags:
|
|
|
125
125
|
| `--allow-destructive` | Also apply drops and deletes |
|
|
126
126
|
| `--apply-posture` | Also apply the target-only checks' fixes |
|
|
127
127
|
| `--no-transaction` | Apply fix by fix, keeping what works |
|
|
128
|
+
| `--no-snapshot` | Read each query on its own. By default each database is read as of one instant, so a change made while the scan runs is seen by all of it or none; as with `pg_dump`, what it reads stays locked until the scan ends |
|
|
128
129
|
| `--json` / `--ci` | Machine-readable output; CI annotations and exit codes |
|
|
129
130
|
|
|
130
131
|
## Applying fixes safely
|
|
@@ -197,7 +198,9 @@ the output.
|
|
|
197
198
|
- **Targets.** Restore runs as one transaction and expects an empty database.
|
|
198
199
|
`--force` clears the snapshot's own schemas first (never Supabase's) and
|
|
199
200
|
puts back the triggers and policies outside them that depended on what it
|
|
200
|
-
cleared.
|
|
201
|
+
cleared. A restore or apply that looks likely to need more locks than the
|
|
202
|
+
target allows in one transaction says so before it starts;
|
|
203
|
+
`--no-transaction` commits as it goes instead.
|
|
201
204
|
- **Plain PostgreSQL.** Restoring into plain PostgreSQL works. What can't
|
|
202
205
|
exist there is skipped and named: a foreign key to `auth.users`, a webhook,
|
|
203
206
|
an extension the server doesn't ship, and everything that needs it.
|
package/dist/base-command.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseCommand
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-OXS42LJH.js";
|
|
4
|
+
import "./chunk-KT7NMELZ.js";
|
|
5
|
+
import "./chunk-KHXEES2M.js";
|
|
6
|
+
import "./chunk-SQ52YBKK.js";
|
|
7
7
|
export {
|
|
8
8
|
BaseCommand
|
|
9
9
|
};
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
getServerMajorVersion,
|
|
5
5
|
normalizeRoles,
|
|
6
6
|
resolvePgDumpPath
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-Z2YUOA4W.js";
|
|
8
8
|
import {
|
|
9
9
|
Check,
|
|
10
10
|
inRolledBackTransaction,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
quoteLiteral,
|
|
16
16
|
quoteName,
|
|
17
17
|
readOrAbsent
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-KT7NMELZ.js";
|
|
19
19
|
import {
|
|
20
20
|
DEFAULT_IGNORE_SCHEMAS,
|
|
21
21
|
MIGRATIONS_SUBDIR,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
errMsg,
|
|
29
29
|
ok,
|
|
30
30
|
warn
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-SQ52YBKK.js";
|
|
32
32
|
|
|
33
33
|
// src/snapshot.ts
|
|
34
34
|
import { mkdir, writeFile, readFile, readdir, rm } from "fs/promises";
|
|
@@ -1015,6 +1015,20 @@ async function captureRoleGrants(dir, dbUrl, queryFn) {
|
|
|
1015
1015
|
AND (a.grantee = 0 OR pg_get_userbyid(a.grantee) NOT LIKE 'pg\\_%')
|
|
1016
1016
|
AND n.nspname NOT IN (${excluded})
|
|
1017
1017
|
UNION ALL
|
|
1018
|
+
-- Schemas: USAGE on a schema of its own is what lets a role reach its tables.
|
|
1019
|
+
SELECT CASE WHEN a.grantee = 0 THEN 'PUBLIC' ELSE pg_get_userbyid(a.grantee) END,
|
|
1020
|
+
n.nspname, '', NULL::text, a.privilege_type, a.is_grantable, 'SCHEMA', NULL::text
|
|
1021
|
+
FROM pg_namespace n
|
|
1022
|
+
CROSS JOIN LATERAL aclexplode(n.nspacl) a
|
|
1023
|
+
WHERE n.nspacl IS NOT NULL AND a.grantee <> n.nspowner
|
|
1024
|
+
AND n.nspname NOT IN (${excluded}) AND n.nspname NOT LIKE 'pg\\_%' AND n.nspname <> 'information_schema'
|
|
1025
|
+
AND NOT EXISTS (SELECT 1 FROM pg_depend d WHERE d.classid = 'pg_namespace'::regclass AND d.objid = n.oid AND d.deptype = 'e')
|
|
1026
|
+
AND (a.grantee = 0 OR pg_get_userbyid(a.grantee) NOT IN (
|
|
1027
|
+
'postgres','supabase_admin','authenticator','supabase_auth_admin',
|
|
1028
|
+
'supabase_storage_admin','dashboard_user','pgbouncer','supavisor'
|
|
1029
|
+
))
|
|
1030
|
+
AND (a.grantee = 0 OR pg_get_userbyid(a.grantee) NOT LIKE 'pg\\_%')
|
|
1031
|
+
UNION ALL
|
|
1018
1032
|
SELECT CASE WHEN a.grantee = 0 THEN 'PUBLIC' ELSE pg_get_userbyid(a.grantee) END,
|
|
1019
1033
|
n.nspname, c.relname, att.attname, a.privilege_type, a.is_grantable, '', NULL::text
|
|
1020
1034
|
FROM pg_attribute att
|
|
@@ -1040,18 +1054,64 @@ async function captureRoleGrants(dir, dbUrl, queryFn) {
|
|
|
1040
1054
|
]);
|
|
1041
1055
|
grouped.set(key, [...grouped.get(key) ?? [], row]);
|
|
1042
1056
|
}
|
|
1043
|
-
const statements = [...grouped.values()].map(([row, ...rest]) => `GRANT ${[row, ...rest].map((r) => r.privilege_type + (r.column_name ? ` (${quoteName(r.column_name)})` : "")).join(", ")} ON ${row.keyword ? `${row.keyword} ` : ""}${quoteName(row.table_schema)}.${quoteName(row.table_name)}` + (row.args !== null && row.keyword !== "SEQUENCE" && row.keyword ? `(${row.args})` : "") + ` TO ${row.grantee === "PUBLIC" ? "PUBLIC" : quoteName(row.grantee)}` + (row.is_grantable ? " WITH GRANT OPTION" : "") + ";");
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1057
|
+
const statements = [...grouped.values()].map(([row, ...rest]) => `GRANT ${[row, ...rest].map((r) => r.privilege_type + (r.column_name ? ` (${quoteName(r.column_name)})` : "")).join(", ")} ON ${row.keyword === "SCHEMA" ? `SCHEMA ${quoteName(row.table_schema)}` : `${row.keyword ? `${row.keyword} ` : ""}${quoteName(row.table_schema)}.${quoteName(row.table_name)}`}` + (row.args !== null && row.keyword !== "SEQUENCE" && row.keyword !== "SCHEMA" && row.keyword ? `(${row.args})` : "") + ` TO ${row.grantee === "PUBLIC" ? "PUBLIC" : quoteName(row.grantee)}` + (row.is_grantable ? " WITH GRANT OPTION" : "") + ";");
|
|
1058
|
+
const defaults = await defaultPrivilegeStatements(dbUrl, queryFn, excluded);
|
|
1059
|
+
const all = [...statements, ...defaults];
|
|
1060
|
+
const output = all.length > 0 ? `-- SupaForge Role Grants Snapshot
|
|
1061
|
+
-- ${rows.length} grant(s), ${defaults.length} default privilege statement(s)
|
|
1046
1062
|
|
|
1047
|
-
${
|
|
1063
|
+
${all.join("\n")}
|
|
1048
1064
|
` : "-- No role grants found\n";
|
|
1049
1065
|
await writeFile(join(dir, file), output);
|
|
1050
|
-
return { captured: true, file, itemCount: rows.length };
|
|
1066
|
+
return { captured: true, file, itemCount: rows.length + defaults.length };
|
|
1051
1067
|
} catch (err) {
|
|
1052
1068
|
return { captured: false, file, itemCount: 0, error: errMsg(err) };
|
|
1053
1069
|
}
|
|
1054
1070
|
}
|
|
1071
|
+
var DEFAULT_ACL_KINDS = { r: "TABLES", S: "SEQUENCES", f: "FUNCTIONS", T: "TYPES", n: "SCHEMAS" };
|
|
1072
|
+
async function defaultPrivilegeStatements(dbUrl, queryFn, excludedSchemas) {
|
|
1073
|
+
const platform = `'postgres','supabase_admin','authenticator','supabase_auth_admin','supabase_storage_admin','dashboard_user','pgbouncer','supavisor'`;
|
|
1074
|
+
const rows = await queryFn(dbUrl, `
|
|
1075
|
+
WITH d AS (
|
|
1076
|
+
SELECT d.*, n.nspname FROM pg_default_acl d LEFT JOIN pg_namespace n ON n.oid = d.defaclnamespace
|
|
1077
|
+
WHERE pg_get_userbyid(d.defaclrole) NOT IN ('supabase_admin','supabase_auth_admin','supabase_storage_admin','dashboard_user')
|
|
1078
|
+
AND (n.nspname IS NULL OR n.nspname NOT IN (${excludedSchemas}))
|
|
1079
|
+
), have AS (
|
|
1080
|
+
SELECT d.oid, a.* FROM d CROSS JOIN LATERAL aclexplode(d.defaclacl) a
|
|
1081
|
+
), builtin AS (
|
|
1082
|
+
SELECT d.oid, b.* FROM d CROSS JOIN LATERAL aclexplode(acldefault(d.defaclobjtype, d.defaclrole)) b
|
|
1083
|
+
WHERE d.defaclnamespace = 0
|
|
1084
|
+
)
|
|
1085
|
+
SELECT pg_get_userbyid(d.defaclrole) AS role, d.nspname AS schema, d.defaclobjtype::text AS kind, x.action,
|
|
1086
|
+
CASE WHEN x.grantee = 0 THEN 'PUBLIC' ELSE pg_get_userbyid(x.grantee) END AS grantee,
|
|
1087
|
+
x.privilege_type, x.is_grantable
|
|
1088
|
+
FROM d JOIN (
|
|
1089
|
+
SELECT h.oid, 'GRANT' AS action, h.grantee, h.privilege_type, h.is_grantable FROM have h
|
|
1090
|
+
WHERE NOT EXISTS (SELECT 1 FROM builtin b WHERE b.oid = h.oid AND b.grantee = h.grantee
|
|
1091
|
+
AND b.privilege_type = h.privilege_type AND b.is_grantable = h.is_grantable)
|
|
1092
|
+
UNION ALL
|
|
1093
|
+
SELECT b.oid, 'REVOKE', b.grantee, b.privilege_type, b.is_grantable FROM builtin b
|
|
1094
|
+
WHERE NOT EXISTS (SELECT 1 FROM have h WHERE h.oid = b.oid AND h.grantee = b.grantee
|
|
1095
|
+
AND h.privilege_type = b.privilege_type AND h.is_grantable = b.is_grantable)
|
|
1096
|
+
) x ON x.oid = d.oid
|
|
1097
|
+
WHERE (x.grantee = 0 OR pg_get_userbyid(x.grantee) NOT IN (${platform}) OR x.grantee = d.defaclrole)
|
|
1098
|
+
AND (x.grantee = 0 OR pg_get_userbyid(x.grantee) NOT LIKE 'pg\\_%')
|
|
1099
|
+
ORDER BY 1, 2 NULLS FIRST, 3, 4, 5, 6
|
|
1100
|
+
`);
|
|
1101
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
1102
|
+
for (const row of rows) {
|
|
1103
|
+
if (!DEFAULT_ACL_KINDS[row.kind]) continue;
|
|
1104
|
+
const key = JSON.stringify([row.role, row.schema, row.kind, row.action, row.grantee, row.action === "GRANT" && row.is_grantable]);
|
|
1105
|
+
grouped.set(key, [...grouped.get(key) ?? [], row]);
|
|
1106
|
+
}
|
|
1107
|
+
const grantee = (g) => g === "PUBLIC" ? "PUBLIC" : quoteName(g);
|
|
1108
|
+
return [...grouped.values()].map(([row, ...rest]) => {
|
|
1109
|
+
const head = `ALTER DEFAULT PRIVILEGES FOR ROLE ${quoteName(row.role)}${row.schema ? ` IN SCHEMA ${quoteName(row.schema)}` : ""}`;
|
|
1110
|
+
const privileges = [row, ...rest].map((r) => r.privilege_type).join(", ");
|
|
1111
|
+
const on = DEFAULT_ACL_KINDS[row.kind];
|
|
1112
|
+
return row.action === "GRANT" ? `${head} GRANT ${privileges} ON ${on} TO ${grantee(row.grantee)}${row.is_grantable ? " WITH GRANT OPTION" : ""};` : `${head} REVOKE ${privileges} ON ${on} FROM ${grantee(row.grantee)};`;
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1055
1115
|
async function captureExtensions(dir, dbUrl, queryFn) {
|
|
1056
1116
|
const file = "extensions.sql";
|
|
1057
1117
|
try {
|
|
@@ -1171,4 +1231,4 @@ export {
|
|
|
1171
1231
|
DEFAULT_KEEP_COUNT,
|
|
1172
1232
|
pruneSnapshots
|
|
1173
1233
|
};
|
|
1174
|
-
//# sourceMappingURL=chunk-
|
|
1234
|
+
//# sourceMappingURL=chunk-5UHIWFQG.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pgQuery,
|
|
3
3
|
readLocalMigrations
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KT7NMELZ.js";
|
|
5
5
|
import {
|
|
6
6
|
MIGRATIONS_SCHEMA,
|
|
7
7
|
MIGRATIONS_TABLE
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SQ52YBKK.js";
|
|
9
9
|
|
|
10
10
|
// src/migrate.ts
|
|
11
11
|
import { readFile } from "fs/promises";
|
|
@@ -119,4 +119,4 @@ export {
|
|
|
119
119
|
runMigration,
|
|
120
120
|
baselineMigrations
|
|
121
121
|
};
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
122
|
+
//# sourceMappingURL=chunk-AL6INEFX.js.map
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RolesCheck
|
|
3
|
-
} from "./chunk-WNTCZM2J.js";
|
|
4
1
|
import {
|
|
5
2
|
CHECK_NAMES,
|
|
3
|
+
RolesCheck,
|
|
6
4
|
applyTableFilter,
|
|
7
5
|
destructiveReason,
|
|
8
6
|
isComparisonCheck,
|
|
@@ -13,8 +11,9 @@ import {
|
|
|
13
11
|
runDbDiff,
|
|
14
12
|
schemaNotices,
|
|
15
13
|
sqlSkeleton,
|
|
16
|
-
sqlToIssues
|
|
17
|
-
|
|
14
|
+
sqlToIssues,
|
|
15
|
+
withoutAbsentRoles
|
|
16
|
+
} from "./chunk-YUJ2MHLM.js";
|
|
18
17
|
import {
|
|
19
18
|
splitSqlStatements
|
|
20
19
|
} from "./chunk-WK5YTINL.js";
|
|
@@ -29,19 +28,22 @@ import {
|
|
|
29
28
|
readJsonArray,
|
|
30
29
|
readJsonObject,
|
|
31
30
|
schemaPolicySql
|
|
32
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-5UHIWFQG.js";
|
|
33
32
|
import {
|
|
34
33
|
Check,
|
|
35
34
|
CheckSkipped,
|
|
36
35
|
MigrationsCheck,
|
|
36
|
+
holdSnapshot,
|
|
37
37
|
isCheckSkipped,
|
|
38
38
|
pgQuery,
|
|
39
39
|
quoteIdent,
|
|
40
40
|
quoteLiteral,
|
|
41
41
|
quoteName,
|
|
42
42
|
readOrAbsent,
|
|
43
|
+
releaseSnapshots,
|
|
44
|
+
setSnapshotsOff,
|
|
43
45
|
sqlLiteral
|
|
44
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-KT7NMELZ.js";
|
|
45
47
|
import {
|
|
46
48
|
DEFAULT_IGNORE_SCHEMAS,
|
|
47
49
|
SCORE_MAX,
|
|
@@ -52,7 +54,7 @@ import {
|
|
|
52
54
|
STORAGE_LIST_LIMIT,
|
|
53
55
|
SUPABASE_MGMT_API,
|
|
54
56
|
friendlyDbError
|
|
55
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-SQ52YBKK.js";
|
|
56
58
|
|
|
57
59
|
// src/scoring.ts
|
|
58
60
|
function summarize(results) {
|
|
@@ -297,9 +299,17 @@ async function scan(registry, options, bus) {
|
|
|
297
299
|
await bus?.emit("supaforge.check.after", { check: name, result });
|
|
298
300
|
}
|
|
299
301
|
};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
302
|
+
setSnapshotsOff(options.snapshot === false);
|
|
303
|
+
if (options.snapshot !== false) {
|
|
304
|
+
await Promise.all([source?.dbUrl, target?.dbUrl].filter(Boolean).map((url) => holdSnapshot(url)));
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
await Promise.all(
|
|
308
|
+
Array.from({ length: Math.min(checkConcurrency(), total) }, () => worker())
|
|
309
|
+
);
|
|
310
|
+
} finally {
|
|
311
|
+
if (options.snapshot !== false) await releaseSnapshots();
|
|
312
|
+
}
|
|
303
313
|
foldDuplicatePolicyFindings(results);
|
|
304
314
|
foldDuplicateExtensionFindings(results);
|
|
305
315
|
const summary = summarize(results);
|
|
@@ -394,7 +404,9 @@ var SchemaCheck = class extends Check {
|
|
|
394
404
|
this.fetchIgnoredSchemaTables(ctx.target.dbUrl, ignoreSchemas)
|
|
395
405
|
]);
|
|
396
406
|
for (const notice of schemaNotices(result.notices ?? [])) ctx.onNotice?.(notice);
|
|
397
|
-
|
|
407
|
+
const issues = sqlToIssues(result, "schema", ignoreSchemas, ignoredSchemaTables);
|
|
408
|
+
const roles = await this.targetRoles(ctx.target.dbUrl);
|
|
409
|
+
return roles?.size ? withoutAbsentRoles(issues, roles) : issues;
|
|
398
410
|
} catch (err) {
|
|
399
411
|
if (err instanceof Error && err.message.includes("@dbdiff/cli is not installed")) {
|
|
400
412
|
throw new CheckSkipped("@dbdiff/cli is not installed");
|
|
@@ -412,6 +424,15 @@ var SchemaCheck = class extends Check {
|
|
|
412
424
|
* Returns a Set of lowercase table names, bare and schema-qualified. Fails silently so that a transient
|
|
413
425
|
* DB error here never blocks the main schema diff.
|
|
414
426
|
*/
|
|
427
|
+
/** The target's roles, or undefined when they cannot be read. */
|
|
428
|
+
async targetRoles(dbUrl) {
|
|
429
|
+
try {
|
|
430
|
+
const rows = await this.queryFn(dbUrl, "SELECT rolname FROM pg_roles");
|
|
431
|
+
return new Set(rows.map((r) => r.rolname));
|
|
432
|
+
} catch {
|
|
433
|
+
return void 0;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
415
436
|
async fetchIgnoredSchemaTables(dbUrl, ignoreSchemas) {
|
|
416
437
|
if (ignoreSchemas.length === 0) return /* @__PURE__ */ new Set();
|
|
417
438
|
try {
|
|
@@ -2092,12 +2113,24 @@ var ExtensionsCheck = class extends Check {
|
|
|
2092
2113
|
}
|
|
2093
2114
|
name = "extensions";
|
|
2094
2115
|
async scan(ctx) {
|
|
2095
|
-
const [source, target] = await Promise.all([
|
|
2116
|
+
const [source, target, reachable] = await Promise.all([
|
|
2096
2117
|
this.fetchExtensions(ctx.source.dbUrl),
|
|
2097
|
-
this.fetchExtensions(ctx.target.dbUrl)
|
|
2118
|
+
this.fetchExtensions(ctx.target.dbUrl),
|
|
2119
|
+
this.fetchUpdates(ctx.target.dbUrl)
|
|
2098
2120
|
]);
|
|
2099
2121
|
const ignored = new Set(ctx.config.ignoreExtensions ?? []);
|
|
2100
|
-
return diffExtensions(source, target.filter((e) => !ignored.has(e.name) || source.some((s) => s.name === e.name)));
|
|
2122
|
+
return diffExtensions(source, target.filter((e) => !ignored.has(e.name) || source.some((s) => s.name === e.name)), reachable);
|
|
2123
|
+
}
|
|
2124
|
+
/** The versions each installed extension can be updated to on this server. */
|
|
2125
|
+
async fetchUpdates(dbUrl) {
|
|
2126
|
+
try {
|
|
2127
|
+
const rows = await this.queryFn(dbUrl, UPDATES_SQL);
|
|
2128
|
+
const out = /* @__PURE__ */ new Map();
|
|
2129
|
+
for (const r of rows) out.set(r.name, (out.get(r.name) ?? /* @__PURE__ */ new Set()).add(r.version));
|
|
2130
|
+
return out;
|
|
2131
|
+
} catch {
|
|
2132
|
+
return void 0;
|
|
2133
|
+
}
|
|
2101
2134
|
}
|
|
2102
2135
|
async fetchExtensions(dbUrl) {
|
|
2103
2136
|
return await this.queryFn(dbUrl, EXTENSIONS_SQL);
|
|
@@ -2111,7 +2144,13 @@ var EXTENSIONS_SQL = `
|
|
|
2111
2144
|
JOIN pg_namespace n ON n.oid = e.extnamespace
|
|
2112
2145
|
ORDER BY e.extname
|
|
2113
2146
|
`;
|
|
2114
|
-
|
|
2147
|
+
var UPDATES_SQL = `
|
|
2148
|
+
SELECT e.extname AS name, p.target AS version
|
|
2149
|
+
FROM pg_extension e
|
|
2150
|
+
CROSS JOIN LATERAL pg_extension_update_paths(e.extname) p
|
|
2151
|
+
WHERE p.source = e.extversion AND p.path IS NOT NULL
|
|
2152
|
+
`;
|
|
2153
|
+
function diffExtensions(source, target, reachable) {
|
|
2115
2154
|
const issues = [];
|
|
2116
2155
|
const sourceMap = new Map(source.map((e) => [e.name, e]));
|
|
2117
2156
|
const targetMap = new Map(target.map((e) => [e.name, e]));
|
|
@@ -2125,7 +2164,13 @@ function diffExtensions(source, target) {
|
|
|
2125
2164
|
description: `Extension "${name}" (v${ext.version}) is enabled in source (schema: ${ext.schema}) but not in target.`,
|
|
2126
2165
|
sourceValue: ext,
|
|
2127
2166
|
sql: {
|
|
2128
|
-
|
|
2167
|
+
// Into the schema it is in on the source, which plain PostgreSQL
|
|
2168
|
+
// may not have — Supabase's `extensions`. Made first; if the server
|
|
2169
|
+
// does not ship the extension, the fix is left out with it. A
|
|
2170
|
+
// system schema (pg_cron's pg_catalog) is always there, and cannot
|
|
2171
|
+
// be made.
|
|
2172
|
+
up: ext.schema === "public" ? `CREATE EXTENSION IF NOT EXISTS ${quoteName(name)};` : `${ext.schema.startsWith("pg_") ? "" : `CREATE SCHEMA IF NOT EXISTS ${quoteName(ext.schema)};
|
|
2173
|
+
`}CREATE EXTENSION IF NOT EXISTS ${quoteName(name)} SCHEMA ${quoteName(ext.schema)};`,
|
|
2129
2174
|
down: `DROP EXTENSION IF EXISTS ${quoteName(name)};`
|
|
2130
2175
|
}
|
|
2131
2176
|
});
|
|
@@ -2147,6 +2192,7 @@ function diffExtensions(source, target) {
|
|
|
2147
2192
|
const tgtExt = targetMap.get(name);
|
|
2148
2193
|
if (!tgtExt) continue;
|
|
2149
2194
|
if (srcExt.version !== tgtExt.version) {
|
|
2195
|
+
const updatable = !reachable || reachable.get(name)?.has(srcExt.version);
|
|
2150
2196
|
issues.push({
|
|
2151
2197
|
id: `ext-version-${name}`,
|
|
2152
2198
|
check: "extensions",
|
|
@@ -2155,10 +2201,12 @@ function diffExtensions(source, target) {
|
|
|
2155
2201
|
description: `Extension "${name}" is v${srcExt.version} in source but v${tgtExt.version} in target.`,
|
|
2156
2202
|
sourceValue: srcExt,
|
|
2157
2203
|
targetValue: tgtExt,
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2204
|
+
...updatable ? {
|
|
2205
|
+
sql: {
|
|
2206
|
+
up: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(srcExt.version)};`,
|
|
2207
|
+
down: `ALTER EXTENSION ${quoteName(name)} UPDATE TO ${quoteLiteral(tgtExt.version)};`
|
|
2208
|
+
}
|
|
2209
|
+
} : { 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)` }
|
|
2162
2210
|
});
|
|
2163
2211
|
}
|
|
2164
2212
|
}
|
|
@@ -2417,4 +2465,4 @@ export {
|
|
|
2417
2465
|
CheckRegistry,
|
|
2418
2466
|
createDefaultRegistry
|
|
2419
2467
|
};
|
|
2420
|
-
//# sourceMappingURL=chunk-
|
|
2468
|
+
//# sourceMappingURL=chunk-CAQ3QQFP.js.map
|
|
@@ -3,20 +3,20 @@ import {
|
|
|
3
3
|
getAppliedVersions,
|
|
4
4
|
getPendingMigrations,
|
|
5
5
|
runMigration
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AL6INEFX.js";
|
|
7
7
|
import {
|
|
8
8
|
comparedSchemas,
|
|
9
9
|
fingerprint
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-GGZ7YWBZ.js";
|
|
11
11
|
import {
|
|
12
12
|
isDestructiveSql
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YUJ2MHLM.js";
|
|
14
14
|
import {
|
|
15
15
|
splitSqlStatements
|
|
16
16
|
} from "./chunk-WK5YTINL.js";
|
|
17
17
|
import {
|
|
18
18
|
BaseCommand
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-OXS42LJH.js";
|
|
20
20
|
import {
|
|
21
21
|
DEFAULT_IGNORE_SCHEMAS,
|
|
22
22
|
bold,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
errMsg,
|
|
25
25
|
ok,
|
|
26
26
|
warn
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-SQ52YBKK.js";
|
|
28
28
|
|
|
29
29
|
// src/commands/migrate/run.ts
|
|
30
30
|
import { Flags } from "@oclif/core";
|
|
@@ -200,4 +200,4 @@ export {
|
|
|
200
200
|
findDestructiveStatements,
|
|
201
201
|
truncateSql
|
|
202
202
|
};
|
|
203
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-CCB7ARZU.js.map
|
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
captureSnapshot,
|
|
7
7
|
findLatestSnapshot,
|
|
8
8
|
loadSnapshot
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5UHIWFQG.js";
|
|
10
10
|
import {
|
|
11
11
|
slugify
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-Z2YUOA4W.js";
|
|
13
13
|
import {
|
|
14
14
|
MIGRATIONS_SUBDIR,
|
|
15
15
|
SUPAFORGE_DIR
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-SQ52YBKK.js";
|
|
17
17
|
|
|
18
18
|
// src/migration.ts
|
|
19
19
|
import { mkdir, writeFile, readFile, readdir } from "fs/promises";
|
|
@@ -245,4 +245,4 @@ export {
|
|
|
245
245
|
loadMigrations,
|
|
246
246
|
listMigrationFiles
|
|
247
247
|
};
|
|
248
|
-
//# sourceMappingURL=chunk-
|
|
248
|
+
//# sourceMappingURL=chunk-EWNZIRCD.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
captureSnapshot
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5UHIWFQG.js";
|
|
4
4
|
import {
|
|
5
5
|
checkPgDumpCompat
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Z2YUOA4W.js";
|
|
7
7
|
import {
|
|
8
8
|
newPgClient,
|
|
9
9
|
pgQuery,
|
|
10
10
|
quoteName
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KT7NMELZ.js";
|
|
12
12
|
import {
|
|
13
13
|
BRANCHES_FILE,
|
|
14
14
|
CLONE_PROGRESS_INTERVAL_MS,
|
|
15
15
|
PG_PIPELINE_TIMEOUT_MS,
|
|
16
16
|
SUPABASE_PLATFORM_SCHEMAS
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-SQ52YBKK.js";
|
|
18
18
|
|
|
19
19
|
// src/branch.ts
|
|
20
20
|
import { spawn } from "child_process";
|
|
@@ -640,4 +640,4 @@ export {
|
|
|
640
640
|
isCloneDatabase,
|
|
641
641
|
sourceLooksLikeCloneOf
|
|
642
642
|
};
|
|
643
|
-
//# sourceMappingURL=chunk-
|
|
643
|
+
//# sourceMappingURL=chunk-FD2JKEJA.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
rolesNamedBy,
|
|
5
5
|
runLikeApply,
|
|
6
6
|
sqlSkeleton
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YUJ2MHLM.js";
|
|
8
8
|
import {
|
|
9
9
|
isCommentOnly,
|
|
10
10
|
splitSqlStatements
|
|
@@ -14,13 +14,13 @@ import {
|
|
|
14
14
|
getServerMajorVersion,
|
|
15
15
|
globToRegExp,
|
|
16
16
|
resolvePgDumpPath
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-Z2YUOA4W.js";
|
|
18
18
|
import {
|
|
19
19
|
pgQuery,
|
|
20
20
|
quoteIdent,
|
|
21
21
|
quoteLiteral,
|
|
22
22
|
quoteName
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-KT7NMELZ.js";
|
|
24
24
|
|
|
25
25
|
// src/prove.ts
|
|
26
26
|
import { randomBytes } from "crypto";
|
|
@@ -28,7 +28,16 @@ import { execFile, spawn as spawn2 } from "child_process";
|
|
|
28
28
|
import { promisify } from "util";
|
|
29
29
|
import { fingerprintSql, stateSql } from "@akal/pg-conformance";
|
|
30
30
|
|
|
31
|
+
// src/expression-forms.ts
|
|
32
|
+
var LITERAL = `'(?:[^']|'')*'(?:::[a-z_][\\w ]*(?:\\(\\d+(?:,\\s*\\d+)?\\))?)?`;
|
|
33
|
+
var CAST_ARRAY = new RegExp(`\\(ARRAY\\[(${LITERAL}(?:, ${LITERAL})*)\\]\\)::([a-z_][\\w ]*?(?:\\(\\d+(?:,\\s*\\d+)?\\))?)\\[\\]`, "g");
|
|
34
|
+
var ELEMENT = new RegExp(LITERAL, "g");
|
|
35
|
+
function canonicalArrays(text) {
|
|
36
|
+
return text.replace(CAST_ARRAY, (_match, elements, type) => `ARRAY[${(elements.match(ELEMENT) ?? []).map((e) => `(${e})::${type}`).join(", ")}]`);
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
// src/state-diff.ts
|
|
40
|
+
var canonical = (d) => typeof d === "string" ? canonicalArrays(d) : d;
|
|
32
41
|
var show = (v) => {
|
|
33
42
|
if (v === null || v === void 0) return "none";
|
|
34
43
|
if (typeof v === "boolean") return v ? "yes" : "no";
|
|
@@ -89,9 +98,9 @@ function compareTable(out, subject, a, b) {
|
|
|
89
98
|
`constraint on ${prefix}`,
|
|
90
99
|
a.constraints,
|
|
91
100
|
b.constraints,
|
|
92
|
-
(c) => c.name,
|
|
101
|
+
(c) => c.type === "not_null" ? c.definition : c.name,
|
|
93
102
|
(o, s, x, y) => {
|
|
94
|
-
compareField(o, s, "definition", x.definition, y.definition);
|
|
103
|
+
compareField(o, s, "definition", canonical(x.definition), canonical(y.definition));
|
|
95
104
|
compareField(o, s, "validated", x.validated, y.validated);
|
|
96
105
|
compareField(o, s, "deferrable", x.deferrable, y.deferrable);
|
|
97
106
|
compareField(o, s, "deferred", x.deferred, y.deferred);
|
|
@@ -103,7 +112,7 @@ function compareTable(out, subject, a, b) {
|
|
|
103
112
|
a.indexes,
|
|
104
113
|
b.indexes,
|
|
105
114
|
(i) => i.name,
|
|
106
|
-
(o, s, x, y) => compareField(o, s, "definition", x.definition, y.definition)
|
|
115
|
+
(o, s, x, y) => compareField(o, s, "definition", canonical(x.definition), canonical(y.definition))
|
|
107
116
|
);
|
|
108
117
|
compareKeyed(
|
|
109
118
|
out,
|
|
@@ -115,8 +124,8 @@ function compareTable(out, subject, a, b) {
|
|
|
115
124
|
compareField(o, s, "command", x.command, y.command);
|
|
116
125
|
compareField(o, s, "permissive", x.permissive, y.permissive);
|
|
117
126
|
compareField(o, s, "roles", x.roles, y.roles);
|
|
118
|
-
compareField(o, s, "using", x.using, y.using);
|
|
119
|
-
compareField(o, s, "with check", x.with_check, y.with_check);
|
|
127
|
+
compareField(o, s, "using", canonical(x.using), canonical(y.using));
|
|
128
|
+
compareField(o, s, "with check", canonical(x.with_check), canonical(y.with_check));
|
|
120
129
|
}
|
|
121
130
|
);
|
|
122
131
|
compareKeyed(
|
|
@@ -125,7 +134,7 @@ function compareTable(out, subject, a, b) {
|
|
|
125
134
|
a.triggers,
|
|
126
135
|
b.triggers,
|
|
127
136
|
(t) => t.name,
|
|
128
|
-
(o, s, x, y) => compareField(o, s, "definition", x.definition, y.definition)
|
|
137
|
+
(o, s, x, y) => compareField(o, s, "definition", canonical(x.definition), canonical(y.definition))
|
|
129
138
|
);
|
|
130
139
|
}
|
|
131
140
|
function diffState(before, after) {
|
|
@@ -146,7 +155,7 @@ function diffState(before, after) {
|
|
|
146
155
|
(v) => qualify(v.schema, v.name),
|
|
147
156
|
(o, s, a, b) => {
|
|
148
157
|
compareField(o, s, "materialized", a.materialized, b.materialized);
|
|
149
|
-
compareField(o, s, "definition", a.definition, b.definition);
|
|
158
|
+
compareField(o, s, "definition", canonical(a.definition), canonical(b.definition));
|
|
150
159
|
compareField(o, s, "options", a.options, b.options);
|
|
151
160
|
}
|
|
152
161
|
);
|
|
@@ -172,7 +181,7 @@ function diffState(before, after) {
|
|
|
172
181
|
(r) => `${qualify(r.schema, r.name)}(${r.arguments})`,
|
|
173
182
|
(o, s, a, b) => {
|
|
174
183
|
compareField(o, s, "kind", a.kind, b.kind);
|
|
175
|
-
compareField(o, s, "definition", a.definition, b.definition);
|
|
184
|
+
compareField(o, s, "definition", canonical(a.definition), canonical(b.definition));
|
|
176
185
|
}
|
|
177
186
|
);
|
|
178
187
|
compareKeyed(
|
|
@@ -447,7 +456,7 @@ async function proveConvergence(opts) {
|
|
|
447
456
|
const tablesBefore = sample ? await snapshotTables(cloneUrl, schemas) : void 0;
|
|
448
457
|
let notApplied;
|
|
449
458
|
if (opts.fixes) {
|
|
450
|
-
const replayed = await runLikeApply(cloneUrl, opts.fixes);
|
|
459
|
+
const replayed = await runLikeApply(cloneUrl, opts.fixes, sourceMajor);
|
|
451
460
|
const unmet = replayed.errors.filter((e) => / — not applied: /.test(e.error));
|
|
452
461
|
const failed = replayed.errors.filter((e) => !unmet.includes(e));
|
|
453
462
|
if (failed.length > 0) {
|
|
@@ -477,7 +486,7 @@ async function proveConvergence(opts) {
|
|
|
477
486
|
fingerprint(opts.sourceUrl, schemas),
|
|
478
487
|
fingerprint(cloneUrl, schemas)
|
|
479
488
|
]);
|
|
480
|
-
if (want === got) return reported({ converged: true, residual: [], cloneName });
|
|
489
|
+
if (canonicalArrays(want) === canonicalArrays(got)) return reported({ converged: true, residual: [], cloneName });
|
|
481
490
|
roundTripName = `${cloneName}_src`;
|
|
482
491
|
const roundTripUrl = withDatabase(opts.targetUrl, roundTripName);
|
|
483
492
|
const roundTrip = await copyOfSource(adminUrl, opts.sourceUrl, roundTripUrl, roundTripName, schemas, tools);
|
|
@@ -485,7 +494,7 @@ async function proveConvergence(opts) {
|
|
|
485
494
|
sourceCopyCreated = true;
|
|
486
495
|
if (roundTrip.ok) {
|
|
487
496
|
const wantRoundTripped = await fingerprint(roundTripUrl, schemas);
|
|
488
|
-
if (wantRoundTripped === got) return reported({ converged: true, residual: [], cloneName });
|
|
497
|
+
if (canonicalArrays(wantRoundTripped) === canonicalArrays(got)) return reported({ converged: true, residual: [], cloneName });
|
|
489
498
|
const residual2 = await describeDifference(roundTripUrl, cloneUrl, schemas, wantRoundTripped, got);
|
|
490
499
|
return reported(withinScope(residual2, before && diffState(await schemaState(roundTripUrl, schemas), before), opts.checks, cloneName));
|
|
491
500
|
}
|
|
@@ -749,4 +758,4 @@ export {
|
|
|
749
758
|
residualHeldBack,
|
|
750
759
|
proofScope
|
|
751
760
|
};
|
|
752
|
-
//# sourceMappingURL=chunk-
|
|
761
|
+
//# sourceMappingURL=chunk-GGZ7YWBZ.js.map
|