Use SQL commands instead of mysql cli to clear tables for test

This commit is contained in:
Johannes Zellner
2025-06-10 11:47:05 +02:00
parent 639b7d9374
commit c6aef98361

View File

@@ -78,10 +78,10 @@ async function uninitialize() {
}
async function clear() {
await fs.promises.writeFile('/tmp/extra.cnf', `[client]\nhost=${gDatabase.hostname}\nuser=${gDatabase.username}\npassword=${gDatabase.password}\ndatabase=${gDatabase.name}`, 'utf8');
const tables = await query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'box' AND table_name != 'migrations';");
const queries = [{ query: "SET FOREIGN_KEY_CHECKS = 0;" }].concat(tables.map(q => { return { query: 'TRUNCATE TABLE ' + q.TABLE_NAME }; }));
const cmd = 'mysql --defaults-extra-file=/tmp/extra.cnf -Nse "SHOW TABLES" | grep -v "^migrations$" | while read table; do mysql --defaults-extra-file=/tmp/extra.cnf -e "SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE $table"; done';
await shell.bash(cmd, {});
await transaction(queries);
}
async function query() {