test: set FOREIGN_KEY_CHECKS=1 after clearing

This commit is contained in:
Girish Ramakrishnan
2025-06-11 15:35:00 +02:00
parent 6dc0e4f5c3
commit 059547e37c

View File

@@ -17,7 +17,6 @@ const assert = require('assert'),
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
debug = require('debug')('box:database'),
fs = require('fs'),
execSync = require('child_process').execSync,
mysql = require('mysql'),
safe = require('safetydance'),
@@ -78,8 +77,10 @@ async function uninitialize() {
}
async function clear() {
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 tables = await query('SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_name != ?', [ 'box', 'migrations' ]);
const queries = [{ query: 'SET FOREIGN_KEY_CHECKS = 0' }];
for (const t of tables) queries.push({ query: `TRUNCATE TABLE ${t.TABLE_NAME}` });
queries.push({ query: 'SET FOREIGN_KEY_CHECKS = 1' }); // this is a session/connection variable, must be reset back
await transaction(queries);
}