Wiederherstellungstest: DEFINER aus Dump entfernen, EPIPE abfangen
Trigger aus Migration 033 tragen den DEFINER des Import-Nutzers (phpMyAdmin von KeyHelp); ohne SET USER schlägt der Import in die Test-DB fehl. Zusätzlich stürzte run() bei frühem Abbruch von mysql mit unbehandeltem EPIPE ab und verschluckte die eigentliche Fehlermeldung. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb3a2ebf73
commit
9ad687b90b
1 changed files with 7 additions and 2 deletions
|
|
@ -33,7 +33,8 @@ function run(cmd: string, args: string[], o: { env?: Record<string, string>; std
|
|||
let out = ''; let err = '';
|
||||
if (o.stdout) p.stdout!.pipe(createWriteStream(o.stdout, { mode: 0o600 })); else p.stdout!.on('data', (d) => (out += d));
|
||||
p.stderr!.on('data', (d) => { err += d; if (err.length > 4000) err = err.slice(-4000); });
|
||||
if (o.stdin) createReadStream(o.stdin).pipe(p.stdin!); else if (o.stdinText !== undefined) { p.stdin!.on('error', () => undefined); p.stdin!.end(o.stdinText); }
|
||||
// EPIPE abfangen, wenn das Programm (z.B. mysql) früh abbricht – der eigentliche Fehler kommt über Exit-Code und stderr
|
||||
if (o.stdin) { p.stdin!.on('error', () => undefined); createReadStream(o.stdin).pipe(p.stdin!); } else if (o.stdinText !== undefined) { p.stdin!.on('error', () => undefined); p.stdin!.end(o.stdinText); }
|
||||
p.on('error', (e) => reject(new Error(`${basename(cmd)} konnte nicht gestartet werden: ${e.message}`)));
|
||||
p.on('close', (code) => (code === 0 ? resolve(out) : reject(new Error(`${basename(cmd)} Fehler (Exit ${code}): ${err.trim().split('\n').slice(-3).join(' | ')}`))));
|
||||
});
|
||||
|
|
@ -205,7 +206,11 @@ export async function runRestoreTest(c: BackupConfig, file?: string): Promise<No
|
|||
try {
|
||||
await admin.query(`DROP DATABASE IF EXISTS \`${scratch}\``); await admin.query(`CREATE DATABASE \`${scratch}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`);
|
||||
} finally { await admin.end(); }
|
||||
await run('mysql', [...dbArgs(), scratch], { env: dbEnv(), stdin: join(work, 'db.sql') });
|
||||
// DEFINER der Trigger/Routinen ist umgebungsabhängig (z.B. phpMyAdmin-Importnutzer) und braucht SET USER –
|
||||
// für den Test entfernen, dann gilt der verbindende Nutzer als DEFINER
|
||||
const dump = (await readFile(join(work, 'db.sql'), 'utf8')).replace(/\/\*!50017 DEFINER=`[^`]*`@`[^`]*`\*\/ ?/g, '').replace(/ DEFINER=`[^`]*`@`[^`]*`/g, '');
|
||||
await writeFile(join(work, 'restore.sql'), dump, { mode: 0o600 });
|
||||
await run('mysql', [...dbArgs(), scratch], { env: dbEnv(), stdin: join(work, 'restore.sql') });
|
||||
const conn = await mysql.createConnection({ host: config.db.host, port: config.db.port, user: config.db.user, password: config.db.password, database: scratch, timezone: 'Z' }); // UTC wie im Betrieb, sonst stimmt die Hash-Kette der Zeitstempel nicht
|
||||
try {
|
||||
const q = async (sql: string) => (await conn.query(sql))[0] as any[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue