@otwdesign/db-core 1.2.0 → 1.3.0
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/dist/backup/api.d.ts +55 -0
- package/dist/backup/api.js +441 -0
- package/dist/backup/api.js.map +1 -0
- package/dist/backup/catalog.d.ts +47 -0
- package/dist/backup/catalog.js +348 -0
- package/dist/backup/catalog.js.map +1 -0
- package/dist/backup/dump.d.ts +48 -0
- package/dist/backup/dump.js +860 -0
- package/dist/backup/dump.js.map +1 -0
- package/dist/backup/format.d.ts +38 -0
- package/dist/backup/format.js +70 -0
- package/dist/backup/format.js.map +1 -0
- package/dist/backup/pg-tools.d.ts +29 -0
- package/dist/backup/pg-tools.js +154 -0
- package/dist/backup/pg-tools.js.map +1 -0
- package/dist/backup/restore.d.ts +41 -0
- package/dist/backup/restore.js +196 -0
- package/dist/backup/restore.js.map +1 -0
- package/dist/backup/split.d.ts +18 -0
- package/dist/backup/split.js +316 -0
- package/dist/backup/split.js.map +1 -0
- package/dist/backup/staging.d.ts +29 -0
- package/dist/backup/staging.js +96 -0
- package/dist/backup/staging.js.map +1 -0
- package/dist/browser.d.ts +5 -0
- package/dist/drivers/pglite.js +57 -0
- package/dist/drivers/pglite.js.map +1 -1
- package/dist/drivers/postgres.js +45 -0
- package/dist/drivers/postgres.js.map +1 -1
- package/dist/handler.d.ts +5 -0
- package/dist/handler.js +48 -1
- package/dist/handler.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/types.d.ts +30 -1
- package/package.json +2 -2
- package/src/backup/api.ts +543 -0
- package/src/backup/catalog.ts +381 -0
- package/src/backup/dump.ts +1102 -0
- package/src/backup/format.ts +114 -0
- package/src/backup/pg-tools.ts +185 -0
- package/src/backup/restore.ts +270 -0
- package/src/backup/split.ts +300 -0
- package/src/backup/staging.ts +143 -0
- package/src/browser.ts +5 -0
- package/src/drivers/pglite.ts +55 -0
- package/src/drivers/postgres.ts +46 -0
- package/src/handler.ts +56 -1
- package/src/index.ts +6 -0
- package/src/types.ts +29 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Access, AuditEvent, ConnectionConfig, Driver, Viewer } from '../types.ts';
|
|
2
|
+
import { type SchemaChoice } from './dump.ts';
|
|
3
|
+
import { type PgTool } from './pg-tools.ts';
|
|
4
|
+
import { type RestorePlan } from './restore.ts';
|
|
5
|
+
/** What an endpoint gets from the handler: the connection it reached, and who asks. */
|
|
6
|
+
export interface BackupContext {
|
|
7
|
+
connection: ConnectionConfig;
|
|
8
|
+
access: Access;
|
|
9
|
+
db: Driver;
|
|
10
|
+
database?: string;
|
|
11
|
+
viewer: Viewer;
|
|
12
|
+
record(event: Omit<AuditEvent, 'at'>): Promise<void>;
|
|
13
|
+
maxRestoreBytes: number;
|
|
14
|
+
}
|
|
15
|
+
/** What the Back up and Restore dialog shows. */
|
|
16
|
+
export interface BackupOptions {
|
|
17
|
+
database: string;
|
|
18
|
+
server: string;
|
|
19
|
+
/** The database runs in the host's process (PGlite): it waits while a backup or restore runs. */
|
|
20
|
+
exclusive: boolean;
|
|
21
|
+
schemas: SchemaChoice[];
|
|
22
|
+
notIncluded: {
|
|
23
|
+
schema: string | null;
|
|
24
|
+
what: string;
|
|
25
|
+
}[];
|
|
26
|
+
pgDump: PgTool;
|
|
27
|
+
pgRestore: PgTool;
|
|
28
|
+
restore: {
|
|
29
|
+
allowed: boolean;
|
|
30
|
+
chunkBytes: number;
|
|
31
|
+
maxBytes: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export declare function options(ctx: BackupContext): Promise<BackupOptions>;
|
|
35
|
+
/** The backup as a download: SQL, gzipped, or pg_dump's archive. */
|
|
36
|
+
export declare function download(ctx: BackupContext, body: Record<string, unknown>): Promise<Response>;
|
|
37
|
+
/** What restoring the backup with `header` would replace, and what stops it. */
|
|
38
|
+
export declare function plan(ctx: BackupContext, body: Record<string, unknown>): Promise<RestorePlan>;
|
|
39
|
+
export declare function start(ctx: BackupContext, body: Record<string, unknown>): Promise<{
|
|
40
|
+
upload: string;
|
|
41
|
+
chunkBytes: number;
|
|
42
|
+
}>;
|
|
43
|
+
/** One piece of an upload, as the request's body. */
|
|
44
|
+
export declare function chunk(ctx: BackupContext, request: Request): Promise<{
|
|
45
|
+
received: number;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Runs the restore, answering with a line of JSON as it goes: `progress`, then `done` or
|
|
49
|
+
* `error`. The upload is checked first, so a missing one is a plain error.
|
|
50
|
+
*/
|
|
51
|
+
export declare function run(ctx: BackupContext, body: Record<string, unknown>): Promise<Response>;
|
|
52
|
+
/** Drops an upload that won't be restored. */
|
|
53
|
+
export declare function discard(ctx: BackupContext, body: Record<string, unknown>): Promise<{
|
|
54
|
+
discarded: true;
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
import { createGzip } from 'node:zlib';
|
|
8
|
+
import { DbAdminError, QueryError } from "../errors.js";
|
|
9
|
+
import { backupSql, notIncluded, prepare, schemaChoices, } from "./dump.js";
|
|
10
|
+
import { backupFileName, HEADER_PREFIX, readHeader, STAGING_SCHEMA, } from "./format.js";
|
|
11
|
+
import { pgTool, runDump, runRestore } from "./pg-tools.js";
|
|
12
|
+
import { refuseBlocked, restorePlan, restoreSql } from "./restore.js";
|
|
13
|
+
import * as staging from "./staging.js";
|
|
14
|
+
const NOT_A_SERVER = {
|
|
15
|
+
available: false,
|
|
16
|
+
reason: 'This database runs inside the site, where pg_dump and pg_restore can’t reach it.',
|
|
17
|
+
};
|
|
18
|
+
export async function options(ctx) {
|
|
19
|
+
const session = await open(ctx, 'snapshot');
|
|
20
|
+
try {
|
|
21
|
+
const server = await prepare(session);
|
|
22
|
+
const schemas = await schemaChoices(session);
|
|
23
|
+
const missing = await notIncluded(session, schemas.map((s) => s.name));
|
|
24
|
+
const tools = ctx.db.pgUrl
|
|
25
|
+
? await Promise.all([pgTool('pg_dump', server.version), pgTool('pg_restore', server.version)])
|
|
26
|
+
: [NOT_A_SERVER, NOT_A_SERVER];
|
|
27
|
+
return {
|
|
28
|
+
database: server.database,
|
|
29
|
+
server: server.server,
|
|
30
|
+
exclusive: session.exclusive,
|
|
31
|
+
schemas,
|
|
32
|
+
notIncluded: missing,
|
|
33
|
+
pgDump: tools[0],
|
|
34
|
+
pgRestore: tools[1],
|
|
35
|
+
restore: {
|
|
36
|
+
allowed: ctx.access === 'write',
|
|
37
|
+
chunkBytes: staging.CHUNK_BYTES,
|
|
38
|
+
maxBytes: ctx.maxRestoreBytes,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await session.end(false);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The backup as a download: SQL, gzipped, or pg_dump's archive. */
|
|
47
|
+
export async function download(ctx, body) {
|
|
48
|
+
const schemas = schemaList(body.schemas);
|
|
49
|
+
const format = body.format === 'pg_dump' ? 'pg_dump' : body.format === 'sql' ? 'sql' : null;
|
|
50
|
+
if (!format)
|
|
51
|
+
throw bad('"format" is "sql" or "pg_dump".');
|
|
52
|
+
const started = performance.now();
|
|
53
|
+
const now = new Date();
|
|
54
|
+
const audit = (rows, error) => void ctx.record({
|
|
55
|
+
viewer: ctx.viewer.id,
|
|
56
|
+
connection: ctx.connection.name,
|
|
57
|
+
...(ctx.database ? { database: ctx.database } : {}),
|
|
58
|
+
action: 'backup',
|
|
59
|
+
statement: `backup of ${schemas.join(', ')} as ${format}`,
|
|
60
|
+
durationMs: Math.round(performance.now() - started),
|
|
61
|
+
...(rows === undefined ? {} : { rows }),
|
|
62
|
+
...(error ? { error: error.message } : {}),
|
|
63
|
+
});
|
|
64
|
+
const session = await open(ctx, 'snapshot');
|
|
65
|
+
let server;
|
|
66
|
+
try {
|
|
67
|
+
server = await prepare(session);
|
|
68
|
+
const known = new Set((await schemaChoices(session)).map((s) => s.name));
|
|
69
|
+
const unknown = schemas.filter((s) => !known.has(s));
|
|
70
|
+
if (unknown.length)
|
|
71
|
+
throw bad(`There's no schema ${unknown.map((s) => `"${s}"`).join(', ')} to back up.`);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
await session.end(false);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
const name = (extension) => backupFileName(ctx.connection.name, server.database, now, extension);
|
|
78
|
+
if (format === 'pg_dump') {
|
|
79
|
+
await session.end(false);
|
|
80
|
+
if (!ctx.db.pgUrl)
|
|
81
|
+
throw bad(NOT_A_SERVER.reason);
|
|
82
|
+
const tool = await pgTool('pg_dump', server.version);
|
|
83
|
+
if (!tool.available)
|
|
84
|
+
throw bad(tool.reason);
|
|
85
|
+
const archive = await runDump(ctx.db.pgUrl, schemas);
|
|
86
|
+
return file(counted(archive, audit), name('dump'), 'application/octet-stream');
|
|
87
|
+
}
|
|
88
|
+
const summary = { tables: 0, rows: 0 };
|
|
89
|
+
const pieces = backupSql(session, server, schemas, now, summary);
|
|
90
|
+
let ended = false;
|
|
91
|
+
const end = async () => {
|
|
92
|
+
if (ended)
|
|
93
|
+
return;
|
|
94
|
+
ended = true;
|
|
95
|
+
await session
|
|
96
|
+
.end(false)
|
|
97
|
+
.catch((error) => console.error('otw-db: could not end the backup’s transaction', error));
|
|
98
|
+
};
|
|
99
|
+
if (session.exclusive) {
|
|
100
|
+
// The host waits while this session is open: read it all now, rather than at the pace of
|
|
101
|
+
// the download.
|
|
102
|
+
try {
|
|
103
|
+
const gz = await gzipAll(pieces);
|
|
104
|
+
audit(summary.rows);
|
|
105
|
+
return file(new Blob([gz]).stream(), name('sql.gz'), 'application/gzip');
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
audit(undefined, error);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
await end();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Read the first piece before answering, so a failure is an error rather than a broken file.
|
|
116
|
+
let pending;
|
|
117
|
+
try {
|
|
118
|
+
pending = await pieces.next();
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
await end();
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
const encoder = new TextEncoder();
|
|
125
|
+
const text = new ReadableStream({
|
|
126
|
+
async pull(controller) {
|
|
127
|
+
try {
|
|
128
|
+
const next = pending ?? (await pieces.next());
|
|
129
|
+
pending = null;
|
|
130
|
+
if (next.done) {
|
|
131
|
+
await end();
|
|
132
|
+
audit(summary.rows);
|
|
133
|
+
controller.close();
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
controller.enqueue(encoder.encode(next.value));
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
await end();
|
|
140
|
+
audit(undefined, error);
|
|
141
|
+
controller.error(error);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
async cancel() {
|
|
145
|
+
await pieces.return(undefined);
|
|
146
|
+
await end();
|
|
147
|
+
audit(summary.rows, new Error('The download stopped before the end.'));
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
// TypeScript's DOM types take a CompressionStream's input as any BufferSource; bytes it is.
|
|
151
|
+
const gzip = new CompressionStream('gzip');
|
|
152
|
+
return file(text.pipeThrough(gzip), name('sql.gz'), 'application/gzip');
|
|
153
|
+
}
|
|
154
|
+
/** What restoring the backup with `header` would replace, and what stops it. */
|
|
155
|
+
export async function plan(ctx, body) {
|
|
156
|
+
mayRestore(ctx);
|
|
157
|
+
const header = headerOf(body.header);
|
|
158
|
+
const session = await open(ctx, 'snapshot');
|
|
159
|
+
try {
|
|
160
|
+
return await restorePlan(session, header);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
await session.end(false);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export async function start(ctx, body) {
|
|
167
|
+
mayRestore(ctx);
|
|
168
|
+
const size = body.size;
|
|
169
|
+
if (typeof size !== 'number' || !Number.isInteger(size) || size < 1) {
|
|
170
|
+
throw bad('"size" is the backup’s size in bytes.');
|
|
171
|
+
}
|
|
172
|
+
if (size > ctx.maxRestoreBytes) {
|
|
173
|
+
throw new DbAdminError(`The backup is ${megabytes(size)}; this tool restores ${megabytes(ctx.maxRestoreBytes)} at most. Restore it with psql or pg_restore instead.`, 413, 'too-large');
|
|
174
|
+
}
|
|
175
|
+
const kind = body.kind === 'pg_dump' ? 'pg_dump' : body.kind === 'sql' ? 'sql' : null;
|
|
176
|
+
if (!kind)
|
|
177
|
+
throw bad('"kind" is "sql" or "pg_dump".');
|
|
178
|
+
if (kind === 'pg_dump')
|
|
179
|
+
await restoreTool(ctx);
|
|
180
|
+
const name = typeof body.name === 'string' ? body.name : 'backup';
|
|
181
|
+
const upload = await write(ctx, (s) => staging.startUpload(s, { viewer: ctx.viewer.id, kind, size, name }));
|
|
182
|
+
return { upload, chunkBytes: staging.CHUNK_BYTES };
|
|
183
|
+
}
|
|
184
|
+
/** One piece of an upload, as the request's body. */
|
|
185
|
+
export async function chunk(ctx, request) {
|
|
186
|
+
mayRestore(ctx);
|
|
187
|
+
const params = new URL(request.url).searchParams;
|
|
188
|
+
const seq = Number(params.get('seq'));
|
|
189
|
+
const data = await bytes(request, staging.CHUNK_BYTES);
|
|
190
|
+
if (!data.byteLength)
|
|
191
|
+
throw bad('The piece is empty.');
|
|
192
|
+
await write(ctx, async (s) => {
|
|
193
|
+
const upload = await staging.findUpload(s, String(params.get('upload')), ctx.viewer.id);
|
|
194
|
+
await staging.putChunk(s, upload, seq, data);
|
|
195
|
+
});
|
|
196
|
+
return { received: data.byteLength };
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Runs the restore, answering with a line of JSON as it goes: `progress`, then `done` or
|
|
200
|
+
* `error`. The upload is checked first, so a missing one is a plain error.
|
|
201
|
+
*/
|
|
202
|
+
export async function run(ctx, body) {
|
|
203
|
+
mayRestore(ctx);
|
|
204
|
+
const id = String(body.upload);
|
|
205
|
+
const started = performance.now();
|
|
206
|
+
const session = await open(ctx, 'write');
|
|
207
|
+
let upload;
|
|
208
|
+
try {
|
|
209
|
+
upload = await staging.findUpload(session, id, ctx.viewer.id);
|
|
210
|
+
staging.complete(upload);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
await session.end(false);
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
let header = null;
|
|
217
|
+
const audit = (result, error) => void ctx.record({
|
|
218
|
+
viewer: ctx.viewer.id,
|
|
219
|
+
connection: ctx.connection.name,
|
|
220
|
+
...(ctx.database ? { database: ctx.database } : {}),
|
|
221
|
+
action: 'restore',
|
|
222
|
+
statement: `restore of ${header ? header.schemas.join(', ') : 'a backup'} (${upload.kind}, ${upload.size} bytes)`,
|
|
223
|
+
durationMs: Math.round(performance.now() - started),
|
|
224
|
+
...(result.rows === undefined ? {} : { rows: result.rows }),
|
|
225
|
+
...(error ? { error: error.message } : {}),
|
|
226
|
+
});
|
|
227
|
+
const encoder = new TextEncoder();
|
|
228
|
+
const stream = new ReadableStream({
|
|
229
|
+
async start(controller) {
|
|
230
|
+
const send = (line) => controller.enqueue(encoder.encode(`${JSON.stringify(line)}\n`));
|
|
231
|
+
try {
|
|
232
|
+
const result = upload.kind === 'sql'
|
|
233
|
+
? await restoreInSession(session, upload, (h) => (header = h), (p) => send({ type: 'progress', ...p }))
|
|
234
|
+
: await restoreArchive(ctx, session, upload, () => send({ type: 'progress', statements: 0, bytes: upload.size }));
|
|
235
|
+
audit(result);
|
|
236
|
+
send({ type: 'done', ...result, durationMs: Math.round(performance.now() - started) });
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
const failure = error instanceof DbAdminError
|
|
240
|
+
? error
|
|
241
|
+
: new DbAdminError(`The restore failed: ${error.message}`, 500, 'restore-failed');
|
|
242
|
+
audit({}, failure);
|
|
243
|
+
send({ type: 'error', error: { code: failure.code, message: failure.message } });
|
|
244
|
+
// A failed restore's upload goes too: it would only fail again.
|
|
245
|
+
await write(ctx, (s) => staging.discard(s, id)).catch((e) => console.error('otw-db: could not remove a restore’s upload', e));
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
controller.close();
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
return new Response(stream, {
|
|
253
|
+
headers: {
|
|
254
|
+
'content-type': 'application/x-ndjson; charset=utf-8',
|
|
255
|
+
'cache-control': 'no-store',
|
|
256
|
+
'x-content-type-options': 'nosniff',
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/** Drops an upload that won't be restored. */
|
|
261
|
+
export async function discard(ctx, body) {
|
|
262
|
+
mayRestore(ctx);
|
|
263
|
+
const id = String(body.upload);
|
|
264
|
+
await write(ctx, async (s) => {
|
|
265
|
+
await staging.findUpload(s, id, ctx.viewer.id);
|
|
266
|
+
await staging.discard(s, id);
|
|
267
|
+
});
|
|
268
|
+
return { discarded: true };
|
|
269
|
+
}
|
|
270
|
+
async function restoreInSession(session, upload, onHeader, onProgress) {
|
|
271
|
+
try {
|
|
272
|
+
// A table the site is using makes DROP wait; better to fail soon and say why.
|
|
273
|
+
if (!session.exclusive)
|
|
274
|
+
await session.query(`SET LOCAL lock_timeout = '10s'`);
|
|
275
|
+
const result = await restoreSql(session, staging.chunks(session, upload), {
|
|
276
|
+
async check(header) {
|
|
277
|
+
onHeader(header);
|
|
278
|
+
refuseBlocked(header, await restorePlan(session, header));
|
|
279
|
+
},
|
|
280
|
+
onProgress,
|
|
281
|
+
});
|
|
282
|
+
await staging.discard(session, upload.id);
|
|
283
|
+
await session.end(true);
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
await session.end(false).catch(() => { });
|
|
288
|
+
if (error instanceof QueryError && error.sqlState === '55P03') {
|
|
289
|
+
throw new DbAdminError('The database is busy: something is using a table the restore replaces. Nothing changed; try again in a moment.', 409, 'busy');
|
|
290
|
+
}
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/** pg_dump's archive, put in a file for pg_restore, which restores it in one transaction. */
|
|
295
|
+
async function restoreArchive(ctx, session, upload, onStart) {
|
|
296
|
+
const dir = await mkdtemp(join(tmpdir(), 'otw-db-restore-'));
|
|
297
|
+
const path = join(dir, 'backup.dump');
|
|
298
|
+
try {
|
|
299
|
+
try {
|
|
300
|
+
await pipeline(Readable.from(staging.chunks(session, upload)), createWriteStream(path));
|
|
301
|
+
}
|
|
302
|
+
finally {
|
|
303
|
+
await session.end(false);
|
|
304
|
+
}
|
|
305
|
+
await restoreTool(ctx);
|
|
306
|
+
onStart();
|
|
307
|
+
await runRestore(ctx.db.pgUrl, path);
|
|
308
|
+
await write(ctx, (s) => staging.discard(s, upload.id));
|
|
309
|
+
return { statements: 0, tables: 0, rows: 0 };
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
await rm(dir, { recursive: true, force: true });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
async function restoreTool(ctx) {
|
|
316
|
+
if (!ctx.db.pgUrl)
|
|
317
|
+
throw bad(NOT_A_SERVER.reason);
|
|
318
|
+
const session = await open(ctx, 'snapshot');
|
|
319
|
+
let version;
|
|
320
|
+
try {
|
|
321
|
+
version = (await prepare(session)).version;
|
|
322
|
+
}
|
|
323
|
+
finally {
|
|
324
|
+
await session.end(false);
|
|
325
|
+
}
|
|
326
|
+
const tool = await pgTool('pg_restore', version);
|
|
327
|
+
if (!tool.available)
|
|
328
|
+
throw bad(tool.reason);
|
|
329
|
+
}
|
|
330
|
+
function mayRestore(ctx) {
|
|
331
|
+
if (ctx.access !== 'write') {
|
|
332
|
+
throw new DbAdminError(`Restoring needs write access, and connection "${ctx.connection.name}" is read-only.`, 403, 'read-only');
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function open(ctx, mode) {
|
|
336
|
+
if (typeof ctx.db.session !== 'function') {
|
|
337
|
+
throw new DbAdminError(`Connection "${ctx.connection.name}" can't be backed up here: backups are for PostgreSQL.`, 400, 'no-backups');
|
|
338
|
+
}
|
|
339
|
+
return ctx.db.session(mode);
|
|
340
|
+
}
|
|
341
|
+
/** `work` in a write session of its own, committed if it succeeds. */
|
|
342
|
+
async function write(ctx, work) {
|
|
343
|
+
const session = await open(ctx, 'write');
|
|
344
|
+
try {
|
|
345
|
+
const result = await work(session);
|
|
346
|
+
await session.end(true);
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
await session.end(false).catch(() => { });
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function schemaList(value) {
|
|
355
|
+
if (!Array.isArray(value) || !value.length || value.length > 500) {
|
|
356
|
+
throw bad('"schemas" lists the schemas to back up.');
|
|
357
|
+
}
|
|
358
|
+
const names = value.map((name) => {
|
|
359
|
+
if (typeof name !== 'string' || !name || new TextEncoder().encode(name).length > 63) {
|
|
360
|
+
throw bad('"schemas" lists the schemas to back up, by name.');
|
|
361
|
+
}
|
|
362
|
+
if (name === STAGING_SCHEMA)
|
|
363
|
+
throw bad(`${STAGING_SCHEMA} is where restores wait: it isn't backed up.`);
|
|
364
|
+
return name;
|
|
365
|
+
});
|
|
366
|
+
return [...new Set(names)];
|
|
367
|
+
}
|
|
368
|
+
/** A header the browser read from the file, checked as the file's own would be. */
|
|
369
|
+
function headerOf(value) {
|
|
370
|
+
if (!value || typeof value !== 'object')
|
|
371
|
+
throw bad('"header" is the backup’s first line, read.');
|
|
372
|
+
return readHeader(`${HEADER_PREFIX}${JSON.stringify(value)}`);
|
|
373
|
+
}
|
|
374
|
+
/** The request's body, refused past `max` bytes. */
|
|
375
|
+
async function bytes(request, max) {
|
|
376
|
+
const tooBig = () => new DbAdminError(`A piece of an upload is ${megabytes(max)} at most.`, 413, 'too-large');
|
|
377
|
+
if (Number(request.headers.get('content-length') ?? 0) > max)
|
|
378
|
+
throw tooBig();
|
|
379
|
+
const reader = request.body?.getReader();
|
|
380
|
+
if (!reader)
|
|
381
|
+
return new Uint8Array();
|
|
382
|
+
const parts = [];
|
|
383
|
+
let size = 0;
|
|
384
|
+
for (;;) {
|
|
385
|
+
const { done, value } = await reader.read();
|
|
386
|
+
if (done)
|
|
387
|
+
break;
|
|
388
|
+
size += value.byteLength;
|
|
389
|
+
if (size > max) {
|
|
390
|
+
await reader.cancel();
|
|
391
|
+
throw tooBig();
|
|
392
|
+
}
|
|
393
|
+
parts.push(value);
|
|
394
|
+
}
|
|
395
|
+
const all = new Uint8Array(size);
|
|
396
|
+
let at = 0;
|
|
397
|
+
for (const part of parts) {
|
|
398
|
+
all.set(part, at);
|
|
399
|
+
at += part.byteLength;
|
|
400
|
+
}
|
|
401
|
+
return all;
|
|
402
|
+
}
|
|
403
|
+
async function gzipAll(pieces) {
|
|
404
|
+
const gzip = createGzip();
|
|
405
|
+
const out = [];
|
|
406
|
+
gzip.on('data', (data) => out.push(data));
|
|
407
|
+
const done = new Promise((resolve, reject) => {
|
|
408
|
+
gzip.on('end', resolve);
|
|
409
|
+
gzip.on('error', reject);
|
|
410
|
+
});
|
|
411
|
+
for await (const piece of pieces) {
|
|
412
|
+
if (!gzip.write(piece))
|
|
413
|
+
await new Promise((resolve) => gzip.once('drain', resolve));
|
|
414
|
+
}
|
|
415
|
+
gzip.end();
|
|
416
|
+
await done;
|
|
417
|
+
return Buffer.concat(out);
|
|
418
|
+
}
|
|
419
|
+
/** `stream`, with `audit` told its end: its bytes, or why it stopped. */
|
|
420
|
+
function counted(stream, audit) {
|
|
421
|
+
return stream.pipeThrough(new TransformStream({
|
|
422
|
+
flush: () => audit(undefined),
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
function file(body, name, type) {
|
|
426
|
+
return new Response(body, {
|
|
427
|
+
headers: {
|
|
428
|
+
'content-type': type,
|
|
429
|
+
'content-disposition': `attachment; filename="${name}"`,
|
|
430
|
+
'cache-control': 'no-store',
|
|
431
|
+
'x-content-type-options': 'nosniff',
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
function megabytes(bytes) {
|
|
436
|
+
return `${(bytes / 1_048_576).toLocaleString('en', { maximumFractionDigits: 1 })} MB`;
|
|
437
|
+
}
|
|
438
|
+
function bad(message) {
|
|
439
|
+
return new DbAdminError(message, 400, 'bad-request');
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/backup/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,EACL,SAAS,EACT,WAAW,EACX,OAAO,EACP,aAAa,GAGd,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,cAAc,EACd,aAAa,EACb,UAAU,EACV,cAAc,GAEf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAe,MAAM,eAAe,CAAA;AACxE,OAA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,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,CAAA;IACV,MAAM,IAAI,CAAA;IACV,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AAC3B,CAAC;AAED,yEAAyE;AACzE,SAAS,OAAO,CACd,MAAkC,EAClC,KAAwD;IAExD,OAAO,MAAM,CAAC,WAAW,CACvB,IAAI,eAAe,CAAyB;QAC1C,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;KAC9B,CAAC,CACH,CAAA;AACH,CAAC;AAED,SAAS,IAAI,CAAC,IAAgC,EAAE,IAAY,EAAE,IAAY;IACxE,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,OAAO,EAAE;YACP,cAAc,EAAE,IAAI;YACpB,qBAAqB,EAAE,yBAAyB,IAAI,GAAG;YACvD,eAAe,EAAE,UAAU;YAC3B,wBAAwB,EAAE,SAAS;SACpC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,KAAK,CAAA;AACvF,CAAC;AAED,SAAS,GAAG,CAAC,OAAe;IAC1B,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** The catalogs' OIDs, the same in every PostgreSQL. */
|
|
2
|
+
export declare const PG_TYPE = 1247;
|
|
3
|
+
export declare const PG_PROC = 1255;
|
|
4
|
+
export declare const PG_CLASS = 1259;
|
|
5
|
+
export declare const PG_ATTRDEF = 2604;
|
|
6
|
+
export declare const PG_CONSTRAINT = 2606;
|
|
7
|
+
export declare const PG_NAMESPACE = 2615;
|
|
8
|
+
export declare const PG_REWRITE = 2618;
|
|
9
|
+
export declare const PG_EXTENSION = 3079;
|
|
10
|
+
/** The session's settings: names printed qualified, values printed so they read back the same. */
|
|
11
|
+
export declare const SESSION_SQL: string[];
|
|
12
|
+
export declare const SERVER_SQL = "SELECT json_build_object(\n 'version', current_setting('server_version_num')::int, 'server', split_part(version(), ' ', 1)\n || ' ' || current_setting('server_version'), 'database', current_database(), 'user', current_user)";
|
|
13
|
+
/** Every schema a backup could hold, with what's in it; takes no parameters. */
|
|
14
|
+
export declare const SCHEMAS_SQL: string;
|
|
15
|
+
/**
|
|
16
|
+
* What the backup can't hold, in the schemas it backs up, and what's database-wide (schema null):
|
|
17
|
+
* described as the server describes them, such as `aggregate public.median(numeric)`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const NOT_INCLUDED_SQL: string;
|
|
20
|
+
export declare const SCHEMA_DETAILS_SQL: string;
|
|
21
|
+
/** The extensions besides plpgsql, each with its schema; the backup keeps the ones it needs. */
|
|
22
|
+
export declare const EXTENSIONS_SQL = "SELECT coalesce(json_agg(json_build_object('oid', x.oid, 'name', x.extname,\n 'schema', n.nspname) ORDER BY x.extname), '[]')\n FROM pg_extension x JOIN pg_namespace n ON n.oid = x.extnamespace WHERE x.extname <> 'plpgsql'";
|
|
23
|
+
/**
|
|
24
|
+
* The extensions something in the schemas needs: a column of citext, a default calling
|
|
25
|
+
* uuid_generate_v4(), an index with pg_trgm's operator class.
|
|
26
|
+
*/
|
|
27
|
+
export declare const NEEDED_EXTENSIONS_SQL = "SELECT coalesce(json_agg(DISTINCT m.refobjid), '[]')\n FROM pg_depend d\n JOIN pg_depend m ON m.classid = d.refclassid AND m.objid = d.refobjid AND m.deptype = 'e'\n AND m.refclassid = 3079\n WHERE d.deptype IN ('n', 'a') AND d.classid IN (1259, 1247, 1255, 2604, 2606, 2618)\n AND NOT EXISTS (SELECT 1 FROM pg_depend e WHERE e.classid = d.classid AND e.objid = d.objid AND e.deptype = 'e')\n AND CASE d.classid\n WHEN 1259 THEN (SELECT relnamespace FROM pg_class WHERE oid = d.objid)\n WHEN 1247 THEN (SELECT typnamespace FROM pg_type WHERE oid = d.objid)\n WHEN 1255 THEN (SELECT pronamespace FROM pg_proc WHERE oid = d.objid)\n WHEN 2604 THEN (SELECT c.relnamespace FROM pg_attrdef a JOIN pg_class c ON c.oid = a.adrelid WHERE a.oid = d.objid)\n WHEN 2606 THEN (SELECT connamespace FROM pg_constraint WHERE oid = d.objid)\n WHEN 2618 THEN (SELECT c.relnamespace FROM pg_rewrite r JOIN pg_class c ON c.oid = r.ev_class WHERE r.oid = d.objid)\n END IN (SELECT oid FROM pg_namespace WHERE nspname = ANY($1))";
|
|
28
|
+
export declare const TYPES_SQL: string;
|
|
29
|
+
export declare const FUNCTIONS_SQL: string;
|
|
30
|
+
/** Sequences of their own; an identity column's comes with its table. */
|
|
31
|
+
export declare const SEQUENCES_SQL: string;
|
|
32
|
+
export declare const TABLES_SQL: string;
|
|
33
|
+
export declare const VIEWS_SQL: string;
|
|
34
|
+
/** Primary keys, unique and exclusion constraints, and foreign keys. */
|
|
35
|
+
export declare const CONSTRAINTS_SQL: string;
|
|
36
|
+
export declare const INDEXES_SQL: string;
|
|
37
|
+
export declare const TRIGGERS_SQL: string;
|
|
38
|
+
/** Rules besides a view's own. */
|
|
39
|
+
export declare const RULES_SQL: string;
|
|
40
|
+
export declare const POLICIES_SQL = "SELECT coalesce(json_agg(json_build_object(\n 'name', p.polname, 'table', p.polrelid, 'command', p.polcmd, 'permissive', p.polpermissive,\n 'roles', (SELECT json_agg(CASE WHEN r = 0 THEN NULL ELSE pg_get_userbyid(r) END) FROM unnest(p.polroles) r),\n 'using', pg_get_expr(p.polqual, p.polrelid), 'check', pg_get_expr(p.polwithcheck, p.polrelid),\n 'comment', obj_description(p.oid, 'pg_policy'))\n ORDER BY n.nspname, c.relname, p.polname), '[]')\n FROM pg_policy p JOIN pg_class c ON c.oid = p.polrelid JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE n.nspname = ANY($1)";
|
|
41
|
+
export declare const STATISTICS_SQL = "SELECT coalesce(json_agg(json_build_object(\n 'name', quote_ident(n.nspname) || '.' || quote_ident(s.stxname),\n 'def', pg_get_statisticsobjdef(s.oid), 'comment', obj_description(s.oid, 'pg_statistic_ext'))\n ORDER BY n.nspname, s.stxname), '[]')\n FROM pg_statistic_ext s JOIN pg_namespace n ON n.oid = s.stxnamespace WHERE n.nspname = ANY($1)";
|
|
42
|
+
/**
|
|
43
|
+
* What depends on what, among the objects a backup creates before its data: [catalog, oid,
|
|
44
|
+
* referenced catalog, referenced oid, how], with column defaults, a view's rule and check
|
|
45
|
+
* constraints standing for their table, view or domain, and a row type for its relation.
|
|
46
|
+
*/
|
|
47
|
+
export declare const DEPENDENCIES_SQL = "SELECT coalesce(json_agg(json_build_array(x.cat, x.oid, x.refcat, x.refoid, x.how)), '[]')\n FROM (\n SELECT DISTINCT\n CASE WHEN d.classid IN (2604, 2618) THEN 1259\n WHEN d.classid = 2606 THEN CASE WHEN co.contypid <> 0 THEN 1247 ELSE 1259 END\n WHEN d.classid = 1259 AND cc.relkind = 'c' THEN 1247\n ELSE d.classid::int END AS cat,\n CASE WHEN d.classid = 2604 THEN ad.adrelid\n WHEN d.classid = 2618 THEN rw.ev_class\n WHEN d.classid = 2606 THEN CASE WHEN co.contypid <> 0 THEN co.contypid ELSE co.conrelid END\n WHEN d.classid = 1259 AND cc.relkind = 'c' THEN cc.reltype\n ELSE d.objid END AS oid,\n CASE WHEN d.refclassid = 1247 AND rc.relkind IS NOT NULL AND rc.relkind <> 'c' THEN 1259\n ELSE d.refclassid::int END AS refcat,\n CASE WHEN d.refclassid = 1247 AND rc.relkind IS NOT NULL AND rc.relkind <> 'c' THEN rc.oid\n WHEN d.refclassid = 1247 AND rt.typcategory = 'A' AND rt.typelem <> 0 THEN rt.typelem\n ELSE d.refobjid END AS refoid,\n CASE WHEN d.classid = 2604 AND att.attgenerated = '' THEN 'default' ELSE 'hard' END AS how\n FROM pg_depend d\n LEFT JOIN pg_attrdef ad ON d.classid = 2604 AND ad.oid = d.objid\n LEFT JOIN pg_attribute att ON att.attrelid = ad.adrelid AND att.attnum = ad.adnum\n LEFT JOIN pg_rewrite rw ON d.classid = 2618 AND rw.oid = d.objid\n LEFT JOIN pg_constraint co ON d.classid = 2606 AND co.oid = d.objid\n LEFT JOIN pg_class cc ON d.classid = 1259 AND cc.oid = d.objid\n LEFT JOIN pg_type rt ON d.refclassid = 1247 AND rt.oid = d.refobjid\n LEFT JOIN pg_class rc ON rc.oid = rt.typrelid\n WHERE d.deptype = 'n' AND d.refclassid IN (1247, 1255, 1259)\n AND (d.classid IN (1247, 1255, 1259, 2604)\n OR (d.classid = 2618 AND rw.rulename = '_RETURN')\n OR (d.classid = 2606 AND co.contype = 'c'))\n ) x";
|