@akal/supaforge 0.0.45 → 0.0.46

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loadMigrations
3
- } from "./chunk-KPU6G6BO.js";
3
+ } from "./chunk-C32M67YH.js";
4
4
  import {
5
5
  ensureMigrationsTable,
6
6
  getAppliedVersions
@@ -18,16 +18,16 @@ import {
18
18
  rolesNamedBy,
19
19
  sqlSkeleton,
20
20
  statementSubject
21
- } from "./chunk-YABERWV7.js";
21
+ } from "./chunk-XBXMOGI3.js";
22
+ import {
23
+ loadSnapshot
24
+ } from "./chunk-67JVGG3G.js";
22
25
  import {
23
26
  isCommentOnly,
24
27
  isPsqlMetaCommand,
25
28
  splitSqlStatements,
26
29
  stripPsqlMetaCommands
27
- } from "./chunk-WK5YTINL.js";
28
- import {
29
- loadSnapshot
30
- } from "./chunk-ZLNP3DUB.js";
30
+ } from "./chunk-YE3RQLCR.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-R4FSOTB6.js.map
903
+ //# sourceMappingURL=chunk-2ELJ46KR.js.map
@@ -4,7 +4,7 @@ import {
4
4
  getServerMajorVersion,
5
5
  normalizeRoles,
6
6
  resolvePgDumpPath
7
- } from "./chunk-USIOUMYL.js";
7
+ } from "./chunk-YE3RQLCR.js";
8
8
  import {
9
9
  Check,
10
10
  inRolledBackTransaction,
@@ -1249,4 +1249,4 @@ export {
1249
1249
  DEFAULT_KEEP_COUNT,
1250
1250
  pruneSnapshots
1251
1251
  };
1252
- //# sourceMappingURL=chunk-ZLNP3DUB.js.map
1252
+ //# sourceMappingURL=chunk-67JVGG3G.js.map
@@ -6,13 +6,13 @@ import {
6
6
  formatSkips,
7
7
  renderDetailed,
8
8
  renderSummary
9
- } from "./chunk-EMRM4RIV.js";
9
+ } from "./chunk-FFRGDQMV.js";
10
10
  import {
11
11
  createDefaultRegistry,
12
12
  proveBeforeApply,
13
13
  scan,
14
14
  summarizeByKind
15
- } from "./chunk-DUTPOR7P.js";
15
+ } from "./chunk-AUNVMGTR.js";
16
16
  import {
17
17
  CHECK_META,
18
18
  CHECK_NAMES,
@@ -24,11 +24,7 @@ import {
24
24
  psqlBeside,
25
25
  resolveTableFilter,
26
26
  withDatabase
27
- } from "./chunk-YABERWV7.js";
28
- import {
29
- isCommentOnly,
30
- splitSqlStatements
31
- } from "./chunk-WK5YTINL.js";
27
+ } from "./chunk-XBXMOGI3.js";
32
28
  import {
33
29
  renderTip
34
30
  } from "./chunk-RQCXGO37.js";
@@ -38,13 +34,15 @@ import {
38
34
  import {
39
35
  isCloneDatabase,
40
36
  sourceLooksLikeCloneOf
41
- } from "./chunk-KTATU64Y.js";
37
+ } from "./chunk-YDISW5X7.js";
42
38
  import {
43
39
  describeMissingPgDump,
44
40
  getServerMajorVersion,
41
+ isCommentOnly,
45
42
  parseFlagList,
46
- resolvePgDumpPath
47
- } from "./chunk-USIOUMYL.js";
43
+ resolvePgDumpPath,
44
+ splitSqlStatements
45
+ } from "./chunk-YE3RQLCR.js";
48
46
  import {
49
47
  Preflight,
50
48
  pgQuery,
@@ -756,4 +754,4 @@ export {
756
754
  inertApplyFlags,
757
755
  Diff
758
756
  };
759
- //# sourceMappingURL=chunk-4RD66RHF.js.map
757
+ //# sourceMappingURL=chunk-AJ53RPJS.js.map
@@ -21,10 +21,7 @@ import {
21
21
  sqlToIssues,
22
22
  withPlatformExtensionCalls,
23
23
  withoutAbsentRoles
24
- } from "./chunk-YABERWV7.js";
25
- import {
26
- splitSqlStatements
27
- } from "./chunk-WK5YTINL.js";
24
+ } from "./chunk-XBXMOGI3.js";
28
25
  import {
29
26
  RealtimeCheck,
30
27
  createPolicySql,
@@ -36,7 +33,10 @@ import {
36
33
  readJsonArray,
37
34
  readJsonObject,
38
35
  schemaPolicySql
39
- } from "./chunk-ZLNP3DUB.js";
36
+ } from "./chunk-67JVGG3G.js";
37
+ import {
38
+ splitSqlStatements
39
+ } from "./chunk-YE3RQLCR.js";
40
40
  import {
41
41
  Check,
42
42
  CheckSkipped,
@@ -2444,4 +2444,4 @@ export {
2444
2444
  createDefaultRegistry,
2445
2445
  proveBeforeApply
2446
2446
  };
2447
- //# sourceMappingURL=chunk-DUTPOR7P.js.map
2447
+ //# sourceMappingURL=chunk-AUNVMGTR.js.map
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  migrationsDir,
3
3
  writeMigrationFile
4
- } from "./chunk-JVZYVZUH.js";
4
+ } from "./chunk-ZBQLDCYV.js";
5
5
  import {
6
6
  createDefaultRegistry,
7
7
  proveBeforeApply,
8
8
  scan
9
- } from "./chunk-DUTPOR7P.js";
9
+ } from "./chunk-AUNVMGTR.js";
10
10
  import {
11
11
  CHECK_NAMES,
12
12
  promote
13
- } from "./chunk-YABERWV7.js";
13
+ } from "./chunk-XBXMOGI3.js";
14
14
  import {
15
15
  captureSnapshot,
16
16
  unrestorableSchema
17
- } from "./chunk-ZLNP3DUB.js";
17
+ } from "./chunk-67JVGG3G.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-J64XMOXU.js.map
533
+ //# sourceMappingURL=chunk-BLP7UO6C.js.map
@@ -1,15 +1,13 @@
1
- import {
2
- isCommentOnly,
3
- splitSqlStatements
4
- } from "./chunk-WK5YTINL.js";
5
1
  import {
6
2
  captureSnapshot,
7
3
  findLatestSnapshot,
8
4
  loadSnapshot
9
- } from "./chunk-ZLNP3DUB.js";
5
+ } from "./chunk-67JVGG3G.js";
10
6
  import {
11
- slugify
12
- } from "./chunk-USIOUMYL.js";
7
+ isCommentOnly,
8
+ slugify,
9
+ splitSqlStatements
10
+ } from "./chunk-YE3RQLCR.js";
13
11
  import {
14
12
  MIGRATIONS_SUBDIR,
15
13
  SUPAFORGE_DIR
@@ -245,4 +243,4 @@ export {
245
243
  loadMigrations,
246
244
  listMigrationFiles
247
245
  };
248
- //# sourceMappingURL=chunk-KPU6G6BO.js.map
246
+ //# sourceMappingURL=chunk-C32M67YH.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CHECK_META,
3
3
  isComparisonCheck
4
- } from "./chunk-YABERWV7.js";
4
+ } from "./chunk-XBXMOGI3.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-EMRM4RIV.js.map
244
+ //# sourceMappingURL=chunk-FFRGDQMV.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  comparedSchemas,
3
3
  fingerprint
