@akal/supaforge 0.0.32 → 0.0.34

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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -11
  3. package/dist/base-command.js +4 -3
  4. package/dist/{chunk-DMIWAJRB.js → chunk-3WKWPSFN.js} +6 -6
  5. package/dist/{chunk-GZREXCQZ.js → chunk-5STH2A6K.js} +17 -10
  6. package/dist/{chunk-6LJERPUN.js → chunk-6ERVCWLY.js} +20 -12
  7. package/dist/{chunk-GEHPTPNZ.js → chunk-7DL63NWP.js} +3 -3
  8. package/dist/{chunk-UWAVXC57.js → chunk-DQJSSTIJ.js} +39 -15
  9. package/dist/{chunk-ORQJVE57.js → chunk-EFKQOQGG.js} +15 -16
  10. package/dist/{chunk-7NAZGZPV.js → chunk-F46FFUKC.js} +16 -17
  11. package/dist/chunk-GQPGH6YR.js +50 -0
  12. package/dist/{chunk-6Q7MHFBM.js → chunk-HNJ6BNNZ.js} +2 -2
  13. package/dist/{chunk-MIRLB5JM.js → chunk-ICSCHS72.js} +66 -14
  14. package/dist/{chunk-6WAMNZLO.js → chunk-KNXHLVF7.js} +126 -4
  15. package/dist/{chunk-SQPCWGQO.js → chunk-MG3SFV5J.js} +22 -121
  16. package/dist/{chunk-BUOWHE36.js → chunk-N5VNNOA2.js} +37 -52
  17. package/dist/{chunk-3HGAV5CC.js → chunk-OB5GP7UB.js} +19 -16
  18. package/dist/{chunk-4IVN7QVY.js → chunk-PYAGSMFB.js} +23 -15
  19. package/dist/{chunk-SC2XHGIS.js → chunk-S5L4A3UR.js} +3 -3
  20. package/dist/{chunk-2SELREHW.js → chunk-TPX2MAO4.js} +7 -9
  21. package/dist/{chunk-NTUASFQ3.js → chunk-V2SBZERO.js} +4 -4
  22. package/dist/{chunk-G2DIPIYU.js → chunk-WK5YTINL.js} +29 -2
  23. package/dist/{chunk-BLKJWDTL.js → chunk-ZI435CAU.js} +2 -2
  24. package/dist/commands/clone.js +11 -11
  25. package/dist/commands/diff.d.ts +13 -1
  26. package/dist/commands/diff.js +19 -16
  27. package/dist/commands/hukam.js +15 -14
  28. package/dist/commands/init.js +5 -1
  29. package/dist/commands/mcp.d.ts +1 -0
  30. package/dist/commands/mcp.js +26 -10
  31. package/dist/commands/migrate/baseline.js +5 -4
  32. package/dist/commands/migrate/create.js +8 -7
  33. package/dist/commands/migrate/list.js +6 -5
  34. package/dist/commands/migrate/run.js +8 -7
  35. package/dist/commands/report.js +5 -4
  36. package/dist/commands/restore.js +13 -12
  37. package/dist/commands/snapshot.d.ts +7 -0
  38. package/dist/commands/snapshot.js +36 -8
  39. package/dist/commands/sync.js +15 -14
  40. package/dist/index.js +14 -14
  41. package/package.json +10 -8
  42. package/bin/dev.js +0 -10
  43. package/dist/base-command.js.map +0 -1
  44. package/dist/chunk-2SELREHW.js.map +0 -1
  45. package/dist/chunk-3HGAV5CC.js.map +0 -1
  46. package/dist/chunk-4IVN7QVY.js.map +0 -1
  47. package/dist/chunk-6LJERPUN.js.map +0 -1
  48. package/dist/chunk-6Q7MHFBM.js.map +0 -1
  49. package/dist/chunk-6WAMNZLO.js.map +0 -1
  50. package/dist/chunk-7NAZGZPV.js.map +0 -1
  51. package/dist/chunk-BLKJWDTL.js.map +0 -1
  52. package/dist/chunk-BUOWHE36.js.map +0 -1
  53. package/dist/chunk-DMIWAJRB.js.map +0 -1
  54. package/dist/chunk-DQQ5E563.js.map +0 -1
  55. package/dist/chunk-G2DIPIYU.js.map +0 -1
  56. package/dist/chunk-GEHPTPNZ.js.map +0 -1
  57. package/dist/chunk-GZREXCQZ.js.map +0 -1
  58. package/dist/chunk-MIRLB5JM.js.map +0 -1
  59. package/dist/chunk-NTUASFQ3.js.map +0 -1
  60. package/dist/chunk-ORQJVE57.js.map +0 -1
  61. package/dist/chunk-SC2XHGIS.js.map +0 -1
  62. package/dist/chunk-SQPCWGQO.js.map +0 -1
  63. package/dist/chunk-UWAVXC57.js.map +0 -1
  64. package/dist/commands/clone.js.map +0 -1
  65. package/dist/commands/diff.js.map +0 -1
  66. package/dist/commands/help.js.map +0 -1
  67. package/dist/commands/hukam.js.map +0 -1
  68. package/dist/commands/init.js.map +0 -1
  69. package/dist/commands/mcp.js.map +0 -1
  70. package/dist/commands/migrate/baseline.js.map +0 -1
  71. package/dist/commands/migrate/create.js.map +0 -1
  72. package/dist/commands/migrate/list.js.map +0 -1
  73. package/dist/commands/migrate/run.js.map +0 -1
  74. package/dist/commands/report.js.map +0 -1
  75. package/dist/commands/restore.js.map +0 -1
  76. package/dist/commands/snapshot.js.map +0 -1
  77. package/dist/commands/sync.js.map +0 -1
  78. package/dist/help.js.map +0 -1
  79. package/dist/index.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Akal Software Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -34,6 +34,23 @@ supaforge diff --apply # fix the target
