@akal/supaforge 0.0.47 → 0.0.49
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 +54 -19
- package/dist/base-command.js +2 -2
- package/dist/{chunk-HWRRFF55.js → chunk-4EEDB7Q3.js} +4 -3
- package/dist/{chunk-YYS4FJ23.js → chunk-56U2BYRZ.js} +2 -2
- package/dist/{chunk-CUGDLO2L.js → chunk-56UP3KK3.js} +17 -10
- package/dist/{chunk-2XMRTAFX.js → chunk-EI7EP5IU.js} +8 -7
- package/dist/{chunk-KBZUTGGF.js → chunk-EJBEEWGI.js} +7 -7
- package/dist/{chunk-YQLVRHJA.js → chunk-EJMRK6LG.js} +2 -2
- package/dist/{chunk-RC7ZU7OV.js → chunk-GKYJA56H.js} +15 -2
- package/dist/{chunk-EGXQ37PA.js → chunk-JLY4IG73.js} +56 -10
- package/dist/{chunk-CRUFF6K5.js → chunk-JPZZL3KJ.js} +5 -5
- package/dist/{chunk-EB6PCOIL.js → chunk-OZW36QCK.js} +2 -2
- package/dist/{chunk-UUDXVYEI.js → chunk-P66NJJ6I.js} +6 -6
- package/dist/{chunk-TU5UIODX.js → chunk-SQHEF5NQ.js} +2 -2
- package/dist/{chunk-3SEVACCT.js → chunk-TREPSQWG.js} +3 -3
- package/dist/{chunk-WNZCOYOK.js → chunk-VCNTXXEC.js} +214 -24
- package/dist/{chunk-XTSFAUXI.js → chunk-Y6JGEFSW.js} +6 -6
- package/dist/{chunk-4TBYWXUK.js → chunk-YCJXGDVL.js} +3 -3
- package/dist/commands/clone.js +5 -5
- package/dist/commands/diff.js +9 -9
- package/dist/commands/hukam.js +9 -9
- package/dist/commands/mcp.js +8 -8
- package/dist/commands/migrate/baseline.js +3 -3
- package/dist/commands/migrate/create.js +8 -8
- package/dist/commands/migrate/list.js +3 -3
- package/dist/commands/migrate/run.js +7 -7
- package/dist/commands/report.js +2 -2
- package/dist/commands/restore.js +8 -8
- package/dist/commands/snapshot.js +5 -5
- package/dist/commands/sync.js +9 -9
- package/dist/index.d.ts +7 -1
- package/dist/index.js +13 -13
- package/package.json +23 -3
package/README.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# supaforge
|
|
2
2
|
|
|
3
|
-
> Diff and
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
> Diff, sync and clone Supabase and Postgres environments - and prove every change before it reaches production.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/akalsoftware/supaforge/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@akal/supaforge)
|
|
7
|
+
[](https://www.npmjs.com/package/@akal/supaforge)
|
|
8
|
+
[](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.akalsoftware/supaforge)
|
|
9
|
+
[](https://github.com/akalsoftware/supaforge/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
SupaForge compares two environments (dev and prod, say) across everything
|
|
12
|
+
that makes up a Supabase project, not just the schema. It reports every
|
|
13
|
+
difference, including the security gaps - an RLS policy that never reached
|
|
14
|
+
production, a bucket public on one side only - and makes the target match the
|
|
15
|
+
source. Fixes run in dependency order, in one transaction, and can be proved
|
|
16
|
+
on a throwaway copy before anything changes. With a single project, it
|
|
17
|
+
snapshots, restores and clones it. It works with Supabase Cloud, self-hosted
|
|
18
|
+
Supabase, local stacks and plain PostgreSQL.
|
|
10
19
|
|
|
11
20
|
- **The whole project.** It covers schema, RLS, storage, auth, Edge Functions,
|
|
12
21
|
cron, webhooks, Realtime, queues, partition sets, Vault, extensions, grants,
|
|
@@ -22,7 +31,8 @@ anything changes. With a single project, it snapshots, restores and clones it.
|
|
|
22
31
|
- **Anywhere.** It works with Supabase Cloud, self-hosted stacks, plain
|
|
23
32
|
PostgreSQL targets, CI pipelines and AI agents (MCP).
|
|
24
33
|
|
|
25
|
-
Built by [Akal](https://
|
|
34
|
+
Built by [Akal Software](https://akalsoftware.com). Website and guides:
|
|
35
|
+
[supaforge.dev](https://supaforge.dev).
|
|
26
36
|
|
|
27
37
|
## Quick start
|
|
28
38
|
|
|
@@ -44,9 +54,9 @@ Everything that writes previews first. Add `--apply` to make it happen.
|
|
|
44
54
|
| npm | `npm install -g @akal/supaforge`, or run it with `npx @akal/supaforge` |
|
|
45
55
|
| Homebrew | `brew install akalsoftware/tap/supaforge` |
|
|
46
56
|
| Docker | `docker run --rm -v "$PWD:/work" ghcr.io/akalsoftware/supaforge diff` |
|
|
47
|
-
| GitHub Actions | [`akalsoftware/supaforge-action`](https://github.com/akalsoftware/supaforge-action)
|
|
57
|
+
| GitHub Actions | [`akalsoftware/supaforge-action`](https://github.com/akalsoftware/supaforge-action) - see [CI](#ci-and-exit-codes) |
|
|
48
58
|
| 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` |
|
|
49
|
-
| Cursor, VS Code, Claude | One-click installs of the MCP server
|
|
59
|
+
| Cursor, VS Code, Claude | One-click installs of the MCP server - see [MCP](#mcp-ai-agents) |
|
|
50
60
|
|
|
51
61
|
It needs Node.js 22 or newer. DBDiff, its diff engine, comes with it as a
|
|
52
62
|
native binary for your platform, so there is nothing else to install. The
|
|
@@ -59,7 +69,7 @@ Docker image needs nothing at all, and carries the PostgreSQL client tools
|
|
|
59
69
|
| Check | What it reads | Fixed with |
|
|
60
70
|
| --- | --- | --- |
|
|
61
71
|
| Schema | [`@dbdiff/cli`](https://github.com/DBDiff/DBDiff): every schema you own | SQL |
|
|
62
|
-
| Reference data | Rows of the tables in `checks.data.tables
|
|
72
|
+
| Reference data | Rows of the tables in `checks.data.tables`, and the sequences behind their ids | SQL |
|
|
63
73
|
| RLS policies | `pg_policies`, compared by meaning, not text | SQL |
|
|
64
74
|
| RLS coverage | Tables in the target with RLS off (target only) | SQL, opt-in |
|
|
65
75
|
| Edge Functions | Management API, Studio, or a functions directory | Deploy command |
|
|
@@ -124,7 +134,7 @@ Useful `diff` flags:
|
|
|
124
134
|
| `--source-dir <dir>` | Compare a directory of schema files (such as `supabase/schemas`) with the target instead of a source database |
|
|
125
135
|
| `--allow-destructive` | Also apply drops and deletes |
|
|
126
136
|
| `--apply-posture` | Also apply the target-only checks' fixes |
|
|
127
|
-
| `--no-transaction` | Apply fix by fix, keeping what works |
|
|
137
|
+
| `--no-transaction` | Apply fix by fix, keeping what works. Synced rows then fire the target's triggers |
|
|
128
138
|
| `--no-snapshot` | Read each query on its own. By default each database is read as of one instant, so a change made while the scan runs is seen by all of it or none; as with `pg_dump`, what it reads stays locked until the scan ends |
|
|
129
139
|
| `--json` / `--ci` | Machine-readable output; CI annotations and exit codes |
|
|
130
140
|
|
|
@@ -136,13 +146,36 @@ Useful `diff` flags:
|
|
|
136
146
|
column, deleting or truncating rows, and removing an RLS policy are reported
|
|
137
147
|
but skipped until you add `--allow-destructive`. `migrate run` uses the same
|
|
138
148
|
gate.
|
|
149
|
+
- **Roles and grants.** What the target grants a role the source doesn't have
|
|
150
|
+
is left alone, since the source says nothing about it. Syncing plain
|
|
151
|
+
PostgreSQL into a Supabase project keeps the Data API roles' access.
|
|
152
|
+
Grants to `anon`, `authenticated` or `service_role` are skipped on a target
|
|
153
|
+
without them. Roles belong to the whole server, not one database, so a role
|
|
154
|
+
only the target has is dropped only with `--allow-destructive`, and one
|
|
155
|
+
that can log in is never dropped for you.
|
|
139
156
|
- **Dependency order.** Fixes run in dependency order: functions before the
|
|
140
157
|
triggers that call them, columns before their indexes, drops last. A changed
|
|
141
158
|
object that has to be dropped and recreated is a single fix.
|
|
142
159
|
- **One transaction.** If a fix fails, the whole set rolls back and the target
|
|
143
|
-
is unchanged.
|
|
144
|
-
|
|
145
|
-
|
|
160
|
+
is unchanged. An extension the server doesn't ship, such as Supabase's own
|
|
161
|
+
on plain PostgreSQL, is skipped with the reason, and the rest still
|
|
162
|
+
applies. So is a fix that needs something the target lacks, such as that
|
|
163
|
+
extension or a Supabase schema, but that one counts as a failure, since
|
|
164
|
+
something of yours didn't arrive.
|
|
165
|
+
- **Rows into a live target.** Reference rows are written the way pg_dump's
|
|
166
|
+
`--disable-triggers` and logical replication write them: the target's own
|
|
167
|
+
triggers on those tables are held off while their rows are synced and put
|
|
168
|
+
back before commit, so an `updated_at` or audit trigger doesn't rewrite
|
|
169
|
+
what was copied, and a webhook doesn't fire once per row. A trigger set
|
|
170
|
+
`ENABLE ALWAYS` still fires. A row that needs one written after it in the
|
|
171
|
+
same table, such as a node moved under a newer one, is checked against the
|
|
172
|
+
table's foreign key at the end instead, and an orphan still rolls
|
|
173
|
+
everything back. Both need the connecting role to own the table; when it
|
|
174
|
+
doesn't, the triggers fire and the run says so.
|
|
175
|
+
- **Sequences follow the rows.** After syncing rows, each serial or identity
|
|
176
|
+
sequence on those tables is moved past the largest id, so the app's next
|
|
177
|
+
insert doesn't collide with a synced row. A sequence is only ever moved
|
|
178
|
+
forward, and one left behind by an earlier sync is reported too.
|
|
146
179
|
- **`--prove`.** The fixes are replayed on a copy of the target's structure,
|
|
147
180
|
made on the target's own server, the way the apply will run them, with a
|
|
148
181
|
sample of each table's rows. Nothing is applied unless the result matches
|
|
@@ -179,6 +212,8 @@ A snapshot records a project's structure and configuration: schema, RLS
|
|
|
179
212
|
policies, cron, webhooks, extensions, storage, auth, Edge Functions,
|
|
180
213
|
reference data, Realtime, Vault names and grants. **It is not a
|
|
181
214
|
backup.** It holds no rows beyond `checks.data.tables`, and no stored files.
|
|
215
|
+
Those rows are written in one fixed text format, so they restore exactly into
|
|
216
|
+
a server whose date, time zone or number settings differ from the source's.
|
|
182
217
|
Its schema is written as SQL by `pg_dump`, which has to be at least as new as
|
|
183
218
|
the server; without one the snapshot can still be diffed but not restored, and
|
|
184
219
|
`snapshot` exits 1 unless `--allow-schema-json-only` says that is enough.
|
|
@@ -279,7 +314,7 @@ supaforge migrate run --env=prod --apply
|
|
|
279
314
|
| `SUPAFORGE_CONNECT_TIMEOUT` | `15` | Seconds to wait for a connection |
|
|
280
315
|
| `SUPAFORGE_CHECK_CONCURRENCY` | `4` | Checks run at once. Lower it behind a tight pooler |
|
|
281
316
|
| `SUPAFORGE_PROVE_ROWS` | `1000` | Rows of each table `--prove` copies to check they survive; `0` checks structure only |
|
|
282
|
-
| `SUPAFORGE_PG_BIN` | — | A directory of PostgreSQL client tools (`pg_dump`, `psql`), used ahead of `PATH
|
|
317
|
+
| `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` |
|
|
283
318
|
|
|
284
319
|
## Self-hosted Supabase
|
|
285
320
|
|
|
@@ -298,11 +333,11 @@ checks run.
|
|
|
298
333
|
## Diffing a clone
|
|
299
334
|
|
|
300
335
|
A local clone is plain PostgreSQL. Storage, auth, Edge Functions, Vault,
|
|
301
|
-
Realtime and Supabase's roles have
|
|
302
|
-
checks:
|
|
336
|
+
Realtime, webhooks (which need Supabase's `pg_net`) and Supabase's roles have
|
|
337
|
+
nothing to compare there, so skip those checks:
|
|
303
338
|
|
|
304
339
|
```json
|
|
305
|
-
{ "checks": { "exclude": ["storage", "auth", "edge-functions", "vault", "realtime", "roles"] } }
|
|
340
|
+
{ "checks": { "exclude": ["storage", "auth", "edge-functions", "vault", "realtime", "webhooks", "roles"] } }
|
|
306
341
|
```
|
|
307
342
|
|
|
308
343
|
When the source is a clone and the target isn't, `diff` warns that `--apply`
|
package/dist/base-command.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pgQuery,
|
|
3
|
+
pgQueryAsWritten,
|
|
3
4
|
readLocalMigrations
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-GKYJA56H.js";
|
|
5
6
|
import {
|
|
6
7
|
MIGRATIONS_SCHEMA,
|
|
7
8
|
MIGRATIONS_TABLE
|
|
@@ -55,7 +56,7 @@ async function getPendingMigrations(dir, applied, readDirFn) {
|
|
|
55
56
|
return local.filter((m) => !applied.has(m.version)).map((m) => ({ ...m, path: join(dir, m.filename) }));
|
|
56
57
|
}
|
|
57
58
|
var defaultReadFile = (path) => readFile(path, "utf8");
|
|
58
|
-
async function runMigration(dbUrl, migration, queryFn =
|
|
59
|
+
async function runMigration(dbUrl, migration, queryFn = pgQueryAsWritten, readFileFn = defaultReadFile) {
|
|
59
60
|
const sql = await readFileFn(migration.path);
|
|
60
61
|
const start = performance.now();
|
|
61
62
|
await queryFn(dbUrl, sql);
|
|
@@ -119,4 +120,4 @@ export {
|
|
|
119
120
|
runMigration,
|
|
120
121
|
baselineMigrations
|
|
121
122
|
};
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-4EEDB7Q3.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
newPgClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GKYJA56H.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/sql-split.ts
|
|
6
6
|
var ROUTINE_HEAD = /^CREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE)\b/i;
|
|
@@ -393,4 +393,4 @@ export {
|
|
|
393
393
|
checkPgDumpCompat,
|
|
394
394
|
pgToolConnection
|
|
395
395
|
};
|
|
396
|
-
//# sourceMappingURL=chunk-
|
|
396
|
+
//# sourceMappingURL=chunk-56U2BYRZ.js.map
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
formatSkips,
|
|
7
7
|
renderDetailed,
|
|
8
8
|
renderSummary
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-OZW36QCK.js";
|
|
10
10
|
import {
|
|
11
11
|
createDefaultRegistry,
|
|
12
12
|
proveBeforeApply,
|
|
13
13
|
scan,
|
|
14
14
|
summarizeByKind
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-JLY4IG73.js";
|
|
16
16
|
import {
|
|
17
17
|
CHECK_META,
|
|
18
18
|
CHECK_NAMES,
|
|
@@ -24,17 +24,17 @@ import {
|
|
|
24
24
|
psqlBeside,
|
|
25
25
|
resolveTableFilter,
|
|
26
26
|
withDatabase
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-VCNTXXEC.js";
|
|
28
28
|
import {
|
|
29
29
|
renderTip
|
|
30
30
|
} from "./chunk-RQCXGO37.js";
|
|
31
31
|
import {
|
|
32
32
|
BaseCommand
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-SQHEF5NQ.js";
|
|
34
34
|
import {
|
|
35
35
|
isCloneDatabase,
|
|
36
36
|
sourceLooksLikeCloneOf
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-EI7EP5IU.js";
|
|
38
38
|
import {
|
|
39
39
|
describeMissingPgDump,
|
|
40
40
|
getServerMajorVersion,
|
|
@@ -42,12 +42,13 @@ import {
|
|
|
42
42
|
parseFlagList,
|
|
43
43
|
resolvePgDumpPath,
|
|
44
44
|
splitSqlStatements
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-56U2BYRZ.js";
|
|
46
46
|
import {
|
|
47
47
|
Preflight,
|
|
48
48
|
pgQuery,
|
|
49
|
+
pgQueryAsWritten,
|
|
49
50
|
quoteName
|
|
50
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-GKYJA56H.js";
|
|
51
52
|
import {
|
|
52
53
|
CLONE_SKIP_FLAGS,
|
|
53
54
|
DEFAULT_IGNORE_SCHEMAS,
|
|
@@ -188,7 +189,7 @@ async function loadStatements(url, files) {
|
|
|
188
189
|
const failed = [];
|
|
189
190
|
for (const p of pending) {
|
|
190
191
|
try {
|
|
191
|
-
await
|
|
192
|
+
await pgQueryAsWritten(url, p.sql);
|
|
192
193
|
} catch (err) {
|
|
193
194
|
failed.push({ ...p, error: errMsg(err) });
|
|
194
195
|
}
|
|
@@ -218,6 +219,7 @@ async function unavailableExtensions(targetUrl, copyUrl) {
|
|
|
218
219
|
|
|
219
220
|
// src/commands/diff.ts
|
|
220
221
|
var SCHEMA_FILES_ENV = "schema files";
|
|
222
|
+
var ROLLED_BACK_SHOWN = 20;
|
|
221
223
|
var SCHEMA_FILE_CHECKS = ["schema", "rls", "extensions"];
|
|
222
224
|
function describeCheckOutcome(status, issueCount, skipReason) {
|
|
223
225
|
if (status === "error") return { glyph: warn("\u2717"), text: warn("error") };
|
|
@@ -376,6 +378,8 @@ var Diff = class _Diff extends BaseCommand {
|
|
|
376
378
|
const verb = dryRun ? "Would apply" : "Applied";
|
|
377
379
|
for (const warning of result.warnings ?? []) this.log(`${warn(warning)}
|
|
378
380
|
`);
|
|
381
|
+
for (const note of result.notes ?? []) this.log(`${dim(note)}`);
|
|
382
|
+
if (result.notes?.length) this.log("");
|
|
379
383
|
if (result.applied.length > 0) {
|
|
380
384
|
const heading = `${verb} ${result.applied.length} fix(es)${dryRun ? ", in this order" : ""}:`;
|
|
381
385
|
this.log(dryRun ? bold(heading) : ok(heading));
|
|
@@ -394,9 +398,12 @@ ${dim(`Skipped ${result.skipped.length} issue(s):`)}`);
|
|
|
394
398
|
if (result.rolledBack?.length) {
|
|
395
399
|
this.log(`
|
|
396
400
|
${warn(`Rolled back ${result.rolledBack.length} fix(es)`)} \u2014 the target is unchanged:`);
|
|
397
|
-
for (const item of result.rolledBack) {
|
|
401
|
+
for (const item of result.rolledBack.slice(0, ROLLED_BACK_SHOWN)) {
|
|
398
402
|
this.log(` ${dim("\u21A9")} ${dim(`[${item.check}]`)} ${item.issueId}`);
|
|
399
403
|
}
|
|
404
|
+
if (result.rolledBack.length > ROLLED_BACK_SHOWN) {
|
|
405
|
+
this.log(` ${dim(`\u21A9 \u2026 and ${result.rolledBack.length - ROLLED_BACK_SHOWN} more (all of them under --json)`)}`);
|
|
406
|
+
}
|
|
400
407
|
}
|
|
401
408
|
if (result.errors.length > 0) {
|
|
402
409
|
this.log(`
|
|
@@ -754,4 +761,4 @@ export {
|
|
|
754
761
|
inertApplyFlags,
|
|
755
762
|
Diff
|
|
756
763
|
};
|
|
757
|
-
//# sourceMappingURL=chunk-
|
|
764
|
+
//# sourceMappingURL=chunk-56UP3KK3.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
captureSnapshot
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TREPSQWG.js";
|
|
4
4
|
import {
|
|
5
5
|
checkPgDumpCompat,
|
|
6
6
|
pgToolConnection,
|
|
7
7
|
splitSqlStatements
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-56U2BYRZ.js";
|
|
9
9
|
import {
|
|
10
10
|
newPgClient,
|
|
11
11
|
pgQuery,
|
|
12
12
|
quoteName
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-GKYJA56H.js";
|
|
14
14
|
import {
|
|
15
15
|
BRANCHES_FILE,
|
|
16
16
|
CLONE_PROGRESS_INTERVAL_MS,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
|
|
21
21
|
// src/branch.ts
|
|
22
22
|
import { spawn } from "child_process";
|
|
23
|
-
import { readFile, writeFile as writeFile2, mkdir } from "fs/promises";
|
|
23
|
+
import { readFile, writeFile as writeFile2, mkdir, chmod } from "fs/promises";
|
|
24
24
|
import { resolve, dirname } from "path";
|
|
25
25
|
|
|
26
26
|
// src/stubs.ts
|
|
@@ -210,8 +210,9 @@ async function loadManifest(cwd = process.cwd()) {
|
|
|
210
210
|
}
|
|
211
211
|
async function saveManifest(manifest, cwd) {
|
|
212
212
|
const p = await manifestPath(cwd);
|
|
213
|
-
await mkdir(dirname(p), { recursive: true });
|
|
214
|
-
await writeFile2(p, JSON.stringify(manifest, null, 2) + "\n");
|
|
213
|
+
await mkdir(dirname(p), { recursive: true, mode: 448 });
|
|
214
|
+
await writeFile2(p, JSON.stringify(manifest, null, 2) + "\n", { mode: 384 });
|
|
215
|
+
await chmod(p, 384);
|
|
215
216
|
}
|
|
216
217
|
async function createBranch(opts) {
|
|
217
218
|
const cwd = opts.cwd ?? process.cwd();
|
|
@@ -744,4 +745,4 @@ export {
|
|
|
744
745
|
isCloneDatabase,
|
|
745
746
|
sourceLooksLikeCloneOf
|
|
746
747
|
};
|
|
747
|
-
//# sourceMappingURL=chunk-
|
|
748
|
+
//# sourceMappingURL=chunk-EI7EP5IU.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadMigrations
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YCJXGDVL.js";
|
|
4
4
|
import {
|
|
5
5
|
ensureMigrationsTable,
|
|
6
6
|
getAppliedVersions
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4EEDB7Q3.js";
|
|
8
8
|
import {
|
|
9
9
|
ABSENT_ON_TARGET,
|
|
10
10
|
EXTENSION_UNAVAILABLE,
|
|
@@ -18,23 +18,23 @@ import {
|
|
|
18
18
|
rolesNamedBy,
|
|
19
19
|
sqlSkeleton,
|
|
20
20
|
statementSubject
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-VCNTXXEC.js";
|
|
22
22
|
import {
|
|
23
23
|
loadSnapshot
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-TREPSQWG.js";
|
|
25
25
|
import {
|
|
26
26
|
isCommentOnly,
|
|
27
27
|
isPsqlMetaCommand,
|
|
28
28
|
splitSqlStatements,
|
|
29
29
|
stripPsqlMetaCommands
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-56U2BYRZ.js";
|
|
31
31
|
import {
|
|
32
32
|
newPgClient,
|
|
33
33
|
pgQuery,
|
|
34
34
|
quoteIdent,
|
|
35
35
|
quoteLiteral,
|
|
36
36
|
quoteName
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-GKYJA56H.js";
|
|
38
38
|
import {
|
|
39
39
|
DEFAULT_IGNORE_SCHEMAS,
|
|
40
40
|
MIGRATIONS_TABLE,
|
|
@@ -900,4 +900,4 @@ export {
|
|
|
900
900
|
previewMigrationRestore,
|
|
901
901
|
summarizeStatement
|
|
902
902
|
};
|
|
903
|
-
//# sourceMappingURL=chunk-
|
|
903
|
+
//# sourceMappingURL=chunk-EJBEEWGI.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
comparedSchemas,
|
|
3
3
|
fingerprint
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VCNTXXEC.js";
|
|
5
5
|
|
|
6
6
|
// src/written-against.ts
|
|
7
7
|
import { createHash } from "crypto";
|
|
@@ -24,4 +24,4 @@ export {
|
|
|
24
24
|
writtenAgainstLine,
|
|
25
25
|
writtenAgainst
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-EJMRK6LG.js.map
|
|
@@ -39,11 +39,13 @@ function newPgClient(dbUrl, queryTimeoutMs) {
|
|
|
39
39
|
client.on("error", () => void 0);
|
|
40
40
|
return client;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
var PINNED_OUTPUT = "SET extra_float_digits = 3; SET bytea_output = hex; SET DateStyle = 'ISO, MDY'; SET IntervalStyle = postgres; SET TimeZone = 'UTC'";
|
|
43
|
+
function newPgPool(config, pinned = true) {
|
|
43
44
|
const pool = new pg.Pool(config);
|
|
44
45
|
pool.on("error", () => void 0);
|
|
45
46
|
pool.on("connect", (client) => {
|
|
46
47
|
client.on("error", () => void 0);
|
|
48
|
+
if (pinned) client.query(PINNED_OUTPUT).catch(() => void 0);
|
|
47
49
|
});
|
|
48
50
|
return pool;
|
|
49
51
|
}
|
|
@@ -142,6 +144,16 @@ async function inRolledBackTransaction(dbUrl, fn) {
|
|
|
142
144
|
client.release();
|
|
143
145
|
}
|
|
144
146
|
}
|
|
147
|
+
var asWritten = /* @__PURE__ */ new Map();
|
|
148
|
+
var pgQueryAsWritten = async (dbUrl, sql, params) => {
|
|
149
|
+
let pool = asWritten.get(dbUrl);
|
|
150
|
+
if (!pool) {
|
|
151
|
+
pool = newPgPool({ ...pgClientConfig(dbUrl), max: POOL_MAX, allowExitOnIdle: true }, false);
|
|
152
|
+
asWritten.set(dbUrl, pool);
|
|
153
|
+
}
|
|
154
|
+
const { rows } = await pool.query(sql, params);
|
|
155
|
+
return rows;
|
|
156
|
+
};
|
|
145
157
|
|
|
146
158
|
// src/local-pg.ts
|
|
147
159
|
import { execFile } from "child_process";
|
|
@@ -609,6 +621,7 @@ export {
|
|
|
609
621
|
releaseSnapshots,
|
|
610
622
|
pgQuery,
|
|
611
623
|
inRolledBackTransaction,
|
|
624
|
+
pgQueryAsWritten,
|
|
612
625
|
DEFAULT_LOCAL_PORT,
|
|
613
626
|
LOCAL_PG_USER,
|
|
614
627
|
LOCAL_PG_PASSWORD,
|
|
@@ -627,4 +640,4 @@ export {
|
|
|
627
640
|
MigrationsCheck,
|
|
628
641
|
readLocalMigrations
|
|
629
642
|
};
|
|
630
|
-
//# sourceMappingURL=chunk-
|
|
643
|
+
//# sourceMappingURL=chunk-GKYJA56H.js.map
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
RolesCheck,
|
|
5
5
|
applyTableFilter,
|
|
6
6
|
comparedSchemas,
|
|
7
|
+
dataScope,
|
|
7
8
|
destructiveReason,
|
|
8
9
|
isComparisonCheck,
|
|
9
10
|
parseStatements,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
sqlToIssues,
|
|
22
23
|
withPlatformExtensionCalls,
|
|
23
24
|
withoutAbsentRoles
|
|
24
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-VCNTXXEC.js";
|
|
25
26
|
import {
|
|
26
27
|
RealtimeCheck,
|
|
27
28
|
createPolicySql,
|
|
@@ -33,10 +34,10 @@ import {
|
|
|
33
34
|
readJsonArray,
|
|
34
35
|
readJsonObject,
|
|
35
36
|
schemaPolicySql
|
|
36
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-TREPSQWG.js";
|
|
37
38
|
import {
|
|
38
39
|
splitSqlStatements
|
|
39
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-56U2BYRZ.js";
|
|
40
41
|
import {
|
|
41
42
|
Check,
|
|
42
43
|
CheckSkipped,
|
|
@@ -51,7 +52,7 @@ import {
|
|
|
51
52
|
releaseSnapshots,
|
|
52
53
|
setSnapshotsOff,
|
|
53
54
|
sqlLiteral
|
|
54
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-GKYJA56H.js";
|
|
55
56
|
import {
|
|
56
57
|
DEFAULT_IGNORE_SCHEMAS,
|
|
57
58
|
SCORE_MAX,
|
|
@@ -1850,7 +1851,7 @@ async function getTableFingerprint(dbUrl, table2, queryFn = pgQuery) {
|
|
|
1850
1851
|
coalesce(sum(('x' || substr(d, 1, 16))::bit(64)::bigint::numeric), 0)::text
|
|
1851
1852
|
|| ':' ||
|
|
1852
1853
|
coalesce(sum(('x' || substr(d, 17, 16))::bit(64)::bigint::numeric), 0)::text AS content
|
|
1853
|
-
FROM (SELECT md5(t::text) AS d FROM ${quoteIdent(table2)} t) s
|
|
1854
|
+
FROM (SELECT md5(ROW(t.*)::text) AS d FROM ${quoteIdent(table2)} t) s
|
|
1854
1855
|
`;
|
|
1855
1856
|
const [row] = await queryFn(dbUrl, sql);
|
|
1856
1857
|
return {
|
|
@@ -1889,6 +1890,50 @@ async function filterChangedTables(sourceUrl, targetUrl, tables, queryFn = pgQue
|
|
|
1889
1890
|
return { changed, skipped };
|
|
1890
1891
|
}
|
|
1891
1892
|
|
|
1893
|
+
// src/checks/data-sequences.ts
|
|
1894
|
+
var OWNED = (table2) => `pg_depend d
|
|
1895
|
+
JOIN pg_sequence q ON q.seqrelid = d.objid
|
|
1896
|
+
JOIN pg_attribute a ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid AND NOT a.attisdropped
|
|
1897
|
+
WHERE d.classid = 'pg_class'::regclass AND d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i')
|
|
1898
|
+
AND d.refobjid = to_regclass(${table2})`;
|
|
1899
|
+
var SOURCE_SQL = (table2) => `SELECT a.attname AS col FROM ${OWNED(quoteLiteral(quoteIdent(table2)))} ORDER BY a.attnum`;
|
|
1900
|
+
var TARGET_SQL = `
|
|
1901
|
+
SELECT q.seqincrement > 0 AS ascending,
|
|
1902
|
+
(coalesce(pg_sequence_last_value(q.seqrelid) + q.seqincrement, q.seqstart))::text AS next
|
|
1903
|
+
FROM ${OWNED("$1")} AND a.attname = $2`;
|
|
1904
|
+
function sequenceFixSql(table2, col) {
|
|
1905
|
+
return `SELECT setval(q.seqrelid, top) FROM (SELECT max(${quoteName(col)}) AS top FROM ${quoteIdent(table2)}) x, ${OWNED(quoteLiteral(quoteIdent(table2))).replace(/\s+/g, " ")} AND a.attname = ${quoteLiteral(col)} AND top IS NOT NULL AND q.seqincrement > 0 AND top >= coalesce(pg_sequence_last_value(q.seqrelid) + q.seqincrement, q.seqstart);`;
|
|
1906
|
+
}
|
|
1907
|
+
async function sequenceIssues(sourceUrl, targetUrl, tables, queryFn) {
|
|
1908
|
+
const issues = [];
|
|
1909
|
+
for (const table2 of tables) {
|
|
1910
|
+
const columns = await queryFn(sourceUrl, SOURCE_SQL(table2));
|
|
1911
|
+
const behind = [];
|
|
1912
|
+
const fixes = [];
|
|
1913
|
+
for (const column of columns) {
|
|
1914
|
+
const [{ max }] = await queryFn(
|
|
1915
|
+
sourceUrl,
|
|
1916
|
+
`SELECT max(${quoteName(column.col)})::text AS max FROM ${quoteIdent(table2)}`
|
|
1917
|
+
);
|
|
1918
|
+
if (max === null) continue;
|
|
1919
|
+
const [target] = await queryFn(targetUrl, TARGET_SQL, [quoteIdent(table2), column.col]);
|
|
1920
|
+
if (target && (!target.ascending || BigInt(target.next) > BigInt(max))) continue;
|
|
1921
|
+
behind.push(target ? `${column.col} (next ${target.next}, rows up to ${max})` : `${column.col} (rows up to ${max}, on a sequence the sync creates)`);
|
|
1922
|
+
fixes.push(sequenceFixSql(table2, column.col));
|
|
1923
|
+
}
|
|
1924
|
+
if (fixes.length === 0) continue;
|
|
1925
|
+
issues.push({
|
|
1926
|
+
id: `data-sequence-${table2}`,
|
|
1927
|
+
check: "data",
|
|
1928
|
+
severity: "warning",
|
|
1929
|
+
title: `Sequence behind the rows in ${table2}`,
|
|
1930
|
+
description: `The ids synced into ${table2} reach past what its sequence would hand out next: ${behind.join(", ")}. The next insert would fail with a duplicate key, so the sequence is moved past them after the rows are written.`,
|
|
1931
|
+
sql: { up: fixes.join("\n"), down: "" }
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
return issues;
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1892
1937
|
// src/checks/data.ts
|
|
1893
1938
|
var DataCheck = class extends Check {
|
|
1894
1939
|
constructor(runFn = runDbDiff, queryFn = pgQuery) {
|
|
@@ -1912,20 +1957,21 @@ var DataCheck = class extends Check {
|
|
|
1912
1957
|
tables,
|
|
1913
1958
|
this.queryFn
|
|
1914
1959
|
);
|
|
1915
|
-
|
|
1960
|
+
const sequences = await sequenceIssues(ctx.source.dbUrl, ctx.target.dbUrl, tables, this.queryFn);
|
|
1961
|
+
if (changed.length === 0) return sequences;
|
|
1916
1962
|
try {
|
|
1917
1963
|
const result = await this.runFn({
|
|
1918
1964
|
sourceUrl: ctx.source.dbUrl,
|
|
1919
1965
|
targetUrl: ctx.target.dbUrl,
|
|
1920
1966
|
type: "data",
|
|
1921
1967
|
include: "both",
|
|
1922
|
-
|
|
1968
|
+
...dataScope(changed, ctx.config.ignoreSchemas ?? DEFAULT_IGNORE_SCHEMAS),
|
|
1923
1969
|
timeoutSeconds: ctx.target?.checks?.schema?.timeout
|
|
1924
1970
|
});
|
|
1925
|
-
return sqlToIssues(result, "data");
|
|
1971
|
+
return [...sqlToIssues(result, "data"), ...sequences];
|
|
1926
1972
|
} catch (err) {
|
|
1927
1973
|
if (err instanceof Error && err.message.includes("@dbdiff/cli is not installed")) {
|
|
1928
|
-
return
|
|
1974
|
+
return sequences;
|
|
1929
1975
|
}
|
|
1930
1976
|
throw err;
|
|
1931
1977
|
}
|
|
@@ -2467,4 +2513,4 @@ export {
|
|
|
2467
2513
|
createDefaultRegistry,
|
|
2468
2514
|
proveBeforeApply
|
|
2469
2515
|
};
|
|
2470
|
-
//# sourceMappingURL=chunk-
|
|
2516
|
+
//# sourceMappingURL=chunk-JLY4IG73.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
targetFingerprint,
|
|
3
3
|
writtenAgainstLine
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-EJMRK6LG.js";
|
|
5
5
|
import {
|
|
6
6
|
RolesCheck,
|
|
7
7
|
isDestructiveSql,
|
|
8
8
|
runDbDiff
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VCNTXXEC.js";
|
|
10
10
|
import {
|
|
11
11
|
slugify,
|
|
12
12
|
splitSqlStatements
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-56U2BYRZ.js";
|
|
14
14
|
import {
|
|
15
15
|
DEFAULT_MIGRATIONS_DIR,
|
|
16
16
|
pgQuery
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-GKYJA56H.js";
|
|
18
18
|
import {
|
|
19
19
|
DEFAULT_IGNORE_SCHEMAS
|
|
20
20
|
} from "./chunk-SQ52YBKK.js";
|
|
@@ -89,4 +89,4 @@ export {
|
|
|
89
89
|
writeMigrationFile,
|
|
90
90
|
generateTimestamp
|
|
91
91
|
};
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-JPZZL3KJ.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHECK_META,
|
|
3
3
|
isComparisonCheck
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VCNTXXEC.js";
|
|
5
5
|
import {
|
|
6
6
|
CHECK_LINE_PADDING,
|
|
7
7
|
bold,
|
|
@@ -241,4 +241,4 @@ export {
|
|
|
241
241
|
renderDetailed,
|
|
242
242
|
formatSkips
|
|
243
243
|
};
|
|
244
|
-
//# sourceMappingURL=chunk-
|
|
244
|
+
//# sourceMappingURL=chunk-OZW36QCK.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
targetFingerprint,
|
|
3
3
|
writtenAgainst
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-EJMRK6LG.js";
|
|
5
5
|
import {
|
|
6
6
|
ensureMigrationsTable,
|
|
7
7
|
getAppliedVersions,
|
|
8
8
|
getPendingMigrations,
|
|
9
9
|
runMigration
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4EEDB7Q3.js";
|
|
11
11
|
import {
|
|
12
12
|
isDestructiveSql
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-VCNTXXEC.js";
|
|
14
14
|
import {
|
|
15
15
|
BaseCommand
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-SQHEF5NQ.js";
|
|
17
17
|
import {
|
|
18
18
|
splitSqlStatements
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-56U2BYRZ.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-
|
|
183
|
+
//# sourceMappingURL=chunk-P66NJJ6I.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_MIGRATIONS_DIR,
|
|
3
3
|
Preflight
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GKYJA56H.js";
|
|
5
5
|
import {
|
|
6
6
|
installProcessGuard,
|
|
7
7
|
noteJsonWritten
|
|
@@ -213,4 +213,4 @@ export {
|
|
|
213
213
|
readRunLog,
|
|
214
214
|
BaseCommand
|
|
215
215
|
};
|
|
216
|
-
//# sourceMappingURL=chunk-
|
|
216
|
+
//# sourceMappingURL=chunk-SQHEF5NQ.js.map
|