4
- } from "./chunk-YABERWV7.js";
4
+ } from "./chunk-XBXMOGI3.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-UPWUXQ24.js.map
27
+ //# sourceMappingURL=chunk-LV44B3BX.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  targetFingerprint,
3
3
  writtenAgainst
4
- } from "./chunk-UPWUXQ24.js";
4
+ } from "./chunk-LV44B3BX.js";
5
5
  import {
6
6
  ensureMigrationsTable,
7
7
  getAppliedVersions,
@@ -10,13 +10,13 @@ import {
10
10
  } from "./chunk-HWRRFF55.js";
11
11
  import {
12
12
  isDestructiveSql
13
- } from "./chunk-YABERWV7.js";
14
- import {
15
- splitSqlStatements
16
- } from "./chunk-WK5YTINL.js";
13
+ } from "./chunk-XBXMOGI3.js";
17
14
  import {
18
15
  BaseCommand
19
16
  } from "./chunk-CKH6J7DI.js";
17
+ import {
18
+ splitSqlStatements
19
+ } from "./chunk-YE3RQLCR.js";
20
20
  import {
21
21
  DEFAULT_IGNORE_SCHEMAS,
22
22
  bold,
@@ -180,4 +180,4 @@ export {
180
180
  findDestructiveStatements,
181
181
  truncateSql
182
182
  };
183
- //# sourceMappingURL=chunk-HGCTVCLV.js.map
183
+ //# sourceMappingURL=chunk-PH2PU4NS.js.map
@@ -1,17 +1,15 @@
1
- import {
2
- isCommentOnly,
3
- splitSqlStatements
4
- } from "./chunk-WK5YTINL.js";
5
1
  import {
6
2
  dbdiffPgToolsEnv,
7
3
  describeMissingPgDump,
8
4
  escapeRegex,
9
5
  getServerMajorVersion,
10
6
  globToRegExp,
7
+ isCommentOnly,
11
8
  matchesGlob,
12
9
  parseFlagList,
13
- resolvePgDumpPath
14
- } from "./chunk-USIOUMYL.js";
10
+ resolvePgDumpPath,
11
+ splitSqlStatements
12
+ } from "./chunk-YE3RQLCR.js";
15
13
  import {
16
14
  Check,
17
15
  heldSnapshot,
@@ -3026,6 +3024,9 @@ function withDatabase(dbUrl, database) {
3026
3024
  url.pathname = `/${database}`;
3027
3025
  return url.toString();
3028
3026
  }
3027
+ function withoutNotNullConstraints(fingerprint2) {
3028
+ return fingerprint2.split("\n").filter((line) => !/^con .+ NOT NULL (?:"(?:[^"]|"")+"|\S+) valid=t deferrable=f deferred=f$/.test(line)).join("\n");
3029
+ }
3029
3030
  async function fingerprint(dbUrl, schemas) {
3030
3031
  const rows = await pgQuery(dbUrl, fingerprintSql(schemas));
3031
3032
  const value = rows[0]?.fingerprint;
@@ -3155,9 +3156,10 @@ async function proveConvergence(opts) {
3155
3156
  const withData = data ? { ...r, data } : r;
3156
3157
  return notApplied?.length ? { ...withData, notApplied } : withData;
3157
3158
  };
3159
+ const comparable = sourceMajor < 18 ? withoutNotNullConstraints : (fp) => fp;
3158
3160
  const [want, got] = await Promise.all([
3159
- fingerprint(opts.sourceUrl, schemas),
3160
- fingerprint(cloneUrl, schemas)
3161
+ fingerprint(opts.sourceUrl, schemas).then(comparable),
3162
+ fingerprint(cloneUrl, schemas).then(comparable)
3161
3163
  ]);
3162
3164
  if (canonicalArrays(want) === canonicalArrays(got)) return reported({ converged: true, residual: [], cloneName });
3163
3165
  roundTripName = `${cloneName}_src`;
@@ -3166,7 +3168,7 @@ async function proveConvergence(opts) {
3166
3168
  if (roundTrip !== null) {
3167
3169
  sourceCopyCreated = true;
3168
3170
  if (roundTrip.ok) {
3169
- const wantRoundTripped = await fingerprint(roundTripUrl, schemas);
3171
+ const wantRoundTripped = comparable(await fingerprint(roundTripUrl, schemas));
3170
3172
  if (canonicalArrays(wantRoundTripped) === canonicalArrays(got)) return reported({ converged: true, residual: [], cloneName });
3171
3173
  const residual2 = await describeDifference2(roundTripUrl, cloneUrl, schemas, wantRoundTripped, got);
3172
3174
  return reported(withinScope(residual2, before && diffState(await schemaState(roundTripUrl, schemas), before), opts.checks, cloneName));
@@ -3463,4 +3465,4 @@ export {
3463
3465
  residualHeldBack,
3464
3466
  proofScope
3465
3467
  };
3466
- //# sourceMappingURL=chunk-YABERWV7.js.map
3468
+ //# sourceMappingURL=chunk-XBXMOGI3.js.map
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  captureSnapshot
3
- } from "./chunk-ZLNP3DUB.js";
3
+ } from "./chunk-67JVGG3G.js";
4
4
  import {
5
- checkPgDumpCompat
6
- } from "./chunk-USIOUMYL.js";
5
+ checkPgDumpCompat,
6
+ splitSqlStatements
7
+ } from "./chunk-YE3RQLCR.js";
7
8
  import {
8
9
  newPgClient,
9
10
  pgQuery,
@@ -18,7 +19,7 @@ import {
18
19
 
19
20
  // src/branch.ts
20
21
  import { spawn } from "child_process";
21
- import { readFile, writeFile, mkdir } from "fs/promises";
22
+ import { readFile, writeFile as writeFile2, mkdir } from "fs/promises";
22
23
  import { resolve, dirname } from "path";
23
24
 
24
25
  // src/stubs.ts
@@ -87,6 +88,73 @@ CREATE TABLE IF NOT EXISTS storage.objects (
87
88
  `;
88
89
  var CLONE_STUBS_SQL = [AUTH_STUBS_SQL, STORAGE_STUBS_SQL].join("\n");
89
90
 
91
+ // src/clone-privileges.ts
92
+ import { execFile } from "child_process";
93
+ import { mkdtemp, rm, writeFile } from "fs/promises";
94
+ import { tmpdir } from "os";
95
+ import { join } from "path";
96
+ import { promisify } from "util";
97
+ var run = promisify(execFile);
98
+ function privilegeEntries(listing) {
99
+ return listing.split("\n").filter((line) => /^\d+;\s+\d+\s+\d+\s+(?:DEFAULT\s+)?ACL\s/.test(line));
100
+ }
101
+ function privilegeStatements(sql) {
102
+ const body = sql.split("\n").filter((line) => !line.startsWith("\\")).join("\n");
103
+ return splitSqlStatements(body).map((s) => s.split("\n").filter((line) => !/^\s*--/.test(line)).join("\n").trim()).filter(Boolean);
104
+ }
105
+ function missingRole(err) {
106
+ const e = err;
107
+ if (e.code !== "42704") return void 0;
108
+ return /^role "((?:[^"]|"")+)" does not exist$/.exec(e.message ?? "")?.[1];
109
+ }
110
+ var isSessionSetting = (sql) => /^SET\s/i.test(sql) || /^SELECT\s+pg_catalog\.set_config\(/i.test(sql);
111
+ async function applyPrivileges(dbUrl, statements) {
112
+ const result = { granted: 0, notGranted: [], failures: [] };
113
+ const client = newPgClient(dbUrl);
114
+ await client.connect();
115
+ try {
116
+ for (const sql of statements) {
117
+ try {
118
+ await client.query(sql);
119
+ if (!isSessionSetting(sql)) result.granted++;
120
+ } catch (err) {
121
+ if (isSessionSetting(sql)) continue;
122
+ const summary = sql.replace(/\s+/g, " ").replace(/;$/, "");
123
+ const role = missingRole(err);
124
+ if (role) result.notGranted.push({ role, statement: summary });
125
+ else result.failures.push({ object: summary, error: err.message });
126
+ }
127
+ }
128
+ } finally {
129
+ await client.end();
130
+ }
131
+ return result;
132
+ }
133
+ async function restorePrivileges(opts) {
134
+ const dir = await mkdtemp(join(tmpdir(), "supaforge-acl-"));
135
+ try {
136
+ const archive = join(dir, "schema.dump");
137
+ const list = join(dir, "acl.list");
138
+ await run(opts.pgDumpPath, [
139
+ "--format=custom",
140
+ "--schema-only",
141
+ "--no-owner",
142
+ ...(opts.excludeSchemas ?? []).map((s) => `--exclude-schema=${s}`),
143
+ "--file",
144
+ archive,
145
+ opts.remoteUrl
146
+ ], { maxBuffer: 64 * 1024 * 1024 });
147
+ const { stdout: listing } = await run(opts.pgRestorePath, ["--list", archive], { maxBuffer: 256 * 1024 * 1024 });
148
+ const entries = privilegeEntries(listing);
149
+ if (entries.length === 0) return { granted: 0, notGranted: [], failures: [] };
150
+ await writeFile(list, entries.join("\n") + "\n");
151
+ const { stdout: sql } = await run(opts.pgRestorePath, ["--use-list", list, "--file", "-", archive], { maxBuffer: 256 * 1024 * 1024 });
152
+ return await applyPrivileges(opts.localDbUrl, privilegeStatements(sql));
153
+ } finally {
154
+ await rm(dir, { recursive: true, force: true });
155
+ }
156
+ }
157
+
90
158
  // src/branch.ts
91
159
  var BRANCH_DB_PREFIX = "supaforge_branch_";
92
160
  function branchDbName(name) {
@@ -134,7 +202,7 @@ async function loadManifest(cwd = process.cwd()) {
134
202
  async function saveManifest(manifest, cwd) {
135
203
  const p = await manifestPath(cwd);
136
204
  await mkdir(dirname(p), { recursive: true });
137
- await writeFile(p, JSON.stringify(manifest, null, 2) + "\n");
205
+ await writeFile2(p, JSON.stringify(manifest, null, 2) + "\n");
138
206
  }
139
207
  async function createBranch(opts) {
140
208
  const cwd = opts.cwd ?? process.cwd();
@@ -210,13 +278,12 @@ async function tryDumpRestore(sourceUrl, newDb, schemaOnly, pgDumpPath = "pg_dum
210
278
  } finally {
211
279
  await client.end();
212
280
  }
213
- const dumpArgs = ["--format=custom", "--no-owner", "--no-acl", sourceUrl];
281
+ const dumpArgs = ["--format=custom", "--no-owner", sourceUrl];
214
282
  if (schemaOnly) dumpArgs.unshift("--schema-only");
215
283
  const targetUrl = replaceDbName(sourceUrl, newDb);
216
284
  const restoreArgs = [
217
285
  "--format=custom",
218
286
  "--no-owner",
219
- "--no-acl",
220
287
  `--dbname=${targetUrl}`
221
288
  ];
222
289
  try {
@@ -515,10 +582,22 @@ async function cloneRemoteToLocal(opts) {
515
582
  throw err;
516
583
  }
517
584
  const { failures, unavailable } = restoreFailures(restoreLog);
585
+ const privileges = await restorePrivileges({
586
+ pgDumpPath: compat.pgDumpPath,
587
+ pgRestorePath: compat.pgRestorePath,
588
+ remoteUrl: opts.remoteUrl,
589
+ localDbUrl,
590
+ excludeSchemas: opts.excludeSchemas
591
+ }).catch((err) => ({
592
+ granted: 0,
593
+ notGranted: [],
594
+ failures: [{ object: "the source's privileges", error: err.message.split("\n")[0] }]
595
+ }));
518
596
  return {
519
597
  url: localDbUrl,
520
- failures,
598
+ failures: [...failures, ...privileges.failures],
521
599
  unavailable,
600
+ notGranted: privileges.notGranted,
522
601
  extensionsInstalled: extensions.installed
523
602
  };
524
603
  }
@@ -653,4 +732,4 @@ export {
653
732
  isCloneDatabase,
654
733
  sourceLooksLikeCloneOf
655
734
  };
656
- //# sourceMappingURL=chunk-KTATU64Y.js.map
735
+ //# sourceMappingURL=chunk-YDISW5X7.js.map
@@ -2,6 +2,120 @@ import {
2
2
  newPgClient
3
3
  } from "./chunk-RC7ZU7OV.js";
4
4
 
5
+ // src/utils/sql-split.ts
6
+ var ROUTINE_HEAD = /^CREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE)\b/i;
7
+ function withoutLeadingComments(text) {
8
+ let rest = text.trimStart();
9
+ for (; ; ) {
10
+ if (rest.startsWith("--")) {
11
+ const newline = rest.indexOf("\n");
12
+ rest = newline === -1 ? "" : rest.slice(newline + 1).trimStart();
13
+ } else if (rest.startsWith("/*")) {
14
+ const close = rest.indexOf("*/");
15
+ rest = close === -1 ? "" : rest.slice(close + 2).trimStart();
16
+ } else {
17
+ return rest;
18
+ }
19
+ }
20
+ }
21
+ var DOLLAR_TAG = /^\$(?:[A-Za-z_][A-Za-z0-9_]*)?\$/;
22
+ function splitSqlStatements(sql) {
23
+ const statements = [];
24
+ let start = 0;
25
+ let i = 0;
26
+ let blockDepth = 0;
27
+ let beginDepth = 0;
28
+ const push = (end) => {
29
+ const piece = sql.slice(start, end).trim();
30
+ if (piece.length > 0) statements.push(piece);
31
+ };
32
+ while (i < sql.length) {
33
+ if (blockDepth > 0) {
34
+ if (sql.startsWith("/*", i)) {
35
+ blockDepth++;
36
+ i += 2;
37
+ continue;
38
+ }
39
+ if (sql.startsWith("*/", i)) {
40
+ blockDepth--;
41
+ i += 2;
42
+ continue;
43
+ }
44
+ i++;
45
+ continue;
46
+ }
47
+ if (sql.startsWith("/*", i)) {
48
+ blockDepth = 1;
49
+ i += 2;
50
+ continue;
51
+ }
52
+ if (sql.startsWith("--", i)) {
53
+ const newline = sql.indexOf("\n", i);
54
+ i = newline === -1 ? sql.length : newline + 1;
55
+ continue;
56
+ }
57
+ const ch = sql[i];
58
+ if (ch === "'" || ch === '"') {
59
+ i++;
60
+ while (i < sql.length) {
61
+ if (sql[i] !== ch) {
62
+ i++;
63
+ continue;
64
+ }
65
+ if (sql[i + 1] === ch) {
66
+ i += 2;
67
+ continue;
68
+ }
69
+ i++;
70
+ break;
71
+ }
72
+ continue;
73
+ }
74
+ if (ch === "$") {
75
+ const tag = DOLLAR_TAG.exec(sql.slice(i));
76
+ if (tag) {
77
+ const close = sql.indexOf(tag[0], i + tag[0].length);
78
+ i = close === -1 ? sql.length : close + tag[0].length;
79
+ continue;
80
+ }
81
+ i++;
82
+ continue;
83
+ }
84
+ if (/[A-Za-z_]/.test(ch)) {
85
+ const word = /^[A-Za-z_][A-Za-z0-9_]*/.exec(sql.slice(i, i + 64))[0];
86
+ const upper = word.toUpperCase();
87
+ if ((upper === "BEGIN" || upper === "CASE") && ROUTINE_HEAD.test(withoutLeadingComments(sql.slice(start, i)))) {
88
+ beginDepth++;
89
+ } else if (upper === "END" && beginDepth > 0) {
90
+ beginDepth--;
91
+ }
92
+ i += word.length;
93
+ continue;
94
+ }
95
+ if (ch === ";" && beginDepth === 0) {
96
+ push(i);
97
+ i++;
98
+ start = i;
99
+ continue;
100
+ }
101
+ i++;
102
+ }
103
+ push(sql.length);
104
+ return statements;
105
+ }
106
+ function isCommentOnly(statement) {
107
+ const meaningful = statement.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("--"));
108
+ return meaningful.length === 0;
109
+ }
110
+ var PSQL_WRAPPER_LINE = /^[ \t]*\\(?:un)?restrict\b[^\n]*$/gm;
111
+ function stripPsqlMetaCommands(sql) {
112
+ return sql.replace(PSQL_WRAPPER_LINE, "");
113
+ }
114
+ function isPsqlMetaCommand(statement) {
115
+ const meaningful = statement.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("--"));
116
+ return meaningful.length > 0 && meaningful.every((line) => line.startsWith("\\"));
117
+ }
118
+
5
119
  // src/utils/strings.ts
6
120
  var MAX_SLUG_LENGTH = 60;
7
121
  function slugify(name, separator = "_") {
@@ -241,6 +355,10 @@ function getInstallInstructions(majorVersion) {
241
355
  }
242
356
 
243
357
  export {
358
+ splitSqlStatements,
359
+ isCommentOnly,
360
+ stripPsqlMetaCommands,
361
+ isPsqlMetaCommand,
244
362
  slugify,
245
363
  escapeRegex,
246
364
  parseFlagList,
@@ -254,4 +372,4 @@ export {
254
372
  dbdiffPgToolsEnv,
255
373
  checkPgDumpCompat
256
374
  };
257
- //# sourceMappingURL=chunk-USIOUMYL.js.map
375
+ //# sourceMappingURL=chunk-YE3RQLCR.js.map
@@ -1,18 +1,16 @@
1
1
  import {
2
2
  targetFingerprint,
3
3
  writtenAgainstLine
4
- } from "./chunk-UPWUXQ24.js";
4
+ } from "./chunk-LV44B3BX.js";
5
5
  import {
6
6
  RolesCheck,
7
7
  isDestructiveSql,
8
8
  runDbDiff
9
- } from "./chunk-YABERWV7.js";
9
+ } from "./chunk-XBXMOGI3.js";
10
10
  import {
11
+ slugify,
11
12
  splitSqlStatements
12
- } from "./chunk-WK5YTINL.js";
13
- import {
14
- slugify
15
- } from "./chunk-USIOUMYL.js";
13
+ } from "./chunk-YE3RQLCR.js";
16
14
  import {
17
15
  DEFAULT_MIGRATIONS_DIR,
18
16
  pgQuery
@@ -91,4 +89,4 @@ export {
91
89
  writeMigrationFile,
92
90
  generateTimestamp
93
91
  };
94
- //# sourceMappingURL=chunk-JVZYVZUH.js.map
92
+ //# sourceMappingURL=chunk-ZBQLDCYV.js.map
@@ -4,6 +4,13 @@ import { R as RestoreFailure } from '../branch-BppjQBv_.js';
4
4
  import { S as SupaForgeConfig } from '../config-l3ggjw9r.js';
5
5
  import '@oclif/core';
6
6
 
7
+ /** A privilege the clone could not grant, because its role is not on this server. */
8
+ interface NotGranted {
9
+ role: string;
10
+ /** The statement, summarised: `GRANT SELECT ON TABLE public.film TO reader`. */
11
+ statement: string;
12
+ }
13
+
7
14
  /**
8
15
  * Clone a remote environment to a local database and manage clones.
9
16
  *
@@ -36,6 +43,12 @@ declare class Clone extends BaseCommand {
36
43
  * are stated rather than counted as the clone failing — see restoreFailures.
37
44
  */
38
45
  declare function formatUnavailable(items: readonly RestoreFailure[]): string[];
46
+ /**
47
+ * The source's privileges this server has no role for, by role: a clone of a
48
+ * Supabase project onto plain PostgreSQL has no `anon`, so none of its grants.
49
+ * Everything else the source grants is in the clone.
50
+ */
51
+ declare function formatNotGranted(items: readonly NotGranted[]): string[];
39
52
  /**
40
53
  * What pg_restore could not reproduce, for step 1 of the output.
41
54
  *
@@ -63,4 +76,4 @@ declare function formatRestoreFailures(failures: readonly RestoreFailure[]): str
63
76
  */
64
77
  declare function configAfterClone(config: SupaForgeConfig, envName: string, localDbUrl: string): SupaForgeConfig;
65
78
 
66
- export { configAfterClone, Clone as default, formatRestoreFailures, formatUnavailable };
79
+ export { configAfterClone, Clone as default, formatNotGranted, formatRestoreFailures, formatUnavailable };
@@ -13,14 +13,14 @@ import {
13
13
  maintenanceUrl,
14
14
  reconcileClones,
15
15
  replaceDbName
16
- } from "../chunk-KTATU64Y.js";
16
+ } from "../chunk-YDISW5X7.js";
17
17
  import {
18
18
  captureSnapshot,
19
19
  formatSnapshotLayers
20
- } from "../chunk-ZLNP3DUB.js";
20
+ } from "../chunk-67JVGG3G.js";
21
21
  import {
22
22
  checkPgDumpCompat
23
- } from "../chunk-USIOUMYL.js";
23
+ } from "../chunk-YE3RQLCR.js";
24
24
  import {
25
25
  DEFAULT_LOCAL_PORT,
26
26
  LOCAL_PG_PASSWORD,
@@ -283,6 +283,7 @@ var Clone = class _Clone extends BaseCommand {
283
283
  this.log(` ${dim(`Installed first, in the schema the source keeps them in: ${cloned.extensionsInstalled.join(", ")}`)}`);
284
284
  }
285
285
  for (const line of formatUnavailable(cloned.unavailable)) this.log(line);
286
+ for (const line of formatNotGranted(cloned.notGranted)) this.log(line);
286
287
  for (const line of formatRestoreFailures(cloned.failures)) this.log(line);
287
288
  } catch (err) {
288
289
  progressOut.write("\n");
@@ -338,7 +339,8 @@ var Clone = class _Clone extends BaseCommand {
338
339
  snapshot: snapshot.manifest,
339
340
  config: newConfig,
340
341
  restoreFailures: cloned.failures,
341
- unavailable: cloned.unavailable
342
+ unavailable: cloned.unavailable,
343
+ notGranted: cloned.notGranted
342
344
  });
343
345
  if (missing > 0) this.exit(1);
344
346
  return;
@@ -387,6 +389,13 @@ function formatUnavailable(items) {
387
389
  ];
388
390
  return [` ${dim(`Not available on this server, as expected for a Supabase project: ${parts.join("; ")}`)}`];
389
391
  }
392
+ function formatNotGranted(items) {
393
+ if (items.length === 0) return [];
394
+ const byRole = /* @__PURE__ */ new Map();
395
+ for (const { role } of items) byRole.set(role, (byRole.get(role) ?? 0) + 1);
396
+ const roles = [...byRole].map(([role, n]) => `${role} (${n})`).join(", ");
397
+ return [` ${dim(`Privileges not granted, as these roles are not on this server: ${roles}`)}`];
398
+ }
390
399
  var RESTORE_FAILURES_SHOWN = 15;
391
400
  function formatRestoreFailures(failures) {
392
401
  if (failures.length === 0) return [];
@@ -412,6 +421,7 @@ function configAfterClone(config, envName, localDbUrl) {
412
421
  export {
413
422
  configAfterClone,
414
423
  Clone as default,
424
+ formatNotGranted,
415
425
  formatRestoreFailures,
416
426
  formatUnavailable
417
427
  };
@@ -2,17 +2,16 @@ import {
2
2
  Diff,
3
3
  inertApplyFlags,
4
4
  rollbackHint
5
- } from "../chunk-4RD66RHF.js";
5
+ } from "../chunk-AJ53RPJS.js";
6
6
  import "../chunk-Q43MN6NE.js";
7
- import "../chunk-EMRM4RIV.js";
8
- import "../chunk-DUTPOR7P.js";
9
- import "../chunk-YABERWV7.js";
10
- import "../chunk-WK5YTINL.js";
7
+ import "../chunk-FFRGDQMV.js";
8
+ import "../chunk-AUNVMGTR.js";
9
+ import "../chunk-XBXMOGI3.js";
11
10
  import "../chunk-RQCXGO37.js";
12
11
  import "../chunk-CKH6J7DI.js";
13
- import "../chunk-KTATU64Y.js";
14
- import "../chunk-ZLNP3DUB.js";
15
- import "../chunk-USIOUMYL.js";
12
+ import "../chunk-YDISW5X7.js";
13
+ import "../chunk-67JVGG3G.js";
14
+ import "../chunk-YE3RQLCR.js";
16
15
  import "../chunk-RC7ZU7OV.js";
17
16
  import "../chunk-KHXEES2M.js";
18
17
  import "../chunk-SQ52YBKK.js";
@@ -1,16 +1,15 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-4RD66RHF.js";
3
+ } from "../chunk-AJ53RPJS.js";
4
4
  import "../chunk-Q43MN6NE.js";
5
- import "../chunk-EMRM4RIV.js";
6
- import "../chunk-DUTPOR7P.js";
7
- import "../chunk-YABERWV7.js";
8
- import "../chunk-WK5YTINL.js";
5
+ import "../chunk-FFRGDQMV.js";
6
+ import "../chunk-AUNVMGTR.js";
7
+ import "../chunk-XBXMOGI3.js";
9
8
  import "../chunk-RQCXGO37.js";
10
9
  import "../chunk-CKH6J7DI.js";
11
- import "../chunk-KTATU64Y.js";
12
- import "../chunk-ZLNP3DUB.js";
13
- import "../chunk-USIOUMYL.js";
10
+ import "../chunk-YDISW5X7.js";
11
+ import "../chunk-67JVGG3G.js";
12
+ import "../chunk-YE3RQLCR.js";
14
13
  import "../chunk-RC7ZU7OV.js";
15
14
  import "../chunk-KHXEES2M.js";
16
15
  import "../chunk-SQ52YBKK.js";
@@ -1,13 +1,12 @@
1
1
  import {
2
2
  createServer
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
- import "../chunk-WK5YTINL.js";
9
- import "../chunk-ZLNP3DUB.js";
10
- import "../chunk-USIOUMYL.js";
3
+ } from "../chunk-BLP7UO6C.js";
4
+ import "../chunk-ZBQLDCYV.js";
5
+ import "../chunk-LV44B3BX.js";
6
+ import "../chunk-AUNVMGTR.js";
7
+ import "../chunk-XBXMOGI3.js";
8
+ import "../chunk-67JVGG3G.js";
9
+ import "../chunk-YE3RQLCR.js";
11
10
  import "../chunk-RC7ZU7OV.js";
12
11
  import {
13
12
  installProcessGuard,
@@ -1,20 +1,19 @@
1
1
  import {
2
2
  truncateSql
3
- } from "../../chunk-HGCTVCLV.js";
3
+ } from "../../chunk-PH2PU4NS.js";
4
4
  import {
5
5
  generateTimestamp,
6
6
  writeMigrationFile
7
- } from "../../chunk-JVZYVZUH.js";
8
- import "../../chunk-UPWUXQ24.js";
7
+ } from "../../chunk-ZBQLDCYV.js";
8
+ import "../../chunk-LV44B3BX.js";
9
9
  import "../../chunk-HWRRFF55.js";
10
- import "../../chunk-YABERWV7.js";
11
- import "../../chunk-WK5YTINL.js";
10
+ import "../../chunk-XBXMOGI3.js";
12
11
  import {
13
12
  BaseCommand
14
13
  } from "../../chunk-CKH6J7DI.js";
15
14
  import {
16
15
  slugify
17
- } from "../../chunk-USIOUMYL.js";
16
+ } from "../../chunk-YE3RQLCR.js";
18
17
  import "../../chunk-RC7ZU7OV.js";
19
18
  import "../../chunk-KHXEES2M.js";
20
19
  import {
@@ -2,13 +2,12 @@ import {
2
2
  MigrateRun,
3
3
  findDestructiveStatements,
4
4
  truncateSql
5
- } from "../../chunk-HGCTVCLV.js";
6
- import "../../chunk-UPWUXQ24.js";
5
+ } from "../../chunk-PH2PU4NS.js";
6
+ import "../../chunk-LV44B3BX.js";
7
7
  import "../../chunk-HWRRFF55.js";
8
- import "../../chunk-YABERWV7.js";
9
- import "../../chunk-WK5YTINL.js";
8
+ import "../../chunk-XBXMOGI3.js";
10
9
  import "../../chunk-CKH6J7DI.js";
11
- import "../../chunk-USIOUMYL.js";
10
+ import "../../chunk-YE3RQLCR.js";
12
11
  import "../../chunk-RC7ZU7OV.js";
13
12
  import "../../chunk-KHXEES2M.js";
14
13
  import "../../chunk-SQ52YBKK.js";
@@ -5,11 +5,10 @@ import {
5
5
  restoreFromMigrations,
6
6
  restoreFromSnapshot,
7
7
  summarizeStatement
8
- } from "../chunk-R4FSOTB6.js";
9
- import "../chunk-KPU6G6BO.js";
8
+ } from "../chunk-2ELJ46KR.js";
9
+ import "../chunk-C32M67YH.js";
10
10
  import "../chunk-HWRRFF55.js";
11
- import "../chunk-YABERWV7.js";
12
- import "../chunk-WK5YTINL.js";
11
+ import "../chunk-XBXMOGI3.js";
13
12
  import {
14
13
  renderTip
15
14
  } from "../chunk-RQCXGO37.js";
@@ -19,8 +18,8 @@ import {
19
18
  import {
20
19
  findLatestSnapshot,
21
20
  listSnapshots
22
- } from "../chunk-ZLNP3DUB.js";
23
- import "../chunk-USIOUMYL.js";
21
+ } from "../chunk-67JVGG3G.js";
22
+ import "../chunk-YE3RQLCR.js";
24
23
  import "../chunk-RC7ZU7OV.js";
25
24
  import "../chunk-KHXEES2M.js";
26
25
  import {
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  backup,
3
3
  listMigrationFiles
4
- } from "../chunk-KPU6G6BO.js";
5
- import "../chunk-WK5YTINL.js";
4
+ } from "../chunk-C32M67YH.js";
6
5
  import {
7
6
  renderTip
8
7
  } from "../chunk-RQCXGO37.js";
@@ -16,8 +15,8 @@ import {
16
15
  listSnapshots,
17
16
  pruneSnapshots,
18
17
  unrestorableSchema
19
- } from "../chunk-ZLNP3DUB.js";
20
- import "../chunk-USIOUMYL.js";
18
+ } from "../chunk-67JVGG3G.js";
19
+ import "../chunk-YE3RQLCR.js";
21
20
  import "../chunk-RC7ZU7OV.js";
22
21
  import "../chunk-KHXEES2M.js";
23
22
  import {
@@ -1,16 +1,15 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-4RD66RHF.js";
3
+ } from "../chunk-AJ53RPJS.js";
4
4
  import "../chunk-Q43MN6NE.js";
5
- import "../chunk-EMRM4RIV.js";
6
- import "../chunk-DUTPOR7P.js";
7
- import "../chunk-YABERWV7.js";
8
- import "../chunk-WK5YTINL.js";
5
+ import "../chunk-FFRGDQMV.js";
6
+ import "../chunk-AUNVMGTR.js";
7
+ import "../chunk-XBXMOGI3.js";
9
8
  import "../chunk-RQCXGO37.js";
10
9
  import "../chunk-CKH6J7DI.js";
11
- import "../chunk-KTATU64Y.js";
12
- import "../chunk-ZLNP3DUB.js";
13
- import "../chunk-USIOUMYL.js";
10
+ import "../chunk-YDISW5X7.js";
11
+ import "../chunk-67JVGG3G.js";
12
+ import "../chunk-YE3RQLCR.js";
14
13
  import "../chunk-RC7ZU7OV.js";
15
14
  import "../chunk-KHXEES2M.js";
16
15
  import "../chunk-SQ52YBKK.js";
package/dist/index.js CHANGED
@@ -3,38 +3,37 @@ import {
3
3
  createServer,
4
4
  getLastScanResult,
5
5
  setLastScanResult
6
- } from "./chunk-J64XMOXU.js";
6
+ } from "./chunk-BLP7UO6C.js";
7
7
  import {
8
8
  previewMigrationRestore,
9
9
  previewSnapshotRestore,
10
10
  restoreFromMigrations,
11
11
  restoreFromSnapshot
12
- } from "./chunk-R4FSOTB6.js";
12
+ } from "./chunk-2ELJ46KR.js";
13
13
  import {
14
14
  backup,
15
15
  listMigrationFiles,
16
16
  loadMigrations
17
- } from "./chunk-KPU6G6BO.js";
18
- import "./chunk-JVZYVZUH.js";
19
- import "./chunk-UPWUXQ24.js";
17
+ } from "./chunk-C32M67YH.js";
18
+ import "./chunk-ZBQLDCYV.js";
19
+ import "./chunk-LV44B3BX.js";
20
20
  import "./chunk-HWRRFF55.js";
21
21
  import {
22
22
  renderDetailed,
23
23
  renderSummary
24
- } from "./chunk-EMRM4RIV.js";
24
+ } from "./chunk-FFRGDQMV.js";
25
25
  import {
26
26
  CheckRegistry,
27
27
  computeScore,
28
28
  createDefaultRegistry,
29
29
  scan,
30
30
  summarize
31
- } from "./chunk-DUTPOR7P.js";
31
+ } from "./chunk-AUNVMGTR.js";
32
32
  import {
33
33
  CHECK_META,
34
34
  CHECK_NAMES,
35
35
  promote
36
- } from "./chunk-YABERWV7.js";
37
- import "./chunk-WK5YTINL.js";
36
+ } from "./chunk-XBXMOGI3.js";
38
37
  import {
39
38
  BRANCH_DB_PREFIX,
40
39
  branchDbName,
@@ -43,14 +42,14 @@ import {
43
42
  listBranches,
44
43
  loadManifest,
45
44
  replaceDbName
46
- } from "./chunk-KTATU64Y.js";
45
+ } from "./chunk-YDISW5X7.js";
47
46
  import {
48
47
  captureSnapshot,
49
48
  findLatestSnapshot,
50
49
  listSnapshots,
51
50
  loadSnapshot
52
- } from "./chunk-ZLNP3DUB.js";
53
- import "./chunk-USIOUMYL.js";
51
+ } from "./chunk-67JVGG3G.js";
52
+ import "./chunk-YE3RQLCR.js";
54
53
  import {
55
54
  Check
56
55
  } from "./chunk-RC7ZU7OV.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akal/supaforge",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "mcpName": "io.github.akalsoftware/supaforge",
5
5
  "description": "Diff and sync your Supabase environments",
6
6
  "author": "Akal Software Ltd",
@@ -1,121 +0,0 @@
1
- // src/utils/sql-split.ts
2
- var ROUTINE_HEAD = /^CREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE)\b/i;
3
- function withoutLeadingComments(text) {
4
- let rest = text.trimStart();
5
- for (; ; ) {
6
- if (rest.startsWith("--")) {
7
- const newline = rest.indexOf("\n");
8
- rest = newline === -1 ? "" : rest.slice(newline + 1).trimStart();
9
- } else if (rest.startsWith("/*")) {
10
- const close = rest.indexOf("*/");
11
- rest = close === -1 ? "" : rest.slice(close + 2).trimStart();
12
- } else {
13
- return rest;
14
- }
15
- }
16
- }
17
- var DOLLAR_TAG = /^\$(?:[A-Za-z_][A-Za-z0-9_]*)?\$/;
18
- function splitSqlStatements(sql) {
19
- const statements = [];
20
- let start = 0;
21
- let i = 0;
22
- let blockDepth = 0;
23
- let beginDepth = 0;
24
- const push = (end) => {
25
- const piece = sql.slice(start, end).trim();
26
- if (piece.length > 0) statements.push(piece);
27
- };
28
- while (i < sql.length) {
29
- if (blockDepth > 0) {
30
- if (sql.startsWith("/*", i)) {
31
- blockDepth++;
32
- i += 2;
33
- continue;
34
- }
35
- if (sql.startsWith("*/", i)) {
36
- blockDepth--;
37
- i += 2;
38
- continue;
39
- }
40
- i++;
41
- continue;
42
- }
43
- if (sql.startsWith("/*", i)) {
44
- blockDepth = 1;
45
- i += 2;
46
- continue;
47
- }
48
- if (sql.startsWith("--", i)) {
49
- const newline = sql.indexOf("\n", i);
50
- i = newline === -1 ? sql.length : newline + 1;
51
- continue;
52
- }
53
- const ch = sql[i];
54
- if (ch === "'" || ch === '"') {
55
- i++;
56
- while (i < sql.length) {
57
- if (sql[i] !== ch) {
58
- i++;
59
- continue;
60
- }
61
- if (sql[i + 1] === ch) {
62
- i += 2;
63
- continue;
64
- }
65
- i++;
66
- break;
67
- }
68
- continue;
69
- }
70
- if (ch === "$") {
71
- const tag = DOLLAR_TAG.exec(sql.slice(i));
72
- if (tag) {
73
- const close = sql.indexOf(tag[0], i + tag[0].length);
74
- i = close === -1 ? sql.length : close + tag[0].length;
75
- continue;
76
- }
77
- i++;
78
- continue;
79
- }
80
- if (/[A-Za-z_]/.test(ch)) {
81
- const word = /^[A-Za-z_][A-Za-z0-9_]*/.exec(sql.slice(i, i + 64))[0];
82
- const upper = word.toUpperCase();
83
- if ((upper === "BEGIN" || upper === "CASE") && ROUTINE_HEAD.test(withoutLeadingComments(sql.slice(start, i)))) {
84
- beginDepth++;
85
- } else if (upper === "END" && beginDepth > 0) {
86
- beginDepth--;
87
- }
88
- i += word.length;
89
- continue;
90
- }
91
- if (ch === ";" && beginDepth === 0) {
92
- push(i);
93
- i++;
94
- start = i;
95
- continue;
96
- }
97
- i++;
98
- }
99
- push(sql.length);
100
- return statements;
101
- }
102
- function isCommentOnly(statement) {
103
- const meaningful = statement.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("--"));
104
- return meaningful.length === 0;
105
- }
106
- var PSQL_WRAPPER_LINE = /^[ \t]*\\(?:un)?restrict\b[^\n]*$/gm;
107
- function stripPsqlMetaCommands(sql) {
108
- return sql.replace(PSQL_WRAPPER_LINE, "");
109
- }
110
- function isPsqlMetaCommand(statement) {
111
- const meaningful = statement.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("--"));
112
- return meaningful.length > 0 && meaningful.every((line) => line.startsWith("\\"));
113
- }
114
-
115
- export {
116
- splitSqlStatements,
117
- isCommentOnly,
118
- stripPsqlMetaCommands,
119
- isPsqlMetaCommand
120
- };
121
- //# sourceMappingURL=chunk-WK5YTINL.js.map