34
34
 
35
35
  Everything that writes previews first. Add `--apply` to make it happen.
36
36
 
37
+ ## Install
38
+
39
+ | | |
40
+ | --- | --- |
41
+ | npm | `npm install -g @akal/supaforge`, or run it with `npx @akal/supaforge` |
42
+ | Homebrew | `brew install akalsoftware/tap/supaforge` |
43
+ | Docker | `docker run --rm -v "$PWD:/work" ghcr.io/akalsoftware/supaforge diff` |
44
+ | GitHub Actions | [`akalsoftware/supaforge-action`](https://github.com/akalsoftware/supaforge-action) — see [CI](#ci-and-exit-codes) |
45
+ | VS Code and its forks | The SupaForge extension: commands, and the MCP server for the editor's agent. Each [release](https://github.com/akalsoftware/supaforge/releases/latest) carries it as a `.vsix` |
46
+ | Cursor, VS Code, Claude | One-click installs of the MCP server — see [MCP](#mcp-ai-agents) |
47
+
48
+ It needs Node.js 20 or newer. DBDiff, its diff engine, comes with it as a
49
+ native binary for your platform, so there is nothing else to install. The
50
+ Docker image needs nothing at all, and carries the PostgreSQL client tools
51
+ `--prove` uses; pass connection strings with `-e`, and mount the project at
52
+ `/work`.
53
+
37
54
  ## What it compares
38
55
 
39
56
  | Check | What it reads | Fixed with |
@@ -51,7 +68,7 @@ Everything that writes previews first. Add `--apply` to make it happen.
51
68
  | Vault | Secret names and descriptions (values can't be read) | Command to run |
52
69
  | Extensions | `pg_extension` | SQL |
53
70
  | Migration history | Local migration files against `supabase_migrations` (target only) | SQL, opt-in |
54
- | Roles and grants | Custom roles, and grants including `anon`, `authenticated`, `service_role` | SQL |
71
+ | Roles and grants | Custom roles, and grants on tables, views, sequences and functions, including `anon`, `authenticated`, `service_role` | SQL |
55
72
 
56
73
  The schema check covers tables, columns, keys, indexes, partitions, views,
57
74
  materialized views, functions, triggers, sequences, enums, composite types,
@@ -113,9 +130,10 @@ Useful `diff` flags:
113
130
  a Supabase schema the target lacks, is skipped with the reason, and the rest
114
131
  still applies.
115
132
  - **`--prove`.** The fixes are replayed on a structure-only copy of the target,
116
- made on the target's own server. Nothing is applied unless the result matches
117
- the source. Changes a copy can't hold, such as cron jobs (pg_cron lives in
118
- one database per server), are listed as not proved.
133
+ made on the target's own server, the way the apply will run them. Nothing is
134
+ applied unless the result matches the source, and nothing is applied if the
135
+ proof can't run. Changes a copy can't hold, such as cron jobs (pg_cron lives
136
+ in one database per server), are listed as not proved.
119
137
 
120
138
  ```bash
121
139
  supaforge diff --dry-run # the plan, in order
@@ -145,6 +163,9 @@ A snapshot records a project's structure and configuration: schema, RLS
145
163
  policies, cron, webhooks, extensions, storage, auth, Edge Functions,
146
164
  reference data, Realtime, Vault names and grants. **It is not a
147
165
  backup.** It holds no rows beyond `checks.data.tables`, and no stored files.
166
+ Its schema is written as SQL by `pg_dump`, which has to be at least as new as
167
+ the server; without one the snapshot can still be diffed but not restored, and
168
+ `snapshot` exits 1 unless `--allow-schema-json-only` says that is enough.
148
169
 
149
170
  `restore --from-snapshot` puts back:
150
171
 
@@ -239,7 +260,7 @@ supaforge migrate run --env=prod --apply
239
260
  | `SUPAFORGE_DBDIFF_MEMORY` | `1G` | Memory limit for `@dbdiff/cli` (`2G`, `-1` for none) |
240
261
  | `SUPAFORGE_CONNECT_TIMEOUT` | `15` | Seconds to wait for a connection |
241
262
  | `SUPAFORGE_CHECK_CONCURRENCY` | `4` | Checks run at once. Lower it behind a tight pooler |
242
- | `SUPAFORGE_PG_BIN` | — | A directory of PostgreSQL client tools (`pg_dump`, `psql`) to use when the ones on `PATH` are too old for a server |
263
+ | `SUPAFORGE_PG_BIN` | — | A directory of PostgreSQL client tools (`pg_dump`, `psql`), used ahead of `PATH` — for a server newer than the tools on `PATH` |
243
264
 
244
265
  ## Self-hosted Supabase
245
266
 
@@ -270,13 +291,22 @@ would push the clone's shape, absences included, onto the target.
270
291
 
271
292
  ## CI and exit codes
272
293
 
294
+ The [GitHub Action](https://github.com/akalsoftware/supaforge-action) runs
295
+ `diff --ci` and adds a summary of the drift to the job page:
296
+
273
297
  ```yaml
274
- - run: npx @akal/supaforge diff --ci
298
+ - uses: akalsoftware/supaforge-action@v1
275
299
  env:
276
300
  DEV_DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}
277
301
  PROD_DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}
