@akal/supaforge 0.0.34 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -13
- package/dist/base-command.d.ts +1 -1
- package/dist/base-command.js +4 -4
- package/dist/{branch-C4ndfoj5.d.ts → branch-BppjQBv_.d.ts} +1 -1
- package/dist/{chunk-ICSCHS72.js → chunk-5UHIWFQG.js} +76 -186
- package/dist/{chunk-S5L4A3UR.js → chunk-AL6INEFX.js} +3 -3
- package/dist/{chunk-OB5GP7UB.js → chunk-CAQ3QQFP.js} +437 -45
- package/dist/{chunk-TPX2MAO4.js → chunk-CCB7ARZU.js} +54 -5
- package/dist/{chunk-V2SBZERO.js → chunk-EWNZIRCD.js} +4 -4
- package/dist/{chunk-EFKQOQGG.js → chunk-FD2JKEJA.js} +7 -5
- package/dist/{chunk-3WKWPSFN.js → chunk-GGZ7YWBZ.js} +191 -32
- package/dist/{chunk-F46FFUKC.js → chunk-JX5L253P.js} +56 -18
- package/dist/{chunk-GQPGH6YR.js → chunk-KHXEES2M.js} +2 -2
- package/dist/{chunk-MG3SFV5J.js → chunk-KT7NMELZ.js} +77 -7
- package/dist/{chunk-PYAGSMFB.js → chunk-M2564IGT.js} +159 -19
- package/dist/{chunk-7DL63NWP.js → chunk-MRXIE55Y.js} +7 -3
- package/dist/{chunk-6ERVCWLY.js → chunk-MZPWRWBL.js} +7 -7
- package/dist/{chunk-5STH2A6K.js → chunk-OXS42LJH.js} +4 -4
- package/dist/{chunk-HNJ6BNNZ.js → chunk-Q43MN6NE.js} +2 -2
- package/dist/{chunk-ZI435CAU.js → chunk-RQCXGO37.js} +2 -2
- package/dist/{chunk-KNXHLVF7.js → chunk-SQ52YBKK.js} +3 -2
- package/dist/{chunk-N5VNNOA2.js → chunk-YUJ2MHLM.js} +1236 -22
- package/dist/chunk-Z2YUOA4W.js +242 -0
- package/dist/commands/clone.d.ts +2 -2
- package/dist/commands/clone.js +10 -9
- package/dist/commands/diff.d.ts +25 -22
- package/dist/commands/diff.js +14 -15
- package/dist/commands/hukam.d.ts +2 -3
- package/dist/commands/hukam.js +14 -15
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/mcp.js +9 -10
- package/dist/commands/migrate/baseline.d.ts +1 -1
- package/dist/commands/migrate/baseline.js +5 -5
- package/dist/commands/migrate/create.d.ts +1 -1
- package/dist/commands/migrate/create.js +27 -13
- package/dist/commands/migrate/list.d.ts +1 -1
- package/dist/commands/migrate/list.js +5 -5
- package/dist/commands/migrate/run.d.ts +4 -1
- package/dist/commands/migrate/run.js +9 -8
- package/dist/commands/report.d.ts +1 -1
- package/dist/commands/report.js +5 -5
- package/dist/commands/restore.d.ts +1 -1
- package/dist/commands/restore.js +14 -13
- package/dist/commands/snapshot.d.ts +1 -1
- package/dist/commands/snapshot.js +8 -8
- package/dist/commands/sync.d.ts +2 -3
- package/dist/commands/sync.js +14 -15
- package/dist/{config-CTbeRlJk.d.ts → config-l3ggjw9r.d.ts} +2 -0
- package/dist/index.d.ts +38 -4
- package/dist/index.js +13 -14
- package/package.json +2 -2
- package/dist/chunk-DQJSSTIJ.js +0 -940
- package/dist/chunk-DQQ5E563.js +0 -64
package/README.md
CHANGED
|
@@ -9,13 +9,16 @@ order, in one transaction, and can be proved on a throwaway copy before
|
|
|
9
9
|
anything changes. With a single project, it snapshots, restores and clones it.
|
|
10
10
|
|
|
11
11
|
- **The whole project.** It covers schema, RLS, storage, auth, Edge Functions,
|
|
12
|
-
cron, webhooks, Realtime, Vault, extensions, grants,
|
|
13
|
-
migration history.
|
|
12
|
+
cron, webhooks, Realtime, queues, partition sets, Vault, extensions, grants,
|
|
13
|
+
reference data and migration history.
|
|
14
14
|
- **Safe by default.** Every write needs `--apply`, and anything that loses
|
|
15
15
|
data or opens up access also needs `--allow-destructive`. A failed apply
|
|
16
16
|
leaves the target exactly as it was.
|
|
17
|
+
- **Production-aware.** Each fix says what it does to a live database: the
|
|
18
|
+
lock it holds and on which table, whether it may rewrite the table or scan
|
|
19
|
+
every row, whether it can't run in a transaction.
|
|
17
20
|
- **Provable.** `--prove` rehearses the migration and refuses to apply one
|
|
18
|
-
that wouldn't reproduce the source.
|
|
21
|
+
that wouldn't reproduce the source or would lose rows.
|
|
19
22
|
- **Anywhere.** It works with Supabase Cloud, self-hosted stacks, plain
|
|
20
23
|
PostgreSQL targets, CI pipelines and AI agents (MCP).
|
|
21
24
|
|
|
@@ -63,6 +66,8 @@ Docker image needs nothing at all, and carries the PostgreSQL client tools
|
|
|
63
66
|
| Storage | Buckets and their policies (objects are never copied) | API and SQL |
|
|
64
67
|
| Auth config | Management API, or GoTrue on self-hosted | API (hosted) |
|
|
65
68
|
| Cron jobs | `cron.job` | SQL |
|
|
69
|
+
| Queues | Supabase Queues (`pgmq.meta`), created and dropped through pgmq | SQL |
|
|
70
|
+
| Partition sets | pg_partman registrations (`part_config`), made with `create_parent` | SQL |
|
|
66
71
|
| Webhooks | Triggers calling `supabase_functions.http_request` | SQL |
|
|
67
72
|
| Realtime | Publications, and policies on `realtime.messages` | SQL |
|
|
68
73
|
| Vault | Secret names and descriptions (values can't be read) | Command to run |
|
|
@@ -71,10 +76,17 @@ Docker image needs nothing at all, and carries the PostgreSQL client tools
|
|
|
71
76
|
| Roles and grants | Custom roles, and grants on tables, views, sequences and functions, including `anon`, `authenticated`, `service_role` | SQL |
|
|
72
77
|
|
|
73
78
|
The schema check covers tables, columns, keys, indexes, partitions, views,
|
|
74
|
-
materialized views, functions,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
materialized views, functions, aggregates, triggers, event triggers, rules,
|
|
80
|
+
sequences, enums, composite and range types, domains, casts, extended
|
|
81
|
+
statistics, text search configurations and dictionaries, foreign servers,
|
|
82
|
+
user mappings and foreign tables, policies, default privileges, replica
|
|
83
|
+
identity, statistics targets, extensions and comments. A renamed column,
|
|
84
|
+
table or sequence is renamed, keeping its rows, rather than dropped and
|
|
85
|
+
created again. It runs in every schema except Supabase's own (`auth`,
|
|
86
|
+
`storage`, and so on) and those in `ignoreSchemas`. Objects owned by an
|
|
87
|
+
extension belong to it and aren't compared. Objects of a kind it doesn't
|
|
88
|
+
compare, such as operator classes, are named under the check so you can look
|
|
89
|
+
at them by hand; they aren't counted as drift.
|
|
78
90
|
|
|
79
91
|
A check that can't run, for example without API credentials, says so and why.
|
|
80
92
|
It's never reported as a clean pass.
|
|
@@ -109,9 +121,11 @@ Useful `diff` flags:
|
|
|
109
121
|
| `--only=<id,...>` | Apply only these findings (ids come from `--json`, globs allowed) |
|
|
110
122
|
| `--dry-run` | Print the fixes in the order they'd run, run nothing |
|
|
111
123
|
| `--prove` | Rehearse the fixes on a throwaway copy first |
|
|
124
|
+
| `--source-dir <dir>` | Compare a directory of schema files (such as `supabase/schemas`) with the target instead of a source database |
|
|
112
125
|
| `--allow-destructive` | Also apply drops and deletes |
|
|
113
126
|
| `--apply-posture` | Also apply the target-only checks' fixes |
|
|
114
127
|
| `--no-transaction` | Apply fix by fix, keeping what works |
|
|
128
|
+
| `--no-snapshot` | Read each query on its own. By default each database is read as of one instant, so a change made while the scan runs is seen by all of it or none; as with `pg_dump`, what it reads stays locked until the scan ends |
|
|
115
129
|
| `--json` / `--ci` | Machine-readable output; CI annotations and exit codes |
|
|
116
130
|
|
|
117
131
|
## Applying fixes safely
|
|
@@ -129,11 +143,13 @@ Useful `diff` flags:
|
|
|
129
143
|
is unchanged. A fix the target can't hold, because it needs an extension or
|
|
130
144
|
a Supabase schema the target lacks, is skipped with the reason, and the rest
|
|
131
145
|
still applies.
|
|
132
|
-
- **`--prove`.** The fixes are replayed on a
|
|
133
|
-
made on the target's own server, the way the apply will run them
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
- **`--prove`.** The fixes are replayed on a copy of the target's structure,
|
|
147
|
+
made on the target's own server, the way the apply will run them, with a
|
|
148
|
+
sample of each table's rows. Nothing is applied unless the result matches
|
|
149
|
+
the source and the rows survive, and nothing is applied if the proof can't
|
|
150
|
+
run. It also names the tables the fixes rewrite. Changes a copy can't hold,
|
|
151
|
+
such as cron jobs (pg_cron lives in one database per server), are listed as
|
|
152
|
+
not proved.
|
|
137
153
|
|
|
138
154
|
```bash
|
|
139
155
|
supaforge diff --dry-run # the plan, in order
|
|
@@ -182,7 +198,9 @@ the output.
|
|
|
182
198
|
- **Targets.** Restore runs as one transaction and expects an empty database.
|
|
183
199
|
`--force` clears the snapshot's own schemas first (never Supabase's) and
|
|
184
200
|
puts back the triggers and policies outside them that depended on what it
|
|
185
|
-
cleared.
|
|
201
|
+
cleared. A restore or apply that looks likely to need more locks than the
|
|
202
|
+
target allows in one transaction says so before it starts;
|
|
203
|
+
`--no-transaction` commits as it goes instead.
|
|
186
204
|
- **Plain PostgreSQL.** Restoring into plain PostgreSQL works. What can't
|
|
187
205
|
exist there is skipped and named: a foreign key to `auth.users`, a webhook,
|
|
188
206
|
an extension the server doesn't ship, and everything that needs it.
|
|
@@ -260,6 +278,7 @@ supaforge migrate run --env=prod --apply
|
|
|
260
278
|
| `SUPAFORGE_DBDIFF_MEMORY` | `1G` | Memory limit for `@dbdiff/cli` (`2G`, `-1` for none) |
|
|
261
279
|
| `SUPAFORGE_CONNECT_TIMEOUT` | `15` | Seconds to wait for a connection |
|
|
262
280
|
| `SUPAFORGE_CHECK_CONCURRENCY` | `4` | Checks run at once. Lower it behind a tight pooler |
|
|
281
|
+
| `SUPAFORGE_PROVE_ROWS` | `1000` | Rows of each table `--prove` copies to check they survive; `0` checks structure only |
|
|
263
282
|
| `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` |
|
|
264
283
|
|
|
265
284
|
## Self-hosted Supabase
|
package/dist/base-command.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
|
-
import { S as SupaForgeConfig, E as EnvironmentConfig } from './config-
|
|
2
|
+
import { S as SupaForgeConfig, E as EnvironmentConfig } from './config-l3ggjw9r.js';
|
|
3
3
|
|
|
4
4
|
/** Outcome of a single preflight check (DB connectivity or custom). */
|
|
5
5
|
interface CheckEntry {
|
package/dist/base-command.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseCommand
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-OXS42LJH.js";
|
|
4
|
+
import "./chunk-KT7NMELZ.js";
|
|
5
|
+
import "./chunk-KHXEES2M.js";
|
|
6
|
+
import "./chunk-SQ52YBKK.js";
|
|
7
7
|
export {
|
|
8
8
|
BaseCommand
|
|
9
9
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EnvironmentConfig, S as SupaForgeConfig } from './config-
|
|
1
|
+
import { E as EnvironmentConfig, S as SupaForgeConfig } from './config-l3ggjw9r.js';
|
|
2
2
|
|
|
3
3
|
/** Prefix for branch database names created by SupaForge. */
|
|
4
4
|
declare const BRANCH_DB_PREFIX = "supaforge_branch_";
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
assertPgBinUsable,
|
|
3
|
+
describeMissingPgDump,
|
|
4
|
+
getServerMajorVersion,
|
|
5
|
+
normalizeRoles,
|
|
6
|
+
resolvePgDumpPath
|
|
7
|
+
} from "./chunk-Z2YUOA4W.js";
|
|
4
8
|
import {
|
|
5
9
|
Check,
|
|
6
10
|
inRolledBackTransaction,
|
|
7
|
-
newPgClient,
|
|
8
11
|
newPgPool,
|
|
9
12
|
pgClientConfig,
|
|
10
13
|
pgQuery,
|
|
@@ -12,7 +15,7 @@ import {
|
|
|
12
15
|
quoteLiteral,
|
|
13
16
|
quoteName,
|
|
14
17
|
readOrAbsent
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-KT7NMELZ.js";
|
|
16
19
|
import {
|
|
17
20
|
DEFAULT_IGNORE_SCHEMAS,
|
|
18
21
|
MIGRATIONS_SUBDIR,
|
|
@@ -25,176 +28,7 @@ import {
|
|
|
25
28
|
errMsg,
|
|
26
29
|
ok,
|
|
27
30
|
warn
|
|
28
|
-
} from "./chunk-
|
|
29
|
-
|
|
30
|
-
// src/pg-tools.ts
|
|
31
|
-
import { execFile } from "child_process";
|
|
32
|
-
import { platform } from "os";
|
|
33
|
-
import { existsSync } from "fs";
|
|
34
|
-
function parsePgDumpVersion(output) {
|
|
35
|
-
const m = output.match(/(\d+)(?:\.\d+)?/);
|
|
36
|
-
return m ? Number(m[1]) : null;
|
|
37
|
-
}
|
|
38
|
-
function parseServerVersion(versionStr) {
|
|
39
|
-
const m = versionStr.match(/^(\d+)/);
|
|
40
|
-
return m ? Number(m[1]) : null;
|
|
41
|
-
}
|
|
42
|
-
async function getLocalPgDumpVersion() {
|
|
43
|
-
return new Promise((resolve2) => {
|
|
44
|
-
execFile("pg_dump", ["--version"], (err, stdout) => {
|
|
45
|
-
if (err) return resolve2(null);
|
|
46
|
-
resolve2(parsePgDumpVersion(stdout));
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function getPgDumpVersionAt(path) {
|
|
51
|
-
return new Promise((resolve2) => {
|
|
52
|
-
execFile(path, ["--version"], (err, stdout) => {
|
|
53
|
-
if (err) return resolve2(null);
|
|
54
|
-
resolve2(parsePgDumpVersion(stdout));
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
var VERSIONED_PG_DIRS = [
|
|
59
|
-
"/usr/lib/postgresql/{v}/bin",
|
|
60
|
-
// Debian / Ubuntu (PGDG)
|
|
61
|
-
"/opt/homebrew/opt/postgresql@{v}/bin",
|
|
62
|
-
// macOS Homebrew (Apple Silicon)
|
|
63
|
-
"/usr/local/opt/postgresql@{v}/bin",
|
|
64
|
-
// macOS Homebrew (Intel)
|
|
65
|
-
"/usr/pgsql-{v}/bin"
|
|
66
|
-
// RHEL / CentOS (PGDG)
|
|
67
|
-
];
|
|
68
|
-
async function resolvePgDumpPath(serverMajor) {
|
|
69
|
-
const named = process.env.SUPAFORGE_PG_BIN?.trim();
|
|
70
|
-
if (named) {
|
|
71
|
-
if (!existsSync(`${named}/pg_dump`)) {
|
|
72
|
-
throw new Error(`SUPAFORGE_PG_BIN is set to "${named}", which has no pg_dump`);
|
|
73
|
-
}
|
|
74
|
-
const major = await getPgDumpVersionAt(`${named}/pg_dump`);
|
|
75
|
-
if (major !== null && major >= serverMajor) return { path: `${named}/pg_dump`, major };
|
|
76
|
-
}
|
|
77
|
-
const defaultMajor = await getLocalPgDumpVersion();
|
|
78
|
-
if (defaultMajor !== null && defaultMajor >= serverMajor) {
|
|
79
|
-
return { path: "pg_dump", major: defaultMajor };
|
|
80
|
-
}
|
|
81
|
-
for (const v of versionsToCheck(serverMajor)) {
|
|
82
|
-
for (const tmpl of VERSIONED_PG_DIRS) {
|
|
83
|
-
const dir = tmpl.replace("{v}", String(v));
|
|
84
|
-
const candidate = `${dir}/pg_dump`;
|
|
85
|
-
if (!existsSync(candidate)) continue;
|
|
86
|
-
const major = await getPgDumpVersionAt(candidate);
|
|
87
|
-
if (major !== null && major >= serverMajor) {
|
|
88
|
-
return { path: candidate, major };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
function assertPgBinUsable() {
|
|
95
|
-
const named = process.env.SUPAFORGE_PG_BIN?.trim();
|
|
96
|
-
if (named && !existsSync(`${named}/pg_dump`)) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`SUPAFORGE_PG_BIN is set to "${named}", which has no pg_dump. Point it at a directory of PostgreSQL client tools, or unset it to use the ones on PATH.`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async function describeMissingPgDump(neededMajor) {
|
|
103
|
-
const onPath = await getLocalPgDumpVersion();
|
|
104
|
-
const named = process.env.SUPAFORGE_PG_BIN?.trim();
|
|
105
|
-
const namedMajor = named ? await getPgDumpVersionAt(`${named}/pg_dump`) : null;
|
|
106
|
-
const found = [
|
|
107
|
-
onPath === null ? "none on PATH" : `${onPath} on PATH`,
|
|
108
|
-
...named ? [`${namedMajor ?? "none"} in SUPAFORGE_PG_BIN`] : []
|
|
109
|
-
].join(", ");
|
|
110
|
-
return `no pg_dump ${neededMajor} or newer (found: ${found}); set SUPAFORGE_PG_BIN to a directory of PostgreSQL ${neededMajor}+ client tools`;
|
|
111
|
-
}
|
|
112
|
-
function resolvePgRestorePath(pgDumpPath) {
|
|
113
|
-
if (pgDumpPath === "pg_dump") return "pg_restore";
|
|
114
|
-
return pgDumpPath.replace(/pg_dump$/, "pg_restore");
|
|
115
|
-
}
|
|
116
|
-
function versionsToCheck(required) {
|
|
117
|
-
const versions = [];
|
|
118
|
-
for (let v = required + 3; v >= required; v--) {
|
|
119
|
-
versions.push(v);
|
|
120
|
-
}
|
|
121
|
-
return versions;
|
|
122
|
-
}
|
|
123
|
-
async function getServerMajorVersion(dbUrl) {
|
|
124
|
-
const client = newPgClient(dbUrl);
|
|
125
|
-
try {
|
|
126
|
-
await client.connect();
|
|
127
|
-
const { rows } = await client.query("SHOW server_version");
|
|
128
|
-
const raw = rows[0].server_version;
|
|
129
|
-
const major = parseServerVersion(raw);
|
|
130
|
-
if (!major) throw new Error(`Could not parse server version: ${raw}`);
|
|
131
|
-
return major;
|
|
132
|
-
} finally {
|
|
133
|
-
await client.end();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async function checkPgDumpCompat(dbUrl) {
|
|
137
|
-
const serverMajor = await getServerMajorVersion(dbUrl);
|
|
138
|
-
const resolved = await resolvePgDumpPath(serverMajor);
|
|
139
|
-
if (resolved) {
|
|
140
|
-
return {
|
|
141
|
-
localMajor: resolved.major,
|
|
142
|
-
serverMajor,
|
|
143
|
-
compatible: true,
|
|
144
|
-
message: "",
|
|
145
|
-
pgDumpPath: resolved.path,
|
|
146
|
-
pgRestorePath: resolvePgRestorePath(resolved.path)
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const localMajor = await getLocalPgDumpVersion();
|
|
150
|
-
const message = buildInstallMessage(localMajor, serverMajor);
|
|
151
|
-
return {
|
|
152
|
-
localMajor,
|
|
153
|
-
serverMajor,
|
|
154
|
-
compatible: false,
|
|
155
|
-
message,
|
|
156
|
-
pgDumpPath: "pg_dump",
|
|
157
|
-
pgRestorePath: "pg_restore"
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function buildInstallMessage(localMajor, serverMajor) {
|
|
161
|
-
const header = localMajor === null ? `pg_dump not found. The server is PostgreSQL ${serverMajor} \u2014 install postgresql-client-${serverMajor}:` : `pg_dump version mismatch: local v${localMajor}, server v${serverMajor}. Install postgresql-client-${serverMajor}:`;
|
|
162
|
-
const instructions = getInstallInstructions(serverMajor);
|
|
163
|
-
return `${header}
|
|
164
|
-
|
|
165
|
-
${instructions}`;
|
|
166
|
-
}
|
|
167
|
-
function getInstallInstructions(majorVersion) {
|
|
168
|
-
const os = platform();
|
|
169
|
-
const v = majorVersion;
|
|
170
|
-
switch (os) {
|
|
171
|
-
case "darwin":
|
|
172
|
-
return [
|
|
173
|
-
` brew install postgresql@${v}`,
|
|
174
|
-
` # Then add to PATH:`,
|
|
175
|
-
` export PATH="/opt/homebrew/opt/postgresql@${v}/bin:$PATH"`
|
|
176
|
-
].join("\n");
|
|
177
|
-
case "linux":
|
|
178
|
-
return [
|
|
179
|
-
` # Debian / Ubuntu:`,
|
|
180
|
-
` sudo apt-get install -y postgresql-client-${v}`,
|
|
181
|
-
` # If the package is not found, add the PGDG repository first:`,
|
|
182
|
-
` # https://www.postgresql.org/download/linux/ubuntu/`,
|
|
183
|
-
``,
|
|
184
|
-
` # RHEL / Fedora:`,
|
|
185
|
-
` sudo dnf install -y postgresql${v}`
|
|
186
|
-
].join("\n");
|
|
187
|
-
case "win32":
|
|
188
|
-
return [
|
|
189
|
-
` # Download the installer from:`,
|
|
190
|
-
` # https://www.postgresql.org/download/windows/`,
|
|
191
|
-
` # Or use Chocolatey:`,
|
|
192
|
-
` choco install postgresql${v} --params '/Password:postgres'`
|
|
193
|
-
].join("\n");
|
|
194
|
-
default:
|
|
195
|
-
return ` Download PostgreSQL ${v} client tools from: https://www.postgresql.org/download/`;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
31
|
+
} from "./chunk-SQ52YBKK.js";
|
|
198
32
|
|
|
199
33
|
// src/snapshot.ts
|
|
200
34
|
import { mkdir, writeFile, readFile, readdir, rm } from "fs/promises";
|
|
@@ -737,7 +571,7 @@ function shapeOf(value) {
|
|
|
737
571
|
}
|
|
738
572
|
|
|
739
573
|
// src/snapshot.ts
|
|
740
|
-
var
|
|
574
|
+
var execFile = promisify(execFileCb);
|
|
741
575
|
function generateTimestamp() {
|
|
742
576
|
return (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
743
577
|
}
|
|
@@ -852,7 +686,7 @@ async function captureSchemaSql(dir, dbUrl, schemas) {
|
|
|
852
686
|
sqlSkipReason: `${await describeMissingPgDump(serverMajor)} \u2014 schema.json was still captured, but restore cannot replay the schema`
|
|
853
687
|
};
|
|
854
688
|
}
|
|
855
|
-
const { stdout } = await
|
|
689
|
+
const { stdout } = await execFile(resolved.path, [
|
|
856
690
|
dbUrl,
|
|
857
691
|
"--schema-only",
|
|
858
692
|
"--no-owner",
|
|
@@ -1181,6 +1015,20 @@ async function captureRoleGrants(dir, dbUrl, queryFn) {
|
|
|
1181
1015
|
AND (a.grantee = 0 OR pg_get_userbyid(a.grantee) NOT LIKE 'pg\\_%')
|
|
1182
1016
|
AND n.nspname NOT IN (${excluded})
|
|
1183
1017
|
UNION ALL
|
|
1018
|
+
-- Schemas: USAGE on a schema of its own is what lets a role reach its tables.
|
|
1019
|
+
SELECT CASE WHEN a.grantee = 0 THEN 'PUBLIC' ELSE pg_get_userbyid(a.grantee) END,
|
|
1020
|
+
n.nspname, '', NULL::text, a.privilege_type, a.is_grantable, 'SCHEMA', NULL::text
|
|
1021
|
+
FROM pg_namespace n
|
|
1022
|
+
CROSS JOIN LATERAL aclexplode(n.nspacl) a
|
|
1023
|
+
WHERE n.nspacl IS NOT NULL AND a.grantee <> n.nspowner
|
|
1024
|
+
AND n.nspname NOT IN (${excluded}) AND n.nspname NOT LIKE 'pg\\_%' AND n.nspname <> 'information_schema'
|
|
1025
|
+
AND NOT EXISTS (SELECT 1 FROM pg_depend d WHERE d.classid = 'pg_namespace'::regclass AND d.objid = n.oid AND d.deptype = 'e')
|
|
1026
|
+
AND (a.grantee = 0 OR pg_get_userbyid(a.grantee) NOT IN (
|
|
1027
|
+
'postgres','supabase_admin','authenticator','supabase_auth_admin',
|
|
1028
|
+
'supabase_storage_admin','dashboard_user','pgbouncer','supavisor'
|
|
1029
|
+
))
|
|
1030
|
+
AND (a.grantee = 0 OR pg_get_userbyid(a.grantee) NOT LIKE 'pg\\_%')
|
|
1031
|
+
UNION ALL
|
|
1184
1032
|
SELECT CASE WHEN a.grantee = 0 THEN 'PUBLIC' ELSE pg_get_userbyid(a.grantee) END,
|
|
1185
1033
|
n.nspname, c.relname, att.attname, a.privilege_type, a.is_grantable, '', NULL::text
|
|
1186
1034
|
FROM pg_attribute att
|
|
@@ -1206,18 +1054,64 @@ async function captureRoleGrants(dir, dbUrl, queryFn) {
|
|
|
1206
1054
|
]);
|
|
1207
1055
|
grouped.set(key, [...grouped.get(key) ?? [], row]);
|
|
1208
1056
|
}
|
|
1209
|
-
const statements = [...grouped.values()].map(([row, ...rest]) => `GRANT ${[row, ...rest].map((r) => r.privilege_type + (r.column_name ? ` (${quoteName(r.column_name)})` : "")).join(", ")} ON ${row.keyword ? `${row.keyword} ` : ""}${quoteName(row.table_schema)}.${quoteName(row.table_name)}` + (row.args !== null && row.keyword !== "SEQUENCE" && row.keyword ? `(${row.args})` : "") + ` TO ${row.grantee === "PUBLIC" ? "PUBLIC" : quoteName(row.grantee)}` + (row.is_grantable ? " WITH GRANT OPTION" : "") + ";");
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1057
|
+
const statements = [...grouped.values()].map(([row, ...rest]) => `GRANT ${[row, ...rest].map((r) => r.privilege_type + (r.column_name ? ` (${quoteName(r.column_name)})` : "")).join(", ")} ON ${row.keyword === "SCHEMA" ? `SCHEMA ${quoteName(row.table_schema)}` : `${row.keyword ? `${row.keyword} ` : ""}${quoteName(row.table_schema)}.${quoteName(row.table_name)}`}` + (row.args !== null && row.keyword !== "SEQUENCE" && row.keyword !== "SCHEMA" && row.keyword ? `(${row.args})` : "") + ` TO ${row.grantee === "PUBLIC" ? "PUBLIC" : quoteName(row.grantee)}` + (row.is_grantable ? " WITH GRANT OPTION" : "") + ";");
|
|
1058
|
+
const defaults = await defaultPrivilegeStatements(dbUrl, queryFn, excluded);
|
|
1059
|
+
const all = [...statements, ...defaults];
|
|
1060
|
+
const output = all.length > 0 ? `-- SupaForge Role Grants Snapshot
|
|
1061
|
+
-- ${rows.length} grant(s), ${defaults.length} default privilege statement(s)
|
|
1212
1062
|
|
|
1213
|
-
${
|
|
1063
|
+
${all.join("\n")}
|
|
1214
1064
|
` : "-- No role grants found\n";
|
|
1215
1065
|
await writeFile(join(dir, file), output);
|
|
1216
|
-
return { captured: true, file, itemCount: rows.length };
|
|
1066
|
+
return { captured: true, file, itemCount: rows.length + defaults.length };
|
|
1217
1067
|
} catch (err) {
|
|
1218
1068
|
return { captured: false, file, itemCount: 0, error: errMsg(err) };
|
|
1219
1069
|
}
|
|
1220
1070
|
}
|
|
1071
|
+
var DEFAULT_ACL_KINDS = { r: "TABLES", S: "SEQUENCES", f: "FUNCTIONS", T: "TYPES", n: "SCHEMAS" };
|
|
1072
|
+
async function defaultPrivilegeStatements(dbUrl, queryFn, excludedSchemas) {
|
|
1073
|
+
const platform = `'postgres','supabase_admin','authenticator','supabase_auth_admin','supabase_storage_admin','dashboard_user','pgbouncer','supavisor'`;
|
|
1074
|
+
const rows = await queryFn(dbUrl, `
|
|
1075
|
+
WITH d AS (
|
|
1076
|
+
SELECT d.*, n.nspname FROM pg_default_acl d LEFT JOIN pg_namespace n ON n.oid = d.defaclnamespace
|
|
1077
|
+
WHERE pg_get_userbyid(d.defaclrole) NOT IN ('supabase_admin','supabase_auth_admin','supabase_storage_admin','dashboard_user')
|
|
1078
|
+
AND (n.nspname IS NULL OR n.nspname NOT IN (${excludedSchemas}))
|
|
1079
|
+
), have AS (
|
|
1080
|
+
SELECT d.oid, a.* FROM d CROSS JOIN LATERAL aclexplode(d.defaclacl) a
|
|
1081
|
+
), builtin AS (
|
|
1082
|
+
SELECT d.oid, b.* FROM d CROSS JOIN LATERAL aclexplode(acldefault(d.defaclobjtype, d.defaclrole)) b
|
|
1083
|
+
WHERE d.defaclnamespace = 0
|
|
1084
|
+
)
|
|
1085
|
+
SELECT pg_get_userbyid(d.defaclrole) AS role, d.nspname AS schema, d.defaclobjtype::text AS kind, x.action,
|
|
1086
|
+
CASE WHEN x.grantee = 0 THEN 'PUBLIC' ELSE pg_get_userbyid(x.grantee) END AS grantee,
|
|
1087
|
+
x.privilege_type, x.is_grantable
|
|
1088
|
+
FROM d JOIN (
|
|
1089
|
+
SELECT h.oid, 'GRANT' AS action, h.grantee, h.privilege_type, h.is_grantable FROM have h
|
|
1090
|
+
WHERE NOT EXISTS (SELECT 1 FROM builtin b WHERE b.oid = h.oid AND b.grantee = h.grantee
|
|
1091
|
+
AND b.privilege_type = h.privilege_type AND b.is_grantable = h.is_grantable)
|
|
1092
|
+
UNION ALL
|
|
1093
|
+
SELECT b.oid, 'REVOKE', b.grantee, b.privilege_type, b.is_grantable FROM builtin b
|
|
1094
|
+
WHERE NOT EXISTS (SELECT 1 FROM have h WHERE h.oid = b.oid AND h.grantee = b.grantee
|
|
1095
|
+
AND h.privilege_type = b.privilege_type AND h.is_grantable = b.is_grantable)
|
|
1096
|
+
) x ON x.oid = d.oid
|
|
1097
|
+
WHERE (x.grantee = 0 OR pg_get_userbyid(x.grantee) NOT IN (${platform}) OR x.grantee = d.defaclrole)
|
|
1098
|
+
AND (x.grantee = 0 OR pg_get_userbyid(x.grantee) NOT LIKE 'pg\\_%')
|
|
1099
|
+
ORDER BY 1, 2 NULLS FIRST, 3, 4, 5, 6
|
|
1100
|
+
`);
|
|
1101
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
1102
|
+
for (const row of rows) {
|
|
1103
|
+
if (!DEFAULT_ACL_KINDS[row.kind]) continue;
|
|
1104
|
+
const key = JSON.stringify([row.role, row.schema, row.kind, row.action, row.grantee, row.action === "GRANT" && row.is_grantable]);
|
|
1105
|
+
grouped.set(key, [...grouped.get(key) ?? [], row]);
|
|
1106
|
+
}
|
|
1107
|
+
const grantee = (g) => g === "PUBLIC" ? "PUBLIC" : quoteName(g);
|
|
1108
|
+
return [...grouped.values()].map(([row, ...rest]) => {
|
|
1109
|
+
const head = `ALTER DEFAULT PRIVILEGES FOR ROLE ${quoteName(row.role)}${row.schema ? ` IN SCHEMA ${quoteName(row.schema)}` : ""}`;
|
|
1110
|
+
const privileges = [row, ...rest].map((r) => r.privilege_type).join(", ");
|
|
1111
|
+
const on = DEFAULT_ACL_KINDS[row.kind];
|
|
1112
|
+
return row.action === "GRANT" ? `${head} GRANT ${privileges} ON ${on} TO ${grantee(row.grantee)}${row.is_grantable ? " WITH GRANT OPTION" : ""};` : `${head} REVOKE ${privileges} ON ${on} FROM ${grantee(row.grantee)};`;
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1221
1115
|
async function captureExtensions(dir, dbUrl, queryFn) {
|
|
1222
1116
|
const file = "extensions.sql";
|
|
1223
1117
|
try {
|
|
@@ -1328,10 +1222,6 @@ export {
|
|
|
1328
1222
|
readJsonArray,
|
|
1329
1223
|
readJsonObject,
|
|
1330
1224
|
RealtimeCheck,
|
|
1331
|
-
resolvePgDumpPath,
|
|
1332
|
-
describeMissingPgDump,
|
|
1333
|
-
getServerMajorVersion,
|
|
1334
|
-
checkPgDumpCompat,
|
|
1335
1225
|
captureSnapshot,
|
|
1336
1226
|
unrestorableSchema,
|
|
1337
1227
|
formatSnapshotLayers,
|
|
@@ -1341,4 +1231,4 @@ export {
|
|
|
1341
1231
|
DEFAULT_KEEP_COUNT,
|
|
1342
1232
|
pruneSnapshots
|
|
1343
1233
|
};
|
|
1344
|
-
//# sourceMappingURL=chunk-
|
|
1234
|
+
//# sourceMappingURL=chunk-5UHIWFQG.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pgQuery,
|
|
3
3
|
readLocalMigrations
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KT7NMELZ.js";
|
|
5
5
|
import {
|
|
6
6
|
MIGRATIONS_SCHEMA,
|
|
7
7
|
MIGRATIONS_TABLE
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SQ52YBKK.js";
|
|
9
9
|
|
|
10
10
|
// src/migrate.ts
|
|
11
11
|
import { readFile } from "fs/promises";
|
|
@@ -119,4 +119,4 @@ export {
|
|
|
119
119
|
runMigration,
|
|
120
120
|
baselineMigrations
|
|
121
121
|
};
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
122
|
+
//# sourceMappingURL=chunk-AL6INEFX.js.map
|