@akal/supaforge 0.0.33 → 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.
- package/README.md +39 -2
- package/dist/base-command.js +4 -3
- package/dist/{chunk-DMIWAJRB.js → chunk-3WKWPSFN.js} +6 -6
- package/dist/{chunk-GZREXCQZ.js → chunk-5STH2A6K.js} +17 -10
- package/dist/{chunk-6LJERPUN.js → chunk-6ERVCWLY.js} +20 -12
- package/dist/{chunk-GEHPTPNZ.js → chunk-7DL63NWP.js} +3 -3
- package/dist/{chunk-UWAVXC57.js → chunk-DQJSSTIJ.js} +39 -15
- package/dist/{chunk-ORQJVE57.js → chunk-EFKQOQGG.js} +15 -16
- package/dist/{chunk-7NAZGZPV.js → chunk-F46FFUKC.js} +16 -17
- package/dist/chunk-GQPGH6YR.js +50 -0
- package/dist/{chunk-6Q7MHFBM.js → chunk-HNJ6BNNZ.js} +2 -2
- package/dist/{chunk-MIRLB5JM.js → chunk-ICSCHS72.js} +66 -14
- package/dist/{chunk-6WAMNZLO.js → chunk-KNXHLVF7.js} +126 -4
- package/dist/{chunk-SQPCWGQO.js → chunk-MG3SFV5J.js} +22 -121
- package/dist/{chunk-BUOWHE36.js → chunk-N5VNNOA2.js} +37 -52
- package/dist/{chunk-3HGAV5CC.js → chunk-OB5GP7UB.js} +19 -16
- package/dist/{chunk-4IVN7QVY.js → chunk-PYAGSMFB.js} +23 -15
- package/dist/{chunk-SC2XHGIS.js → chunk-S5L4A3UR.js} +3 -3
- package/dist/{chunk-2SELREHW.js → chunk-TPX2MAO4.js} +7 -9
- package/dist/{chunk-NTUASFQ3.js → chunk-V2SBZERO.js} +4 -4
- package/dist/{chunk-G2DIPIYU.js → chunk-WK5YTINL.js} +29 -2
- package/dist/{chunk-BLKJWDTL.js → chunk-ZI435CAU.js} +2 -2
- package/dist/commands/clone.js +11 -11
- package/dist/commands/diff.d.ts +13 -1
- package/dist/commands/diff.js +19 -16
- package/dist/commands/hukam.js +15 -14
- package/dist/commands/init.js +5 -1
- package/dist/commands/mcp.js +15 -9
- package/dist/commands/migrate/baseline.js +5 -4
- package/dist/commands/migrate/create.js +8 -7
- package/dist/commands/migrate/list.js +6 -5
- package/dist/commands/migrate/run.js +8 -7
- package/dist/commands/report.js +5 -4
- package/dist/commands/restore.js +13 -12
- package/dist/commands/snapshot.d.ts +7 -0
- package/dist/commands/snapshot.js +36 -8
- package/dist/commands/sync.js +15 -14
- package/dist/index.js +14 -14
- package/package.json +2 -2
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 |
|
|
@@ -146,6 +163,9 @@ A snapshot records a project's structure and configuration: schema, RLS
|
|
|
146
163
|
policies, cron, webhooks, extensions, storage, auth, Edge Functions,
|
|
147
164
|
reference data, Realtime, Vault names and grants. **It is not a
|
|
148
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.
|
|
149
169
|
|
|
150
170
|
`restore --from-snapshot` puts back:
|
|
151
171
|
|
|
@@ -271,13 +291,22 @@ would push the clone's shape, absences included, onto the target.
|
|
|
271
291
|
|
|
272
292
|
## CI and exit codes
|
|
273
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
|
+
|
|
274
297
|
```yaml
|
|
275
|
-
-
|
|
298
|
+
- uses: akalsoftware/supaforge-action@v1
|
|
276
299
|
env:
|
|
277
300
|
DEV_DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}
|
|
278
301
|
PROD_DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}
|
|
279
302
|
```
|
|
280
303
|
|
|
304
|
+
Anywhere else, run the CLI:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
npx @akal/supaforge diff --ci
|
|
308
|
+
```
|
|
309
|
+
|
|
281
310
|
| Code | Meaning |
|
|
282
311
|
| --- | --- |
|
|
283
312
|
| `0` | Did what was asked, including when there was nothing to do |
|
|
@@ -299,7 +328,15 @@ drift and fix it, asking you before anything is written.
|
|
|
299
328
|
(`supaforge-<version>-<platform>.mcpb`) from the
|
|
300
329
|
[latest release](https://github.com/akalsoftware/supaforge/releases/latest)
|
|
301
330
|
and open it. It asks for your project directory.
|
|
302
|
-
- **Claude Code**:
|
|
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`
|
|
303
340
|
- **Any other client**:
|
|
304
341
|
|
|
305
342
|
```json
|
package/dist/base-command.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseCommand
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
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-
|
|
3
|
+
} from "./chunk-DQJSSTIJ.js";
|
|
4
4
|
import {
|
|
5
5
|
rolesNamedBy,
|
|
6
6
|
sqlSkeleton
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-N5VNNOA2.js";
|
|
8
8
|
import {
|
|
9
9
|
isCommentOnly,
|
|
10
10
|
splitSqlStatements
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-WK5YTINL.js";
|
|
12
12
|
import {
|
|
13
13
|
describeMissingPgDump,
|
|
14
14
|
getServerMajorVersion,
|
|
15
15
|
resolvePgDumpPath
|
|
16
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
602
|
+
//# sourceMappingURL=chunk-3WKWPSFN.js.map
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_MIGRATIONS_DIR,
|
|
3
|
-
Preflight
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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-
|
|
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
|
-
|
|
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-
|
|
214
|
+
//# sourceMappingURL=chunk-5STH2A6K.js.map
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
backup
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V2SBZERO.js";
|
|
4
4
|
import {
|
|
5
5
|
createDefaultRegistry,
|
|
6
6
|
scan
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-OB5GP7UB.js";
|
|
8
8
|
import {
|
|
9
9
|
CHECK_NAMES,
|
|
10
10
|
promote
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-DQJSSTIJ.js";
|
|
12
12
|
import {
|
|
13
|
-
captureSnapshot
|
|
14
|
-
|
|
13
|
+
captureSnapshot,
|
|
14
|
+
unrestorableSchema
|
|
15
|
+
} from "./chunk-ICSCHS72.js";
|
|
15
16
|
import {
|
|
16
|
-
checkConnection
|
|
17
|
-
|
|
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-
|
|
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({
|
|
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-
|
|
507
|
+
//# sourceMappingURL=chunk-6ERVCWLY.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHECK_META,
|
|
3
3
|
isComparisonCheck
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
240
|
+
//# sourceMappingURL=chunk-7DL63NWP.js.map
|
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
parseStatements,
|
|
11
11
|
referencedTables,
|
|
12
12
|
sqlSkeleton
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-N5VNNOA2.js";
|
|
14
14
|
import {
|
|
15
15
|
isCommentOnly,
|
|
16
16
|
splitSqlStatements
|
|
17
|
-
} from "./chunk-
|
|
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
|
-
|
|
26
|
-
pgClientConfig,
|
|
25
|
+
newPgClient,
|
|
27
26
|
pgQuery,
|
|
28
27
|
quoteName
|
|
29
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-MG3SFV5J.js";
|
|
30
29
|
import {
|
|
31
|
-
SUPABASE_PLATFORM_SCHEMAS
|
|
32
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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-
|
|
940
|
+
//# sourceMappingURL=chunk-DQJSSTIJ.js.map
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
captureSnapshot,
|
|
3
3
|
checkPgDumpCompat
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ICSCHS72.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
newPgClient,
|
|
7
7
|
pgQuery,
|
|
8
8
|
quoteName
|
|
9
|
-
} from "./chunk-
|
|
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-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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-
|
|
641
|
+
//# sourceMappingURL=chunk-EFKQOQGG.js.map
|
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadMigrations
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V2SBZERO.js";
|
|
4
4
|
import {
|
|
5
5
|
ensureMigrationsTable,
|
|
6
6
|
getAppliedVersions
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-S5L4A3UR.js";
|
|
8
8
|
import {
|
|
9
9
|
dropUnsupportedSetStatements,
|
|
10
10
|
knownParameters
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3WKWPSFN.js";
|
|
12
12
|
import {
|
|
13
13
|
ABSENT_ON_TARGET,
|
|
14
14
|
EXTENSION_UNAVAILABLE,
|
|
15
15
|
PLATFORM_ROLES
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-DQJSSTIJ.js";
|
|
17
17
|
import {
|
|
18
18
|
rolesNamedBy,
|
|
19
19
|
sqlSkeleton,
|
|
20
20
|
statementSubject
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-N5VNNOA2.js";
|
|
22
22
|
import {
|
|
23
23
|
isCommentOnly,
|
|
24
24
|
isPsqlMetaCommand,
|
|
25
25
|
splitSqlStatements,
|
|
26
26
|
stripPsqlMetaCommands
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-WK5YTINL.js";
|
|
28
28
|
import {
|
|
29
29
|
loadSnapshot
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-ICSCHS72.js";
|
|
31
31
|
import {
|
|
32
|
-
|
|
33
|
-
pgClientConfig,
|
|
32
|
+
newPgClient,
|
|
34
33
|
pgQuery,
|
|
35
34
|
quoteIdent,
|
|
36
35
|
quoteLiteral,
|
|
37
36
|
quoteName
|
|
38
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-MG3SFV5J.js";
|
|
39
38
|
import {
|
|
40
39
|
DEFAULT_IGNORE_SCHEMAS,
|
|
41
40
|
MIGRATIONS_TABLE,
|
|
42
|
-
SUPABASE_PLATFORM_SCHEMAS
|
|
43
|
-
|
|
41
|
+
SUPABASE_PLATFORM_SCHEMAS,
|
|
42
|
+
errMsg
|
|
43
|
+
} from "./chunk-KNXHLVF7.js";
|
|
44
44
|
|
|
45
45
|
// src/restore.ts
|
|
46
46
|
import { readFile as readFile2, access } from "fs/promises";
|
|
47
47
|
import { constants } from "fs";
|
|
48
48
|
import { join as join2 } from "path";
|
|
49
|
-
import pg from "pg";
|
|
50
49
|
|
|
51
50
|
// src/restore-data.ts
|
|
52
51
|
import { readdir, readFile } from "fs/promises";
|
|
@@ -357,7 +356,7 @@ async function resetRelationGrants(client, schemas) {
|
|
|
357
356
|
// src/restore.ts
|
|
358
357
|
async function getPublicTables(targetUrl) {
|
|
359
358
|
const ignoreList = DEFAULT_IGNORE_SCHEMAS.map((s) => `'${s}'`).join(", ");
|
|
360
|
-
const client =
|
|
359
|
+
const client = newPgClient(targetUrl);
|
|
361
360
|
await client.connect();
|
|
362
361
|
try {
|
|
363
362
|
const { rows } = await client.query(
|
|
@@ -376,7 +375,7 @@ async function restoreFromSnapshot(options) {
|
|
|
376
375
|
const result = { applied: [], skipped: [], errors: [], mode: "snapshot" };
|
|
377
376
|
const manifest = await loadSnapshot(options.snapshotDir);
|
|
378
377
|
const sqlOrder = RESTORE_SQL_ORDER;
|
|
379
|
-
const client =
|
|
378
|
+
const client = newPgClient(options.targetUrl);
|
|
380
379
|
await client.connect();
|
|
381
380
|
const transactional = !options.noTransaction;
|
|
382
381
|
if (transactional) await client.query("BEGIN");
|
|
@@ -571,7 +570,7 @@ async function restoreFromMigrations(options) {
|
|
|
571
570
|
if (options.toVersion) {
|
|
572
571
|
filtered = filtered.filter((m) => m.version <= options.toVersion);
|
|
573
572
|
}
|
|
574
|
-
const client =
|
|
573
|
+
const client = newPgClient(options.targetUrl);
|
|
575
574
|
await client.connect();
|
|
576
575
|
try {
|
|
577
576
|
await ensureMigrationsTable(options.targetUrl, queryFn);
|
|
@@ -865,4 +864,4 @@ export {
|
|
|
865
864
|
previewMigrationRestore,
|
|
866
865
|
summarizeStatement
|
|
867
866
|
};
|
|
868
|
-
//# sourceMappingURL=chunk-
|
|
867
|
+
//# sourceMappingURL=chunk-F46FFUKC.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describeFailure,
|
|
3
|
+
redactUrls
|
|
4
|
+
} from "./chunk-KNXHLVF7.js";
|
|
5
|
+
|
|
6
|
+
// src/process-guard.ts
|
|
7
|
+
var installed = false;
|
|
8
|
+
var jsonWritten = false;
|
|
9
|
+
var keepRunning = false;
|
|
10
|
+
function noteJsonWritten() {
|
|
11
|
+
jsonWritten = true;
|
|
12
|
+
}
|
|
13
|
+
function keepRunningOnStrayErrors() {
|
|
14
|
+
keepRunning = true;
|
|
15
|
+
}
|
|
16
|
+
function installProcessGuard(argv = process.argv) {
|
|
17
|
+
if (installed) return;
|
|
18
|
+
installed = true;
|
|
19
|
+
const onStray = (err) => {
|
|
20
|
+
const message = redactUrls(describeFailure(err));
|
|
21
|
+
if (keepRunning) {
|
|
22
|
+
process.stderr.write(`SupaForge: an error no handler caught, carrying on: ${message}
|
|
23
|
+
`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (argv.includes("--json") && !jsonWritten) {
|
|
27
|
+
jsonWritten = true;
|
|
28
|
+
process.stdout.write(JSON.stringify({ error: message }, null, 2) + "\n");
|
|
29
|
+
}
|
|
30
|
+
process.stderr.write(
|
|
31
|
+
`
|
|
32
|
+
Unexpected error: ${message}
|
|
33
|
+
If this looks like a bug, please report it:
|
|
34
|
+
https://github.com/akalsoftware/supaforge/issues/new
|
|
35
|
+
|
|
36
|
+
`
|
|
37
|
+
);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
process.stdout.write("", () => process.exit(1));
|
|
40
|
+
};
|
|
41
|
+
process.on("uncaughtException", onStray);
|
|
42
|
+
process.on("unhandledRejection", onStray);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
noteJsonWritten,
|
|
47
|
+
keepRunningOnStrayErrors,
|
|
48
|
+
installProcessGuard
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=chunk-GQPGH6YR.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
redactUrls
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KNXHLVF7.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/sanitize.ts
|
|
6
6
|
function sanitizeForReport(text) {
|
|
@@ -10,4 +10,4 @@ function sanitizeForReport(text) {
|
|
|
10
10
|
export {
|
|
11
11
|
sanitizeForReport
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-HNJ6BNNZ.js.map
|