278
302
  ```
279
303
 
304
+ Anywhere else, run the CLI:
305
+
306
+ ```bash
307
+ npx @akal/supaforge diff --ci
308
+ ```
309
+
280
310
  | Code | Meaning |
281
311
  | --- | --- |
282
312
  | `0` | Did what was asked, including when there was nothing to do |
@@ -288,9 +318,33 @@ would push the clone's shape, absences included, onto the target.
288
318
 
289
319
  ## MCP (AI agents)
290
320
 
291
- ```json
292
- { "mcpServers": { "supaforge": { "command": "supaforge", "args": ["mcp"] } } }
293
- ```
321
+ SupaForge runs as an MCP server, so an AI agent in your editor can scan for
322
+ drift and fix it, asking you before anything is written.
323
+
324
+ [![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/install-mcp?name=supaforge&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBha2FsL3N1cGFmb3JnZSIsIm1jcCIsIi0tcHJvamVjdCIsIiR7d29ya3NwYWNlRm9sZGVyfSJdfQ==)
325
+ [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_SupaForge-0098FF?logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=supaforge&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40akal%2Fsupaforge%22%2C%22mcp%22%2C%22--project%22%2C%22%24%7BworkspaceFolder%7D%22%5D%7D)
326
+
327
+ - **Claude Desktop**: download the extension for your platform
328
+ (`supaforge-<version>-<platform>.mcpb`) from the
329
+ [latest release](https://github.com/akalsoftware/supaforge/releases/latest)
330
+ and open it. It asks for your project directory.
331
+ - **Claude Code**: install the plugin, which adds the MCP server and a skill
332
+ for applying fixes safely:
333
+
334
+ ```
335
+ /plugin marketplace add akalsoftware/claude-plugins
336
+ /plugin install supaforge@akalsoftware
337
+ ```
338
+
339
+ or add just the server: `claude mcp add supaforge -- npx -y @akal/supaforge mcp`
340
+ - **Any other client**:
341
+
342
+ ```json
343
+ { "mcpServers": { "supaforge": { "command": "npx", "args": ["-y", "@akal/supaforge", "mcp", "--project", "/path/to/project"] } } }
344
+ ```
345
+
346
+ It is listed in the [MCP Registry](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.akalsoftware/supaforge)
347
+ as `io.github.akalsoftware/supaforge`.
294
348
 
295
349
  The server exposes these tools:
296
350
 
@@ -302,8 +356,9 @@ The server exposes these tools:
302
356
  | `take_snapshot` | Writes files |
303
357
  | `create_migration` | Writes files |
304
358
 
305
- It reads the config in its own directory, and refuses a `configPath` from a
306
- client unless started with `--allow-config-path`.
359
+ It reads `supaforge.config.json` in the directory given by `--project` (or the
360
+ one it starts in), and refuses a `configPath` from a client unless started
361
+ with `--allow-config-path`.
307
362
 
308
363
  ## Hooks
309
364
 
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  BaseCommand
3
- } from "./chunk-GZREXCQZ.js";
4
- import "./chunk-SQPCWGQO.js";
5
- import "./chunk-6WAMNZLO.js";
3
+ } from "./chunk-5STH2A6K.js";
4
+ import "./chunk-MG3SFV5J.js";
5
+ import "./chunk-GQPGH6YR.js";
6
+ import "./chunk-KNXHLVF7.js";
6
7
  export {
7
8
  BaseCommand
8
9
  };
@@ -1,26 +1,26 @@
1
1
  import {
2
2
  runLikeApply
3
- } from "./chunk-UWAVXC57.js";
3
+ } from "./chunk-DQJSSTIJ.js";
4
4
  import {
5
5
  rolesNamedBy,
6
6
  sqlSkeleton
7
- } from "./chunk-BUOWHE36.js";
7
+ } from "./chunk-N5VNNOA2.js";
8
8
  import {
9
9
  isCommentOnly,
10
10
  splitSqlStatements
11
- } from "./chunk-G2DIPIYU.js";
11
+ } from "./chunk-WK5YTINL.js";
12
12
  import {
13
13
  describeMissingPgDump,
14
14
  getServerMajorVersion,
15
15
  resolvePgDumpPath
16
- } from "./chunk-MIRLB5JM.js";
16
+ } from "./chunk-ICSCHS72.js";
17
17
  import {
18
18
  globToRegExp
19
19
  } from "./chunk-DQQ5E563.js";
20
20
  import {
21
21
  pgQuery,
22
22
  quoteName
23
- } from "./chunk-SQPCWGQO.js";
23
+ } from "./chunk-MG3SFV5J.js";
24
24
 
25
25
  // src/prove.ts
26
26
  import { randomBytes } from "crypto";
@@ -599,4 +599,4 @@ export {
599
599
  residualHeldBack,
600
600
  proofScope
601
601
  };
602
- //# sourceMappingURL=chunk-DMIWAJRB.js.map
602
+ //# sourceMappingURL=chunk-3WKWPSFN.js.map
@@ -1,17 +1,21 @@
1
1
  import {
2
2
  DEFAULT_MIGRATIONS_DIR,
3
- Preflight,
4
- describeFailure,
5
- redactUrls
6
- } from "./chunk-SQPCWGQO.js";
3
+ Preflight
4
+ } from "./chunk-MG3SFV5J.js";
5
+ import {
6
+ installProcessGuard,
7
+ noteJsonWritten
8
+ } from "./chunk-GQPGH6YR.js";
7
9
  import {
8
10
  RUN_LOG_DIR,
9
11
  RUN_LOG_FILE,
10
12
  RUN_LOG_MAX_ENTRIES,
13
+ describeFailure,
11
14
  loadConfig,
15
+ redactUrls,
12
16
  validateConfig,
13
17
  validateSingleEnvConfig
14
- } from "./chunk-6WAMNZLO.js";
18
+ } from "./chunk-KNXHLVF7.js";
15
19
 
16
20
  // src/base-command.ts
17
21
  import { formatWithOptions } from "util";
@@ -85,6 +89,7 @@ var BaseCommand = class extends Command {
85
89
  /** The command's result as JSON, on stdout. */
86
90
  json(value) {
87
91
  this._jsonWritten = true;
92
+ noteJsonWritten();
88
93
  process.stdout.write(JSON.stringify(value, null, 2) + "\n");
89
94
  }
90
95
  /** Call after scan() to attach per-check metadata to the run log entry. */
@@ -94,6 +99,7 @@ var BaseCommand = class extends Command {
94
99
  async init() {
95
100
  await super.init();
96
101
  this._startTime = Date.now();
102
+ installProcessGuard(this.argv);
97
103
  }
98
104
  async catch(err) {
99
105
  this._logWritten = true;
@@ -130,10 +136,11 @@ var BaseCommand = class extends Command {
130
136
  async loadConfigOrFail() {
131
137
  try {
132
138
  return await loadConfig();
133
- } catch {
134
- this.error(
135
- 'Could not load supaforge.config.json. Run "supaforge init" first.'
136
- );
139
+ } catch (err) {
140
+ if (err?.code === "ENOENT") {
141
+ this.error('Could not load supaforge.config.json. Run "supaforge init" first.');
142
+ }
143
+ this.error(`Could not load supaforge.config.json: ${redactUrls(describeFailure(err))}`);
137
144
  }
138
145
  }
139
146
  /**
@@ -204,4 +211,4 @@ export {
204
211
  readRunLog,
205
212
  BaseCommand
206
213
  };
207
- //# sourceMappingURL=chunk-GZREXCQZ.js.map
214
+ //# sourceMappingURL=chunk-5STH2A6K.js.map
@@ -1,26 +1,27 @@
1
1
  import {
2
2
  backup
3
- } from "./chunk-NTUASFQ3.js";
3
+ } from "./chunk-V2SBZERO.js";
4
4
  import {
5
5
  createDefaultRegistry,
6
6
  scan
7
- } from "./chunk-3HGAV5CC.js";
7
+ } from "./chunk-OB5GP7UB.js";
8
8
  import {
9
9
  CHECK_NAMES,
10
10
  promote
11
- } from "./chunk-UWAVXC57.js";
11
+ } from "./chunk-DQJSSTIJ.js";
12
12
  import {
13
- captureSnapshot
14
- } from "./chunk-MIRLB5JM.js";
13
+ captureSnapshot,
14
+ unrestorableSchema
15
+ } from "./chunk-ICSCHS72.js";
15
16
  import {
16
- checkConnection,
17
- describeFailure,
18
- redactUrls
19
- } from "./chunk-SQPCWGQO.js";
17
+ checkConnection
18
+ } from "./chunk-MG3SFV5J.js";
20
19
  import {
20
+ describeFailure,
21
+ redactUrls,
21
22
  resolveConfig,
22
23
  validateConfig
23
- } from "./chunk-6WAMNZLO.js";
24
+ } from "./chunk-KNXHLVF7.js";
24
25
 
25
26
  // src/mcp/state.ts
26
27
  var lastScanResult = null;
@@ -227,11 +228,18 @@ ${unreachable.join("\n")}` }], isError: true };
227
228
  };
