backupdrill 2.9.1 → 2.10.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/README.md +24 -6
- package/dist/auth-backup.d.ts +110 -0
- package/dist/auth-backup.js +383 -0
- package/dist/auth-drill.d.ts +69 -0
- package/dist/auth-drill.js +469 -0
- package/dist/auth-restore.d.ts +120 -0
- package/dist/auth-restore.js +633 -0
- package/dist/backup.d.ts +17 -0
- package/dist/backup.js +379 -25
- package/dist/config.d.ts +9 -0
- package/dist/config.js +17 -0
- package/dist/drill.d.ts +24 -3
- package/dist/drill.js +36 -0
- package/dist/dump-sql.d.ts +6 -0
- package/dist/dump-sql.js +31 -0
- package/dist/external-refs.d.ts +6 -1
- package/dist/external-refs.js +5 -0
- package/dist/grants.d.ts +25 -1
- package/dist/grants.js +53 -13
- package/dist/index.js +67 -3
- package/dist/lib.d.ts +9 -3
- package/dist/lib.js +4 -2
- package/dist/manifest.d.ts +63 -0
- package/dist/manifest.js +78 -0
- package/dist/orphaned-foreign-keys.d.ts +13 -0
- package/dist/orphaned-foreign-keys.js +75 -25
- package/dist/pgbin.d.ts +7 -0
- package/dist/pgbin.js +24 -0
- package/dist/ping.js +1 -0
- package/dist/recovery-doc.d.ts +25 -0
- package/dist/recovery-doc.js +232 -53
- package/dist/restore-engine.d.ts +73 -1
- package/dist/restore-engine.js +155 -77
- package/dist/restore-record.d.ts +47 -0
- package/dist/restore-record.js +57 -0
- package/dist/restore.d.ts +64 -0
- package/dist/restore.js +348 -34
- package/dist/snapshot-store.d.ts +13 -0
- package/dist/snapshot-store.js +25 -0
- package/dist/snapshots.d.ts +2 -0
- package/dist/snapshots.js +10 -3
- package/package.json +1 -1
- package/plugin/README.md +1 -1
- package/plugin/skills/supabase-backup/SKILL.md +7 -7
- package/plugin/skills/supabase-backup/assets/scheduled-backup.yml +6 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Manifest } from "./manifest.js";
|
|
2
|
+
import { type OrphanedForeignKey } from "./orphaned-foreign-keys.js";
|
|
3
|
+
/**
|
|
4
|
+
* 演练里的 Auth 校验(2.10.0 起,附加模式)。
|
|
5
|
+
*
|
|
6
|
+
* 在演练照旧做完、通过与否已经定下之后,在同一个沙箱里:把 auth.dump 的两张表建出来、灌数据,
|
|
7
|
+
* 补上之前因为沙箱没有 auth 表而跳过的外键,建可以自动恢复的触发器,再以 GoTrue 的身份模拟一次注册。
|
|
8
|
+
* 结果只写进报告的 auth 一节,**不改变演练结论**,自己出错也只记在这一节里——上线初期先观察,
|
|
9
|
+
* 是否计入结论由以后决定(PRD 增补 §0.1 第 5 条)。
|
|
10
|
+
*/
|
|
11
|
+
export interface AuthDrillReport {
|
|
12
|
+
/** verified:全部对上;problems:有对不上的地方(见 summary);not_checked:这次没能检查 */
|
|
13
|
+
status: "verified" | "problems" | "not_checked";
|
|
14
|
+
/** 一句给人看的结论 */
|
|
15
|
+
summary: string;
|
|
16
|
+
users?: number;
|
|
17
|
+
identities?: number;
|
|
18
|
+
/** 指向 auth 表的外键:建成的条数、源库本来就有孤儿行(建成 NOT VALID)的、建不出来的 */
|
|
19
|
+
foreignKeys?: {
|
|
20
|
+
created: number;
|
|
21
|
+
orphaned: OrphanedForeignKey[];
|
|
22
|
+
failed: string[];
|
|
23
|
+
};
|
|
24
|
+
triggers?: {
|
|
25
|
+
created: string[];
|
|
26
|
+
failed: string[];
|
|
27
|
+
};
|
|
28
|
+
/** 不会自动恢复、要人手处理的对象 */
|
|
29
|
+
manual?: string[];
|
|
30
|
+
/** 没验证到的部分,例如触发器还响应模拟注册之外的事件 */
|
|
31
|
+
notes?: string[];
|
|
32
|
+
/** 模拟注册:ran=false 时说明为什么没跑 */
|
|
33
|
+
signup?: {
|
|
34
|
+
ran: boolean;
|
|
35
|
+
ok?: boolean;
|
|
36
|
+
detail?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface AuthDumpForDrill {
|
|
40
|
+
/** 下载到本地的 auth.dump;下载失败时为空,error 说明原因 */
|
|
41
|
+
path?: string;
|
|
42
|
+
error?: string;
|
|
43
|
+
}
|
|
44
|
+
/** SQLSTATE → 固定说法 + 代码本身;不是合法的 SQLSTATE 就说"意外错误"。恢复端写 Auth 数据出错时也用它 */
|
|
45
|
+
export declare function describeSqlstate(code: unknown): string;
|
|
46
|
+
export declare function runAuthDrill(sandboxConnString: string, manifest: Manifest, mainDumpPath: string, authDump: AuthDumpForDrill, signal?: AbortSignal): Promise<AuthDrillReport>;
|
|
47
|
+
/**
|
|
48
|
+
* 终止 Auth 这一节在沙箱里开的会话(按 application_name 认),别人的会话不动。
|
|
49
|
+
* 整个过程(连接、查询、断开)有硬时限:到点直接销毁 socket,沙箱没回应也挂不住进程
|
|
50
|
+
*/
|
|
51
|
+
export declare function stopAuthSessions(sandboxConnString: string, deadlineMs?: number): Promise<void>;
|
|
52
|
+
/** Auth 这一节最多花多久(下载等待 + 恢复两张表 + 外键 + 触发器 + 模拟注册);到点记 not_checked */
|
|
53
|
+
export declare const AUTH_DRILL_LIMITS: {
|
|
54
|
+
totalMs: number;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 演练里调用:任何异常、超时都收进报告,绝不让演练因为 Auth 这一节抛错或拖住。
|
|
58
|
+
* authDump 是个 Promise:下载和正式演练同时进行,这里才等它。到点就不等了,沙箱随后照常销毁,
|
|
59
|
+
* 还在跑的 pg_restore 跟着断开
|
|
60
|
+
*/
|
|
61
|
+
export declare function authDrillSection(sandboxConnString: string, manifest: Manifest, mainDumpPath: string, authDump: Promise<AuthDumpForDrill> | undefined, stopDownload?: () => void,
|
|
62
|
+
/**
|
|
63
|
+
* 托管 worker:begin 在开始前告诉它进入 Auth 阶段(被拒绝就不做这一节);stop 是它叫停这一节的信号。
|
|
64
|
+
* 两者都只影响这一节,演练结论不变
|
|
65
|
+
*/
|
|
66
|
+
runner?: {
|
|
67
|
+
begin?: () => Promise<void>;
|
|
68
|
+
stop?: AbortSignal;
|
|
69
|
+
}): Promise<AuthDrillReport | undefined>;
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { connectCancellable, manualAuthObjects, restorableAuthObjects } from "./auth-backup.js";
|
|
7
|
+
import { parseForeignKeys } from "./dump-sql.js";
|
|
8
|
+
import { addForeignKeys } from "./orphaned-foreign-keys.js";
|
|
9
|
+
import { resolvePgRestoreBin } from "./pgbin.js";
|
|
10
|
+
import { credentialSafeDbArgs, pgRestoreOutput, spawnPgRestore } from "./restore-engine.js";
|
|
11
|
+
import { interrupted } from "./interrupt.js";
|
|
12
|
+
// 报告会发给用户、进运营者告警,**一律不放报错原文**:触发器能在任何错误码下抛出自定义消息、
|
|
13
|
+
// 伪造对象名字段,里面可以是任意数据,靠脱敏堵不干净。只给 SQLSTATE 映射出的固定说法和 SQLSTATE 本身
|
|
14
|
+
const SQLSTATE_TEXT = {
|
|
15
|
+
"42501": "permission denied",
|
|
16
|
+
"42P01": "a table doesn't exist",
|
|
17
|
+
"42883": "a function doesn't exist",
|
|
18
|
+
"42703": "a column doesn't exist",
|
|
19
|
+
"3F000": "a schema doesn't exist",
|
|
20
|
+
"42P07": "a table already exists",
|
|
21
|
+
"42710": "an object already exists",
|
|
22
|
+
"23503": "a foreign key was violated",
|
|
23
|
+
"23505": "a unique constraint was violated",
|
|
24
|
+
"23502": "a not-null constraint was violated",
|
|
25
|
+
"23514": "a check constraint was violated",
|
|
26
|
+
"42804": "a data type didn't match",
|
|
27
|
+
"55P03": "a lock wait timed out",
|
|
28
|
+
"57014": "a statement timed out or was cancelled",
|
|
29
|
+
"40P01": "a deadlock",
|
|
30
|
+
P0001: "an exception was raised",
|
|
31
|
+
};
|
|
32
|
+
function safeError(error) {
|
|
33
|
+
// 只用 SQLSTATE:触发器能用 RAISE ... USING 伪造 TABLE / COLUMN / CONSTRAINT 这些字段,它们同样不可信
|
|
34
|
+
return describeSqlstate(error?.code);
|
|
35
|
+
}
|
|
36
|
+
/** SQLSTATE → 固定说法 + 代码本身;不是合法的 SQLSTATE 就说"意外错误"。恢复端写 Auth 数据出错时也用它 */
|
|
37
|
+
export function describeSqlstate(code) {
|
|
38
|
+
if (typeof code !== "string" || !/^[0-9A-Z]{5}$/.test(code))
|
|
39
|
+
return "an unexpected error";
|
|
40
|
+
return `${SQLSTATE_TEXT[code] ?? "an error"} (SQLSTATE ${code})`;
|
|
41
|
+
}
|
|
42
|
+
/** pg_restore 的 stderr 是一段文字,拿不到 SQLSTATE:只归成几类,不带原文 */
|
|
43
|
+
function safeRestoreError(code, stderr) {
|
|
44
|
+
const categories = [
|
|
45
|
+
[/already exists/i, "an object it creates already exists"],
|
|
46
|
+
[/does not exist/i, "something it refers to doesn't exist"],
|
|
47
|
+
[/permission denied|must be owner/i, "permission denied"],
|
|
48
|
+
[/violates/i, "a constraint was violated"],
|
|
49
|
+
[/no space left|out of memory|could not extend file/i, "the sandbox ran out of resources"],
|
|
50
|
+
];
|
|
51
|
+
const category = categories.find(([re]) => re.test(stderr))?.[1];
|
|
52
|
+
return `${category ? `${category} ` : ""}(pg_restore exited with code ${code})`;
|
|
53
|
+
}
|
|
54
|
+
async function sha256Of(path) {
|
|
55
|
+
const hash = createHash("sha256");
|
|
56
|
+
for await (const chunk of createReadStream(path))
|
|
57
|
+
hash.update(chunk);
|
|
58
|
+
return hash.digest("hex");
|
|
59
|
+
}
|
|
60
|
+
// pg_restore -l 的条目行:"<id>; <oid> <oid> <类型> <schema> <名字> <属主>"
|
|
61
|
+
const tocType = (line) => /^\d+; \d+ \d+ (.+)$/.exec(line)?.[1] ?? null;
|
|
62
|
+
const SIGNUP_USER_ID = "00000000-0000-4000-8000-00000000d211";
|
|
63
|
+
const SIGNUP_EMAIL = "drill-signup@backupdrill.invalid";
|
|
64
|
+
/** 测试注册不带用户元数据:应用注册时会传、触发器又要用的字段,这次没测到,报告里说清楚 */
|
|
65
|
+
const SIGNUP_TESTED_AS = " (tested as an email sign-up with no user metadata)";
|
|
66
|
+
/** 给 NOT NULL 又没有默认值的列造一个合法的值;造不出来返回 null(就不模拟了) */
|
|
67
|
+
function syntheticValue(type, column) {
|
|
68
|
+
if (column === "id" || column === "user_id")
|
|
69
|
+
return `'${SIGNUP_USER_ID}'::uuid`;
|
|
70
|
+
if (column === "email")
|
|
71
|
+
return `'${SIGNUP_EMAIL}'`;
|
|
72
|
+
if (column === "provider")
|
|
73
|
+
return "'email'";
|
|
74
|
+
if (column === "provider_id")
|
|
75
|
+
return `'${SIGNUP_USER_ID}'`;
|
|
76
|
+
if (column === "identity_data")
|
|
77
|
+
return `jsonb_build_object('sub', '${SIGNUP_USER_ID}', 'email', '${SIGNUP_EMAIL}')`;
|
|
78
|
+
// 和 GoTrue 邮箱注册那条 INSERT 一样(internal/api/signup.go):AFTER INSERT 触发器看到的就是这些。
|
|
79
|
+
// app 元数据在插入前就写好了 provider;用户元数据只有客户端随注册传的 data,不传就是 {}——
|
|
80
|
+
// sub、email、email_verified 是同一事务里稍后 UPDATE 进去的,插入那一刻还没有
|
|
81
|
+
if (column === "raw_app_meta_data")
|
|
82
|
+
return `jsonb_build_object('provider', 'email', 'providers', jsonb_build_array('email'))`;
|
|
83
|
+
if (column === "raw_user_meta_data")
|
|
84
|
+
return "'{}'::jsonb";
|
|
85
|
+
if (column === "created_at" || column === "updated_at")
|
|
86
|
+
return "now()";
|
|
87
|
+
if (/^uuid$/.test(type))
|
|
88
|
+
return "'00000000-0000-4000-8000-000000000001'::uuid";
|
|
89
|
+
if (/^(text|character varying|character)\b/.test(type))
|
|
90
|
+
return "'drill'";
|
|
91
|
+
if (/^jsonb?$/.test(type))
|
|
92
|
+
return "'{}'";
|
|
93
|
+
if (/^boolean$/.test(type))
|
|
94
|
+
return "false";
|
|
95
|
+
if (/^(timestamp|date)/.test(type))
|
|
96
|
+
return "now()";
|
|
97
|
+
if (/^(smallint|integer|bigint|numeric|real|double precision)/.test(type))
|
|
98
|
+
return "0";
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
async function insertStatement(client, table) {
|
|
102
|
+
const cols = await client.query(`select a.attname as name, format_type(a.atttypid, a.atttypmod) as type,
|
|
103
|
+
(a.attnotnull and not a.atthasdef and a.attgenerated = '') as required
|
|
104
|
+
from pg_attribute a
|
|
105
|
+
where a.attrelid = $1::regclass and a.attnum > 0 and not a.attisdropped
|
|
106
|
+
order by a.attnum`, [`auth.${table}`]);
|
|
107
|
+
// 一次正常注册会写的几列总带上;再补齐所有必填列
|
|
108
|
+
const wanted = new Set(table === "users"
|
|
109
|
+
? ["id", "email", "raw_user_meta_data", "raw_app_meta_data", "aud", "role", "created_at", "updated_at"]
|
|
110
|
+
: ["user_id", "provider", "provider_id", "identity_data", "created_at", "updated_at"]);
|
|
111
|
+
const names = [];
|
|
112
|
+
const values = [];
|
|
113
|
+
for (const c of cols.rows) {
|
|
114
|
+
if (!c.required && !wanted.has(c.name))
|
|
115
|
+
continue;
|
|
116
|
+
let value = syntheticValue(c.type, c.name);
|
|
117
|
+
if (c.name === "aud" || c.name === "role")
|
|
118
|
+
value = "'authenticated'";
|
|
119
|
+
if (value === null) {
|
|
120
|
+
if (c.required)
|
|
121
|
+
return null;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
names.push(`"${c.name.replace(/"/g, '""')}"`);
|
|
125
|
+
values.push(value);
|
|
126
|
+
}
|
|
127
|
+
return `insert into auth.${table} (${names.join(", ")}) values (${values.join(", ")})`;
|
|
128
|
+
}
|
|
129
|
+
export async function runAuthDrill(sandboxConnString, manifest, mainDumpPath, authDump, signal) {
|
|
130
|
+
const auth = manifest.auth;
|
|
131
|
+
// 这一节的所有会话都带上 application_name,超时时 authDrillSection 只终止它们
|
|
132
|
+
sandboxConnString = taggedUrl(sandboxConnString);
|
|
133
|
+
// 叫停(超时)之后:不再开始任何新的一步;已经开着的连接被 connectCancellable 直接断开,
|
|
134
|
+
// 正在跑的 pg_restore 被 spawnPgRestore 停掉。服务端还没收手的会话由 authDrillSection 事后终止
|
|
135
|
+
const stopIfCancelled = () => {
|
|
136
|
+
if (signal?.aborted)
|
|
137
|
+
throw new Error("the Auth check was stopped");
|
|
138
|
+
};
|
|
139
|
+
if (authDump.error || !authDump.path) {
|
|
140
|
+
return { status: "not_checked", summary: authDump.error ?? "the Auth archive couldn't be downloaded" };
|
|
141
|
+
}
|
|
142
|
+
const sha = await sha256Of(authDump.path);
|
|
143
|
+
if (sha !== auth.dump.sha256) {
|
|
144
|
+
return {
|
|
145
|
+
status: "problems",
|
|
146
|
+
summary: `Auth archive sha256 mismatch — got ${sha.slice(0, 12)}…, manifest ${auth.dump.sha256.slice(0, 12)}…`,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const bin = resolvePgRestoreBin();
|
|
150
|
+
const { url, env } = credentialSafeDbArgs(sandboxConnString);
|
|
151
|
+
const work = await mkdtemp(join(tmpdir(), "backupdrill-auth-drill-"));
|
|
152
|
+
let client;
|
|
153
|
+
try {
|
|
154
|
+
// connectCancellable 挂好了错误监听(沙箱连接被掐断时不会把托管 worker 带走),叫停时直接断开
|
|
155
|
+
stopIfCancelled();
|
|
156
|
+
client = await connectCancellable(sandboxConnString, signal);
|
|
157
|
+
stopIfCancelled();
|
|
158
|
+
// 每条语句都有上限(整段另有总时限,见 authDrillSection)
|
|
159
|
+
await client.query("set statement_timeout = '5min'; set lock_timeout = '1min'");
|
|
160
|
+
// ── 1. 两张表:结构、数据、约束、索引;触发器和策略留到外键之后 ──
|
|
161
|
+
// 新项目里这两张表的属主是平台的 supabase_auth_admin,GoTrue 也用它注册用户:沙箱里照建
|
|
162
|
+
await client.query(`do $$ begin
|
|
163
|
+
if not exists (select 1 from pg_roles where rolname = 'supabase_auth_admin') then
|
|
164
|
+
create role supabase_auth_admin nologin;
|
|
165
|
+
end if; end $$;
|
|
166
|
+
create schema if not exists auth;
|
|
167
|
+
grant usage on schema auth to supabase_auth_admin`);
|
|
168
|
+
stopIfCancelled();
|
|
169
|
+
const listing = await pgRestoreOutput(bin, ["--list", authDump.path], { signal });
|
|
170
|
+
if (listing.code !== 0) {
|
|
171
|
+
return { status: "problems", summary: `Auth archive couldn't be listed: ${safeRestoreError(listing.code, listing.stderr)}` };
|
|
172
|
+
}
|
|
173
|
+
const entries = listing.stdout.split("\n").filter((l) => /^\d+;/.test(l));
|
|
174
|
+
const tablesList = join(work, "auth-tables.list");
|
|
175
|
+
await writeFile(tablesList,
|
|
176
|
+
// 触发器、策略和它们的注释都留到后面(注释先于对象执行会让整个恢复中止);注释不影响功能,干脆不建
|
|
177
|
+
entries.filter((l) => !/^(TRIGGER|POLICY) |^COMMENT \S+ (TRIGGER|POLICY) /.test(tocType(l) ?? "")).join("\n") + "\n");
|
|
178
|
+
stopIfCancelled();
|
|
179
|
+
const restored = await spawnPgRestore(bin, ["--no-owner", "--no-privileges", "--exit-on-error", "--single-transaction", `--use-list=${tablesList}`, "--dbname", url, authDump.path], env, { supabaseHost: false, signal });
|
|
180
|
+
if (restored.code !== 0) {
|
|
181
|
+
return { status: "problems", summary: `the Auth tables couldn't be restored: ${safeRestoreError(restored.code, restored.stderr)}` };
|
|
182
|
+
}
|
|
183
|
+
const counts = await client.query("select (select count(*) from auth.users) as users, (select count(*) from auth.identities) as identities");
|
|
184
|
+
const users = Number(counts.rows[0].users);
|
|
185
|
+
const identities = Number(counts.rows[0].identities);
|
|
186
|
+
const problems = [];
|
|
187
|
+
if (users !== auth.rows.users || identities !== auth.rows.identities) {
|
|
188
|
+
problems.push(`restored ${users} users / ${identities} identities, but the backup counted ${auth.rows.users} / ${auth.rows.identities}`);
|
|
189
|
+
}
|
|
190
|
+
// ── 2. 之前因为沙箱没有 auth 表而跳过的外键:现在补上 ──
|
|
191
|
+
stopIfCancelled();
|
|
192
|
+
const mainListing = await pgRestoreOutput(bin, ["--list", mainDumpPath], { signal });
|
|
193
|
+
let foreignKeys = { created: 0, orphaned: [], failed: [] };
|
|
194
|
+
if (mainListing.code !== 0)
|
|
195
|
+
problems.push("the database archive couldn't be listed, so its foreign keys into the Auth tables weren't checked");
|
|
196
|
+
if (mainListing.code === 0) {
|
|
197
|
+
const fkEntries = mainListing.stdout.split("\n").filter((l) => /^FK CONSTRAINT /.test(tocType(l) ?? ""));
|
|
198
|
+
if (fkEntries.length) {
|
|
199
|
+
const fkList = join(work, "fks.list");
|
|
200
|
+
await writeFile(fkList, fkEntries.join("\n") + "\n");
|
|
201
|
+
stopIfCancelled();
|
|
202
|
+
const ddl = await pgRestoreOutput(bin, ["-f", "-", `--use-list=${fkList}`, mainDumpPath], { signal });
|
|
203
|
+
const parsed = ddl.code === 0 ? parseForeignKeys(ddl.stdout) : [];
|
|
204
|
+
// 读不全外键定义(命令失败,或有定义没解析出来)时不能说"全部对上":把没能检查的条数记下来
|
|
205
|
+
if (parsed.length !== fkEntries.length) {
|
|
206
|
+
problems.push(`${fkEntries.length - parsed.length} foreign key definition(s) couldn't be read, so they weren't checked`);
|
|
207
|
+
}
|
|
208
|
+
const intoAuth = parsed.filter((fk) => fk.references.schema === "auth" && (fk.references.name === "users" || fk.references.name === "identities"));
|
|
209
|
+
// 已经建上的(例如转储自己带了 auth)不再重复
|
|
210
|
+
// 约束名只在同一张表内唯一:按"schema.表.约束名"判断是否已经建上
|
|
211
|
+
const existing = new Set((await client.query(`select n.nspname || '.' || c.relname || '.' || con.conname as key
|
|
212
|
+
from pg_constraint con
|
|
213
|
+
join pg_class c on c.oid = con.conrelid
|
|
214
|
+
join pg_namespace n on n.oid = c.relnamespace
|
|
215
|
+
where con.contype = 'f' and con.confrelid in ('auth.users'::regclass, 'auth.identities'::regclass)`)).rows.map((r) => r.key));
|
|
216
|
+
const missing = intoAuth.filter((fk) => !existing.has(`${fk.table.schema}.${fk.table.name}.${fk.constraint}`));
|
|
217
|
+
if (missing.length) {
|
|
218
|
+
// addForeignKeys 会改这条连接的会话设置(search_path 等),给它单独一条
|
|
219
|
+
stopIfCancelled();
|
|
220
|
+
const fkClient = await connectCancellable(sandboxConnString, signal);
|
|
221
|
+
try {
|
|
222
|
+
const added = await addForeignKeys(fkClient, missing, { allow: /(?!)/, stopOnError: false });
|
|
223
|
+
foreignKeys = {
|
|
224
|
+
created: missing.length - added.failures.length,
|
|
225
|
+
orphaned: added.orphaned,
|
|
226
|
+
// 只留"哪条外键、在哪张表上",消息本身不进报告
|
|
227
|
+
failed: added.failures.map((f) => f.split(": ")[0]),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
await fkClient.end().catch(() => { });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (foreignKeys.failed.length)
|
|
237
|
+
problems.push(`${foreignKeys.failed.length} foreign key(s) into the Auth tables couldn't be created`);
|
|
238
|
+
// ── 3. 可以自动恢复的触发器(规则同真实恢复,见 restorableAuthObjects) ──
|
|
239
|
+
const restorable = restorableAuthObjects({ triggers: auth.triggers, policies: auth.policies }, manifest.database.schemas);
|
|
240
|
+
const manual = manualAuthObjects({ triggers: auth.triggers, policies: auth.policies }, manifest.database.schemas);
|
|
241
|
+
const triggers = { created: [], failed: [] };
|
|
242
|
+
for (const t of restorable.triggers) {
|
|
243
|
+
// 名字都是普通标识符(restorableAuthObjects 保证),按前缀匹配不会认错
|
|
244
|
+
const entry = entries.find((l) => (tocType(l) ?? "").startsWith(`TRIGGER auth ${t.table} ${t.name} `));
|
|
245
|
+
if (!entry) {
|
|
246
|
+
triggers.failed.push(`${t.name}: not found in the Auth archive`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const list = join(work, `trigger-${t.name}.list`);
|
|
250
|
+
await writeFile(list, entry + "\n");
|
|
251
|
+
stopIfCancelled();
|
|
252
|
+
const made = await spawnPgRestore(bin, ["--no-owner", "--no-privileges", "--exit-on-error", `--use-list=${list}`, "--dbname", url, authDump.path], env, {
|
|
253
|
+
supabaseHost: false,
|
|
254
|
+
signal,
|
|
255
|
+
});
|
|
256
|
+
if (made.code === 0)
|
|
257
|
+
triggers.created.push(t.name);
|
|
258
|
+
else
|
|
259
|
+
triggers.failed.push(`${t.name}: ${safeRestoreError(made.code, made.stderr)}`);
|
|
260
|
+
}
|
|
261
|
+
if (triggers.failed.length)
|
|
262
|
+
problems.push(`${triggers.failed.length} trigger(s) on the Auth tables couldn't be recreated`);
|
|
263
|
+
// 模拟注册只是 INSERT:同样响应 UPDATE / DELETE / TRUNCATE 的触发器,那些事件没验证到,明说
|
|
264
|
+
const notes = [];
|
|
265
|
+
if (triggers.created.length) {
|
|
266
|
+
const events = await client.query(`select t.tgname as name, c.relname as table, t.tgtype::int as tgtype
|
|
267
|
+
from pg_trigger t join pg_class c on c.oid = t.tgrelid
|
|
268
|
+
where c.oid in ('auth.users'::regclass, 'auth.identities'::regclass) and t.tgname = any($1::text[])`, [triggers.created]);
|
|
269
|
+
for (const e of events.rows) {
|
|
270
|
+
const other = [
|
|
271
|
+
e.tgtype & 8 ? "DELETE" : "",
|
|
272
|
+
e.tgtype & 16 ? "UPDATE" : "",
|
|
273
|
+
e.tgtype & 32 ? "TRUNCATE" : "",
|
|
274
|
+
].filter(Boolean);
|
|
275
|
+
if (other.length)
|
|
276
|
+
notes.push(`trigger ${e.name} on auth.${e.table} also fires on ${other.join(", ")}, which the test sign-up doesn't exercise`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
stopIfCancelled();
|
|
280
|
+
// ── 4. 以 GoTrue 的身份(supabase_auth_admin,非超级用户)模拟一次邮箱注册,事后回滚 ──
|
|
281
|
+
let signup = { ran: false, detail: "no triggers of your own on the Auth tables" };
|
|
282
|
+
if (triggers.created.length) {
|
|
283
|
+
await client.query("alter table auth.users owner to supabase_auth_admin; alter table auth.identities owner to supabase_auth_admin");
|
|
284
|
+
const userInsert = await insertStatement(client, "users");
|
|
285
|
+
const identityInsert = await insertStatement(client, "identities");
|
|
286
|
+
if (!userInsert || !identityInsert) {
|
|
287
|
+
signup = { ran: false, detail: "couldn't build a test sign-up for this Auth table layout" };
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
await client.query("begin");
|
|
291
|
+
try {
|
|
292
|
+
await client.query("set local role supabase_auth_admin");
|
|
293
|
+
await client.query(userInsert);
|
|
294
|
+
await client.query(identityInsert);
|
|
295
|
+
// 延迟检查的约束和约束触发器平时在提交时才跑:这里立刻跑完,才算这次注册真的能成
|
|
296
|
+
await client.query("set constraints all immediate");
|
|
297
|
+
signup = { ran: true, ok: true };
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
const e = error;
|
|
301
|
+
// 只有错在触发器里才算触发器的问题;造的测试行本身不合表结构,算没模拟成
|
|
302
|
+
const triggerPath = /PL\/pgSQL function|SQL function|trigger/i.test(e.where ?? "") ||
|
|
303
|
+
["23503", "23505", "42501", "42883", "42P01", "42703", "3F000", "P0001"].includes(e.code ?? "");
|
|
304
|
+
signup = triggerPath
|
|
305
|
+
? { ran: true, ok: false, detail: `a new sign-up would fail: ${safeError(e)}${SIGNUP_TESTED_AS}` }
|
|
306
|
+
: { ran: false, detail: `couldn't simulate a sign-up: ${safeError(e)}` };
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
await client.query("rollback").catch(() => { });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (signup.ran && !signup.ok)
|
|
313
|
+
problems.push(signup.detail);
|
|
314
|
+
// 有要验证的触发器,却没能模拟成注册:不能报"全部对上"
|
|
315
|
+
if (!signup.ran)
|
|
316
|
+
problems.push(`the test sign-up couldn't run (${signup.detail})`);
|
|
317
|
+
}
|
|
318
|
+
const parts = [
|
|
319
|
+
`${users.toLocaleString("en-US")} users restored (${identities.toLocaleString("en-US")} identities)`,
|
|
320
|
+
foreignKeys.created ? `${foreignKeys.created} foreign key(s) into the Auth tables created` : "",
|
|
321
|
+
foreignKeys.orphaned.length ? `${foreignKeys.orphaned.length} of them with rows that have no user at the source` : "",
|
|
322
|
+
triggers.created.length ? `${triggers.created.length} trigger(s) recreated` : "",
|
|
323
|
+
signup.ran && signup.ok ? "a test sign-up worked" : "",
|
|
324
|
+
manual.length ? `${manual.length} object(s) need recreating by hand` : "",
|
|
325
|
+
].filter(Boolean);
|
|
326
|
+
return {
|
|
327
|
+
status: problems.length ? "problems" : "verified",
|
|
328
|
+
summary: problems.length ? `${problems.join("; ")}. ${parts.join("; ")}` : parts.join("; "),
|
|
329
|
+
users,
|
|
330
|
+
identities,
|
|
331
|
+
foreignKeys,
|
|
332
|
+
triggers,
|
|
333
|
+
...(manual.length ? { manual } : {}),
|
|
334
|
+
...(notes.length ? { notes } : {}),
|
|
335
|
+
signup,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
finally {
|
|
339
|
+
await client?.end().catch(() => { });
|
|
340
|
+
await rm(work, { recursive: true, force: true }).catch(() => { });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/** Auth 这一节在沙箱里开的每个会话(查询连接、pg_restore)都带这个名字,超时时只终止它们 */
|
|
344
|
+
const AUTH_DRILL_APP_NAME = "backupdrill-auth-drill";
|
|
345
|
+
function taggedUrl(connString) {
|
|
346
|
+
const url = new URL(connString);
|
|
347
|
+
url.searchParams.set("application_name", AUTH_DRILL_APP_NAME);
|
|
348
|
+
return url.toString();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* 终止 Auth 这一节在沙箱里开的会话(按 application_name 认),别人的会话不动。
|
|
352
|
+
* 整个过程(连接、查询、断开)有硬时限:到点直接销毁 socket,沙箱没回应也挂不住进程
|
|
353
|
+
*/
|
|
354
|
+
export async function stopAuthSessions(sandboxConnString, deadlineMs = 10_000) {
|
|
355
|
+
try {
|
|
356
|
+
const client = await connectCancellable(sandboxConnString, AbortSignal.timeout(deadlineMs));
|
|
357
|
+
try {
|
|
358
|
+
await client.query("select pg_terminate_backend(pid) from pg_stat_activity where application_name = $1 and pid <> pg_backend_pid()", [AUTH_DRILL_APP_NAME]);
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
await client.end().catch(() => { });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
// 沙箱可能已经不在了,或者到点了:没什么能再做的
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async function waitAtMost(p, ms) {
|
|
369
|
+
let t;
|
|
370
|
+
await Promise.race([p.then(() => { }, () => { }), new Promise((resolve) => (t = setTimeout(resolve, ms)))]);
|
|
371
|
+
clearTimeout(t);
|
|
372
|
+
}
|
|
373
|
+
/** Auth 这一节最多花多久(下载等待 + 恢复两张表 + 外键 + 触发器 + 模拟注册);到点记 not_checked */
|
|
374
|
+
export const AUTH_DRILL_LIMITS = { totalMs: 15 * 60 * 1000 };
|
|
375
|
+
/**
|
|
376
|
+
* 演练里调用:任何异常、超时都收进报告,绝不让演练因为 Auth 这一节抛错或拖住。
|
|
377
|
+
* authDump 是个 Promise:下载和正式演练同时进行,这里才等它。到点就不等了,沙箱随后照常销毁,
|
|
378
|
+
* 还在跑的 pg_restore 跟着断开
|
|
379
|
+
*/
|
|
380
|
+
export async function authDrillSection(sandboxConnString, manifest, mainDumpPath, authDump, stopDownload,
|
|
381
|
+
/**
|
|
382
|
+
* 托管 worker:begin 在开始前告诉它进入 Auth 阶段(被拒绝就不做这一节);stop 是它叫停这一节的信号。
|
|
383
|
+
* 两者都只影响这一节,演练结论不变
|
|
384
|
+
*/
|
|
385
|
+
runner = {}) {
|
|
386
|
+
if (manifest.auth?.status !== "included" || !authDump)
|
|
387
|
+
return undefined;
|
|
388
|
+
if (interrupted())
|
|
389
|
+
return undefined;
|
|
390
|
+
// 不管从哪条路提前退出,下载那边后来的失败都得有人接住(没人接的 rejection 会把 worker 带走)
|
|
391
|
+
authDump.catch(() => { });
|
|
392
|
+
const stoppedByRunner = () => {
|
|
393
|
+
const why = runner.stop?.reason;
|
|
394
|
+
return {
|
|
395
|
+
status: "not_checked",
|
|
396
|
+
summary: `the drill runner stopped the Auth check${typeof why === "string" && why ? ` (${why})` : ""}`,
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
const timedOut = {
|
|
400
|
+
status: "not_checked",
|
|
401
|
+
summary: `the Auth check didn't finish within ${AUTH_DRILL_LIMITS.totalMs / 60000} minutes`,
|
|
402
|
+
};
|
|
403
|
+
const cancel = new AbortController();
|
|
404
|
+
let work;
|
|
405
|
+
// 叫停(超时或 supervisor):不再开始任何新的一步,自己的连接、pg_restore、下载当场停掉;
|
|
406
|
+
// 已经开始的那部分,收尾放到后台:等它真正退出,再把服务端还没收手的会话终止掉——
|
|
407
|
+
// --keep 留下的沙箱事后不会再被改动
|
|
408
|
+
const halt = () => {
|
|
409
|
+
cancel.abort();
|
|
410
|
+
stopDownload?.();
|
|
411
|
+
const started = work;
|
|
412
|
+
if (started) {
|
|
413
|
+
void (async () => {
|
|
414
|
+
await waitAtMost(started, 10_000);
|
|
415
|
+
await stopAuthSessions(sandboxConnString);
|
|
416
|
+
})();
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
let timer;
|
|
420
|
+
let onRunnerStop;
|
|
421
|
+
try {
|
|
422
|
+
// 叫停和时限在进入 Auth 阶段之前就装好:supervisor 迟迟不回 begin 时同样能叫停、同样到点放弃
|
|
423
|
+
return await Promise.race([
|
|
424
|
+
(async () => {
|
|
425
|
+
if (runner.begin) {
|
|
426
|
+
try {
|
|
427
|
+
await runner.begin();
|
|
428
|
+
}
|
|
429
|
+
catch {
|
|
430
|
+
stopDownload?.();
|
|
431
|
+
return { status: "not_checked", summary: "the drill runner didn't allow the Auth check this time" };
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
// 等 begin 的时候已经被叫停或到点了:比赛已经有了结果,这里不再开始
|
|
435
|
+
if (cancel.signal.aborted)
|
|
436
|
+
return stoppedByRunner();
|
|
437
|
+
work = runAuthDrill(sandboxConnString, manifest, mainDumpPath, await authDump, cancel.signal);
|
|
438
|
+
return await work;
|
|
439
|
+
})(),
|
|
440
|
+
new Promise((resolve) => {
|
|
441
|
+
if (!runner.stop)
|
|
442
|
+
return;
|
|
443
|
+
onRunnerStop = () => {
|
|
444
|
+
halt();
|
|
445
|
+
resolve(stoppedByRunner());
|
|
446
|
+
};
|
|
447
|
+
if (runner.stop.aborted)
|
|
448
|
+
onRunnerStop();
|
|
449
|
+
else
|
|
450
|
+
runner.stop.addEventListener("abort", onRunnerStop, { once: true });
|
|
451
|
+
}),
|
|
452
|
+
new Promise((resolve) => {
|
|
453
|
+
timer = setTimeout(() => {
|
|
454
|
+
// 超时结果立刻返回,收尾在后台、每一步都有时限,绝不让演练等它
|
|
455
|
+
halt();
|
|
456
|
+
resolve(timedOut);
|
|
457
|
+
}, AUTH_DRILL_LIMITS.totalMs);
|
|
458
|
+
}),
|
|
459
|
+
]);
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
return { status: "not_checked", summary: `the Auth check couldn't run: ${safeError(error)}` };
|
|
463
|
+
}
|
|
464
|
+
finally {
|
|
465
|
+
clearTimeout(timer);
|
|
466
|
+
if (onRunnerStop)
|
|
467
|
+
runner.stop?.removeEventListener("abort", onRunnerStop);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { AuthSection, ExtensionInfo, Manifest } from "./manifest.js";
|
|
2
|
+
import { afterCommit, type GrantsToRestore } from "./restore-engine.js";
|
|
3
|
+
/**
|
|
4
|
+
* 恢复后要清掉的待处理认证状态,和 GoTrue 的 ClearAllPendingTokens 对齐:备份时发出去的找回密码、邮箱确认、
|
|
5
|
+
* 改邮箱改手机的链接和验证码,在新项目上一律作废。RECOVERY.md 的手工步骤用同一句
|
|
6
|
+
*/
|
|
7
|
+
export declare const CLEAR_PENDING_AUTH_SQL: string;
|
|
8
|
+
/** auth.dump 里恢复要用的东西:两段数据的目录行、要补建的触发器、数据段的列 */
|
|
9
|
+
export interface AuthArchive {
|
|
10
|
+
path: string;
|
|
11
|
+
usersData: string;
|
|
12
|
+
identitiesData: string;
|
|
13
|
+
triggers: Array<{
|
|
14
|
+
name: string;
|
|
15
|
+
entry: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** 数据段里的列和类型(建表语句的列减去生成列,pg_dump 不导出生成列) */
|
|
18
|
+
columns: Record<"users" | "identities", Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
}>>;
|
|
22
|
+
}
|
|
23
|
+
/** 读 auth.dump 的目录和两张表的建表语句。不碰目标 */
|
|
24
|
+
export declare function readAuthArchive(path: string, manifest: Manifest, workDir: string): Promise<AuthArchive>;
|
|
25
|
+
/**
|
|
26
|
+
* 只读预检(dry-run 和正式执行共用):目标得是一个新项目的 Auth——两张表在、没有用户、没有用户自己的触发器和策略,
|
|
27
|
+
* 列能装下备份的数据。返回拦下的原因,空数组 = 能恢复
|
|
28
|
+
*/
|
|
29
|
+
export declare function authRestorePreflight(targetUrl: string, archive: AuthArchive): Promise<string[]>;
|
|
30
|
+
/**
|
|
31
|
+
* 主 dump 里的大对象。pg_restore 输出 SQL 时会在它们前后自己写 BEGIN; / COMMIT;,混进这个事务就会提前提交。
|
|
32
|
+
* 有的话这条路不能走,由调用方拦下。备份端的主 dump 总带 --schema,pg_dump 这时默认不导出大对象,
|
|
33
|
+
* 所以正常的快照里不会有:这是兜底,防的是别处来的归档
|
|
34
|
+
*/
|
|
35
|
+
export declare function largeObjectEntries(dumpPath: string): Promise<number>;
|
|
36
|
+
export declare function emitsRestrict([major, minor]: [number, number]): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* psql 要能安全地执行 pg_restore 写出来的 SQL:pg_restore 得是带 \restrict 的版本,psql 和它同一个客户端包、
|
|
39
|
+
* 不比它旧(旧 psql 不认识 \restrict)。返回拦下的原因,null = 可以
|
|
40
|
+
*/
|
|
41
|
+
export declare function psqlProblem(): Promise<string | null>;
|
|
42
|
+
/**
|
|
43
|
+
* pg_restore -f - 的输出开头:第一条不是注释、不是空行的行必须是 `\restrict <密钥>`。还没读到完整的那一行时
|
|
44
|
+
* 返回 "more"。不是它就不交给 psql:没有受限模式,归档内容里的元命令会被执行
|
|
45
|
+
*/
|
|
46
|
+
export declare function restrictHeader(text: string): "ok" | "missing" | "more";
|
|
47
|
+
/**
|
|
48
|
+
* 等 stdin 能再写(drain)或者 psql 已经退出。监听用完就摘掉:大库恢复要等几十万次,
|
|
49
|
+
* 挂在一个直到最后才结束的 Promise 上的回调会一直攒着
|
|
50
|
+
*/
|
|
51
|
+
export declare function drainOrExit(stdin: NodeJS.WritableStream, child: NodeJS.EventEmitter): Promise<void>;
|
|
52
|
+
/** psql 默认格式的第一条错误:主消息 + DETAIL/HINT。不带 CONTEXT(COPY 出错时那里是整行数据) */
|
|
53
|
+
export declare function firstPsqlError(stderr: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* 写过 COMMIT、却没看到 psql 确认时,用事务号问目标:提交了、回滚了,还是说不清。
|
|
56
|
+
* 还在进行中(原会话还没收尾)就等一会儿再问;等不到、连不上、事务号查不了,都是"说不清",不猜
|
|
57
|
+
*/
|
|
58
|
+
export declare function transactionOutcome(connString: string, xid: string, opts?: {
|
|
59
|
+
waitMs?: number;
|
|
60
|
+
pollMs?: number;
|
|
61
|
+
graceMs?: number;
|
|
62
|
+
identity?: TargetIdentity;
|
|
63
|
+
}): Promise<"committed" | "rolled_back" | "unknown">;
|
|
64
|
+
export interface AuthRestoreRun {
|
|
65
|
+
/** committed:快照里的东西都在目标上了;rolled_back:目标上什么都没留下;unknown:查不清 */
|
|
66
|
+
transaction: "committed" | "rolled_back" | "unknown";
|
|
67
|
+
/** 没提交(或查不清)的原因;提交后的步骤出错写在 afterCommit 里 */
|
|
68
|
+
failure?: string;
|
|
69
|
+
xid?: string;
|
|
70
|
+
afterCommit?: Awaited<ReturnType<typeof afterCommit>>;
|
|
71
|
+
/** 补建了的触发器 */
|
|
72
|
+
triggers: string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 目标是哪个库:库的 OID,读得到时再加集群的 system identifier。事务号只在同一个集群里有意义,
|
|
76
|
+
* 拿事务号问结果之前先核对:目标被换掉、连接改指了别处,就不能拿那边同号的事务当答案
|
|
77
|
+
*/
|
|
78
|
+
export interface TargetIdentity {
|
|
79
|
+
databaseOid: string;
|
|
80
|
+
systemIdentifier: string | null;
|
|
81
|
+
}
|
|
82
|
+
export declare function targetIdentity(client: {
|
|
83
|
+
query: (text: string) => Promise<{
|
|
84
|
+
rows: Array<Record<string, unknown>>;
|
|
85
|
+
}>;
|
|
86
|
+
}): Promise<TargetIdentity>;
|
|
87
|
+
/** 两个 Auth 表名在 tableKey 里的写法:指向它们的外键和备份里的外键一样,提交后再加 */
|
|
88
|
+
export declare const AUTH_TABLE_KEYS: string[];
|
|
89
|
+
export declare function restoreWithAuth(opts: {
|
|
90
|
+
dumpPath: string;
|
|
91
|
+
archive: AuthArchive;
|
|
92
|
+
connString: string;
|
|
93
|
+
auth: AuthSection;
|
|
94
|
+
schemas: string[];
|
|
95
|
+
grants: GrantsToRestore;
|
|
96
|
+
listDir: string;
|
|
97
|
+
/**
|
|
98
|
+
* manifest 记着的扩展:装在这个事务里(锁内重查之后),恢复失败时随事务一起回滚,重跑时目标是干净的。
|
|
99
|
+
* 调用方事先在一个回滚掉的事务里确认过它们装得上
|
|
100
|
+
*/
|
|
101
|
+
extensions?: ExtensionInfo[];
|
|
102
|
+
/** 拿到事务号之后、写 COMMIT 之前调用:调用方据此记下"这次恢复对应哪个事务" */
|
|
103
|
+
onTransactionId?: (xid: string, identity: TargetIdentity) => Promise<void> | void;
|
|
104
|
+
/** 事务结果确定之后、提交后的步骤之前调用 */
|
|
105
|
+
onOutcome?: (transaction: AuthRestoreRun["transaction"]) => Promise<void> | void;
|
|
106
|
+
/** 提交后补完授权时调用 */
|
|
107
|
+
onGrantsApplied?: () => Promise<void> | void;
|
|
108
|
+
}): Promise<AuthRestoreRun>;
|
|
109
|
+
/**
|
|
110
|
+
* 没提交(或查不清)时给用户的那句话。结果只由事务本身说了算(没写 COMMIT,或 pg_xact_status 的回答),
|
|
111
|
+
* 不去数目标里有什么来推断:查不清就如实说查不清,并给出能查清的那条语句
|
|
112
|
+
*/
|
|
113
|
+
export declare function authRestoreFailureMessage(run: AuthRestoreRun): string;
|
|
114
|
+
/**
|
|
115
|
+
* 恢复报告里关于 Auth 的说明(和 RECOVERY.md 同一套说法):哪些用户恢复后登录会受影响、哪些东西要手工补
|
|
116
|
+
*/
|
|
117
|
+
export declare function authRestoreNotes(auth: AuthSection, schemas: string[]): {
|
|
118
|
+
notes: string[];
|
|
119
|
+
manual: string[];
|
|
120
|
+
};
|