test: set FOREIGN_KEY_CHECKS=1 after clearing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user