228
229
  }
229
230
  const result = await captureSnapshot({ envName, env, config, cwd: effectiveCwd });
231
+ const unrestorable = unrestorableSchema(result.manifest);
230
232
  return {
231
233
  content: [
232
234
  {
233
235
  type: "text",
234
- text: JSON.stringify({ timestamp: result.timestamp, dir: result.dir, manifest: result.manifest }, null, 2)
236
+ text: JSON.stringify({
237
+ timestamp: result.timestamp,
238
+ dir: result.dir,
239
+ manifest: result.manifest,
240
+ // Said up front: restore is the wrong moment to find out.
241
+ ...unrestorable ? { warning: `This snapshot cannot restore the schema: ${unrestorable}` } : {}
242
+ }, null, 2)
235
243
  }
236
244
  ]
237
245
  };
@@ -496,4 +504,4 @@ export {
496
504
  clearLastScanResult,
497
505
  createServer
498
506
  };
499
- //# sourceMappingURL=chunk-6LJERPUN.js.map
507
+ //# sourceMappingURL=chunk-6ERVCWLY.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CHECK_META,
3
3
  isComparisonCheck
4
- } from "./chunk-UWAVXC57.js";
4
+ } from "./chunk-DQJSSTIJ.js";
5
5
  import {
6
6
  CHECK_LINE_PADDING,
7
7
  bold,
@@ -9,7 +9,7 @@ import {
9
9
  dim,
10
10
  ok,
11
11
  warn
12
- } from "./chunk-6WAMNZLO.js";
12
+ } from "./chunk-KNXHLVF7.js";
13
13
 
