lipgrate
Version:
Lipgrate is a clean and safe migration toolkit for SQL databases. Designed to be readable, minimal, and powerful.
24 lines (17 loc) • 597 B
JavaScript
const logger = require('../../common/logger');
async function resetDatabase(db) {
logger.running('Dropping all tables for MySQL...');
await db.query('SET FOREIGN_KEY_CHECKS = 0;');
const [tables] = await db.query(`
SELECT table_name
FROM information_schema.tables
WHERE table_schema = DATABASE();
`);
for (const row of tables) {
const tableName = row.TABLE_NAME;
await db.query(`DROP TABLE IF EXISTS \`${tableName}\`;`);
}
await db.query('SET FOREIGN_KEY_CHECKS = 1;');
logger.success('All MySQL tables dropped.');
}
module.exports = { resetDatabase };