salix/services/db/testing_fixtures.js

58 lines
2.0 KiB
JavaScript
Raw Normal View History

// let mysql = require('mysql');
// let connection = mysql.createConnection({
// multipleStatements: false,
// host: 'localhost',
// user: 'root',
// password: '',
// database: 'salix'
// });
// let connected;
// let firstQuery;
// let secondQuery;
// let thirdQuery;
// let start = Date.now();
// let end = false;
// let callback = (error, results, fields) => {
// thirdQuery = Date.now() - start - connected - firstQuery - secondQuery;
// console.log('connected', connected);
// console.log('firstQuery', firstQuery);
// console.log('secondQuery', secondQuery);
// console.log('thirdQuery', thirdQuery);
// if (error) {
// connection.end();
// throw error;
// }
// if (end)
// connection.end();
// };
// let truncate = (error, results, fields) => {
// if (error) {
// connection.end();
// connection.query('SET FOREIGN_KEY_CHECKS = 1', callback);
// throw error;
// }
// let truncatesSQL = results.reduce((accumulator, currentValue, i) => {
// let sql = 'TRUNCATE TABLE `' + currentValue.table_schema + '`.`' + currentValue.table_name + '`; ';
// return `${accumulator}${sql}`;
// }, '');
// end = true;
// connection.query(truncatesSQL.slice(0, -2), callback);
// };
// connection.connect();
// connected = Date.now() - start;
// connection.query('SET FOREIGN_KEY_CHECKS = 0', callback);
// firstQuery = Date.now() - start - connected;
// connection.query(`SELECT table_schema, table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema IN ('account', 'bi','bs', 'cache', 'edi', 'hedera', 'pbx', 'salix', 'util', 'vn', 'vn2008', 'vncontrol') AND table_rows < 1;`, truncate);
// secondQuery = Date.now() - start - connected - firstQuery;
export function restoreFixtures() {
// connection.connect();
// connection.query('CALL truncateDatabase'); calls the MySQL procedure
console.log('fixtures restored');
}