14
14
  // src/render.ts
15
15
  function countErrored(result) {
@@ -237,4 +237,4 @@ export {
237
237
  renderDetailed,
238
238
  formatSkips
239
239
  };
240
- //# sourceMappingURL=chunk-GEHPTPNZ.js.map
240
+ //# sourceMappingURL=chunk-7DL63NWP.js.map
@@ -10,11 +10,11 @@ import {
10
10
  parseStatements,
11
11
  referencedTables,
12
12
  sqlSkeleton
13
- } from "./chunk-BUOWHE36.js";
13
+ } from "./chunk-N5VNNOA2.js";
14
14
  import {
15
15
  isCommentOnly,
16
16
  splitSqlStatements
17
- } from "./chunk-G2DIPIYU.js";
17
+ } from "./chunk-WK5YTINL.js";
18
18
  import {
19
19
  globToRegExp,
20
20
  matchesGlob,
@@ -22,14 +22,14 @@ import {
22
22
  } from "./chunk-DQQ5E563.js";
23
23
  import {
24
24
  Check,
25
- errMsg,
26
- pgClientConfig,
25
+ newPgClient,
27
26
  pgQuery,
28
27
  quoteName
29
- } from "./chunk-SQPCWGQO.js";
28
+ } from "./chunk-MG3SFV5J.js";
30
29
  import {
31
- SUPABASE_PLATFORM_SCHEMAS
32
- } from "./chunk-6WAMNZLO.js";
30
+ SUPABASE_PLATFORM_SCHEMAS,
31
+ errMsg
32
+ } from "./chunk-KNXHLVF7.js";
33
33
 
34
34
  // src/utils/table-filter.ts
35
35
  var parseTableList = parseFlagList;
@@ -127,9 +127,6 @@ function isComparisonCheck(name) {
127
127
  return CHECK_KIND[name] === "comparison";
128
128
  }
129
129
 
130
- // src/promote.ts
131
- import pg from "pg";
132
-
133
130
  // src/pg-errors.ts
134
131
  var ABSENT_ON_TARGET = /* @__PURE__ */ new Set(["42P01", "42883", "3F000", "42704"]);
135
132
  var UNDEFINED_COLUMN = "42703";
@@ -318,7 +315,7 @@ function dropDuplicateObjectFixes(statements, skipped) {
318
315
  }
319
316
  async function executeSql(dbUrl, statements, result, transactional) {
320
317
  if (statements.length === 0) return;
321
- const client = new pg.Client(pgClientConfig(dbUrl));
318
+ const client = newPgClient(dbUrl);
322
319
  await client.connect();
323
320
  try {
324
321
  if (transactional) await runInTransaction(client, statements, result);
@@ -695,7 +692,8 @@ var RolesCheck = class extends Check {
695
692
  ...diffRoles(sourceRoles, targetRoles),
696
693
  ...diffGrants(
697
694
  [...sourceAll, ...sourceColumns ?? []].filter((g) => comparable(g) && !byDefault(g)),
698
- [...targetAll, ...targetColumns ?? []].filter(comparable)
695
+ [...targetAll, ...targetColumns ?? []].filter(comparable),
696
+ absentOn(targetRoles, sourceRoles)
699
697
  ),
700
698
  ...defaultGrantsToRevoke(
701
699
  sourceObjects,
@@ -706,6 +704,10 @@ var RolesCheck = class extends Check {
706
704
  ];
707
705
  }
708
706
  };
707
+ function absentOn(target, source) {
708
+ const present = new Set((target ?? []).map((r) => r.rolname));
709
+ return new Set((source ?? []).map((r) => r.rolname).filter((name) => !present.has(name)));
710
+ }
709
711
  function roleAttrs(r) {
710
712
  const attrs = [];
711
713
  if (r.rolsuper) attrs.push("SUPERUSER");
@@ -842,12 +844,34 @@ function describeGroup(gs) {
842
844
  return `${gs.map((g) => g.privilege_type).join(", ")} ${column}ON ${describeObject(gs[0])} TO ${gs[0].grantee}`;
843
845
  }
844
846
  var groupKey = (gs) => grantKey(gs[0]).replace(/\.[^.]+$/, "");
845
- function diffGrants(source, target) {
847
+ function grantsToMissingRoles(grants) {
848
+ const byRole = /* @__PURE__ */ new Map();
849
+ for (const g of grants) byRole.set(g.grantee, [...byRole.get(g.grantee) ?? [], g]);
850
+ return [...byRole].map(([role, gs]) => {
851
+ const groups = grouped(gs);
852
+ const objects = new Set(gs.map((g) => describeObject(g))).size;
853
+ const what = `${gs.length} privilege${gs.length === 1 ? "" : "s"} on ${objects} object${objects === 1 ? "" : "s"}`;
854
+ return {
855
+ id: `roles-grant-missing-role-${role}`,
856
+ check: "roles",
857
+ severity: "warning",
858
+ title: `Missing grants: ${what} to ${role}, a role the target does not have`,
859
+ description: `The source grants ${what} to "${role}", which the target lacks. They can only be applied once the role exists (see "Missing role"); on a target that is not meant to have it, skip the roles check.`,
860
+ sourceValue: gs,
861
+ sql: {
862
+ up: groups.map((g) => `GRANT ${groupTarget(g)} TO ${granteeSql(role)}${g[0].is_grantable ? " WITH GRANT OPTION" : ""};`).join("\n"),
863
+ down: groups.map((g) => `REVOKE ${groupTarget(g)} FROM ${granteeSql(role)};`).reverse().join("\n")
864
+ }
865
+ };
866
+ });
867
+ }
868
+ function diffGrants(source, target, missingRoles = /* @__PURE__ */ new Set()) {
846
869
  const issues = [];
847
870
  const sourceMap = new Map(source.map((g) => [grantKey(g), g]));
848
871
  const targetMap = new Map(target.map((g) => [grantKey(g), g]));
849
872
  const missing = [...sourceMap].filter(([key]) => !targetMap.has(key)).map(([, g]) => g);
850
- for (const gs of grouped(missing)) {
873
+ issues.push(...grantsToMissingRoles(missing.filter((g) => missingRoles.has(g.grantee))));
874
+ for (const gs of grouped(missing.filter((g) => !missingRoles.has(g.grantee)))) {
851
875
  const plural = gs.length > 1 ? "s" : "";
852
876
  issues.push({
853
877
  id: `roles-grant-missing-${groupKey(gs)}`,
@@ -913,4 +937,4 @@ export {
913
937
  runLikeApply,
914
938
  promote
915
939
  };
916
- //# sourceMappingURL=chunk-UWAVXC57.js.map
940
+ //# sourceMappingURL=chunk-DQJSSTIJ.js.map
@@ -1,24 +1,23 @@
1
1
  import {
2
2
  captureSnapshot,
3
3
  checkPgDumpCompat
4
- } from "./chunk-MIRLB5JM.js";
4
+ } from "./chunk-ICSCHS72.js";
5
5
  import {
6
- pgClientConfig,
6
+ newPgClient,
7
7
  pgQuery,
8
8
  quoteName
9
- } from "./chunk-SQPCWGQO.js";
9
+ } from "./chunk-MG3SFV5J.js";
10
10
  import {
11
11
  BRANCHES_FILE,
12
12
  CLONE_PROGRESS_INTERVAL_MS,
13
13
  PG_PIPELINE_TIMEOUT_MS,
14
14
  SUPABASE_PLATFORM_SCHEMAS
15
- } from "./chunk-6WAMNZLO.js";
15
+ } from "./chunk-KNXHLVF7.js";
16
16
 
17
17
  // src/branch.ts
18
18
  import { spawn } from "child_process";
19
19
  import { readFile, writeFile, mkdir } from "fs/promises";
20
20
  import { resolve, dirname } from "path";
21
- import pg from "pg";
22
21
 
23
22
  // src/stubs.ts
24
23
  var AUTH_STUBS_SQL = `
@@ -176,7 +175,7 @@ async function createBranch(opts) {
176
175
  async function tryTemplateCopy(sourceUrl, newDb) {
177
176
  const { database } = parseUrl(sourceUrl);
178
177
  const maintenanceUrl = replaceDbName(sourceUrl, "postgres");
179
- const client = new pg.Client(pgClientConfig(maintenanceUrl));
178
+ const client = newPgClient(maintenanceUrl);
180
179
  try {
181
180
  await client.connect();
182
181
  await client.query(`CREATE DATABASE ${quoteName(newDb)} TEMPLATE ${quoteName(database)}`);
@@ -189,7 +188,7 @@ async function tryTemplateCopy(sourceUrl, newDb) {
189
188
  }
190
189
  async function tryDumpRestore(sourceUrl, newDb, schemaOnly, pgDumpPath = "pg_dump", pgRestorePath = "pg_restore") {
191
190
  const maintenanceUrl = replaceDbName(sourceUrl, "postgres");
192
- const client = new pg.Client(pgClientConfig(maintenanceUrl));
191
+ const client = newPgClient(maintenanceUrl);
193
192
  try {
194
193
  await client.connect();
195
194
  await client.query(`CREATE DATABASE ${quoteName(newDb)}`);
@@ -256,7 +255,7 @@ async function tryDumpRestore(sourceUrl, newDb, schemaOnly, pgDumpPath = "pg_dum
256
255
  });
257
256
  return true;
258
257
  } catch {
259
- const cleanup = new pg.Client(pgClientConfig(maintenanceUrl));
258
+ const cleanup = newPgClient(maintenanceUrl);
260
259
  try {
261
260
  await cleanup.connect();
262
261
  await cleanup.query(`DROP DATABASE IF EXISTS ${quoteName(newDb)}`);
@@ -272,7 +271,7 @@ async function listBranches(cwd = process.cwd()) {
272
271
  }
273
272
  async function listServerDatabases(serverUrl) {
274
273
  const maintenanceUrl = replaceDbName(serverUrl, "postgres");
275
- const client = new pg.Client(pgClientConfig(maintenanceUrl));
274
+ const client = newPgClient(maintenanceUrl);
276
275
  try {
277
276
  await client.connect();
278
277
  const { rows } = await client.query(
@@ -334,7 +333,7 @@ async function deleteBranch(name, sourceUrl, cwd = process.cwd()) {
334
333
  if (idx === -1) throw new Error(`Branch "${name}" not found.`);
335
334
  const branch = manifest.branches[idx];
336
335
  const maintenanceUrl = replaceDbName(sourceUrl, "postgres");
337
- const client = new pg.Client(pgClientConfig(maintenanceUrl));
336
+ const client = newPgClient(maintenanceUrl);
338
337
  try {
339
338
  await client.connect();
340
339
  await client.query(
@@ -355,7 +354,7 @@ async function cloneRemoteToLocal(opts) {
355
354
  }
356
355
  const localMaintenanceUrl = opts.localBaseUrl;
357
356
  const localDbUrl = replaceDbName(opts.localBaseUrl, opts.localDbName);
358
- const client = new pg.Client(pgClientConfig(localMaintenanceUrl));
357
+ const client = newPgClient(localMaintenanceUrl);
359
358
  try {
360
359
  await client.connect();
361
360
  if (opts.force) {
@@ -378,7 +377,7 @@ async function cloneRemoteToLocal(opts) {
378
377
  await client.end();
379
378
  }
380
379
  if (opts.excludeSchemas?.length) {
381
- const stubClient = new pg.Client(pgClientConfig(localDbUrl));
380
+ const stubClient = newPgClient(localDbUrl);
382
381
  try {
383
382
  await stubClient.connect();
384
383
  await stubClient.query(CLONE_STUBS_SQL);
@@ -492,7 +491,7 @@ async function cloneRemoteToLocal(opts) {
492
491
  }, PG_PIPELINE_TIMEOUT_MS);
493
492
  });
494
493
  } catch (err) {
495
- const cleanup = new pg.Client(pgClientConfig(localMaintenanceUrl));
494
+ const cleanup = newPgClient(localMaintenanceUrl);
496
495
  try {
497
496
  await cleanup.connect();
498
497
  await cleanup.query(`DROP DATABASE IF EXISTS ${quoteName(opts.localDbName)}`);
@@ -553,7 +552,7 @@ function summariseCommand(command) {
553
552
  async function installRemoteExtensions(remoteUrl, localDbUrl, excludeSchemas) {
554
553
  const installed = [];
555
554
  if (excludeSchemas.length === 0) return { installed };
556
- const remote = new pg.Client(pgClientConfig(remoteUrl));
555
+ const remote = newPgClient(remoteUrl);
557
556
  let wanted = [];
558
557
  try {
559
558
  await remote.connect();
@@ -571,7 +570,7 @@ async function installRemoteExtensions(remoteUrl, localDbUrl, excludeSchemas) {
571
570
  } finally {
572
571
  await remote.end();
573
572
  }
574
- const local = new pg.Client(pgClientConfig(localDbUrl));
573
+ const local = newPgClient(localDbUrl);
575
574
  try {
576
575
  await local.connect();
577
576
  const { rows } = await local.query("SELECT name FROM pg_available_extensions");
@@ -639,4 +638,4 @@ export {
639
638
  isCloneDatabase,
640
639
  sourceLooksLikeCloneOf
641
640
  };
642
- //# sourceMappingURL=chunk-ORQJVE57.js.map
641
+ //# sourceMappingURL=chunk-EFKQOQGG.js.map