truncateAll = async () => {
    debug('Database teardown');
    urlServiceUtils.reset();

    const tables = schemaTables.concat(['migrations']);

    if (module.exports.isSQLite()) {
        try {
            const [foreignKeysEnabled] = await db.knex.raw('PRAGMA foreign_keys;');
            if (foreignKeysEnabled.foreign_keys) {
                await db.knex.raw('PRAGMA foreign_keys = OFF;');
            }

            await sequence(tables.map(table => () => {
                return db.knex.raw('DELETE FROM ' + table + ';');
            }));

            if (foreignKeysEnabled.foreign_keys) {
                await db.knex.raw('PRAGMA foreign_keys = ON;');
            }

            return;
        } catch (err) {
            // CASE: table does not exist
            if (err.errno === 1) {
                return Promise.resolve();
            }

            throw err;
        } finally {
            debug('Database teardown end');
        }
    }

    await db.knex.transaction(async (trx) => {
        try {
            await db.knex.raw('SET FOREIGN_KEY_CHECKS=0;').transacting(trx);
            await sequence(tables.map(table => () => db.knex.raw('DELETE FROM ' + table + ';').transacting(trx)));
            await db.knex.raw('SET FOREIGN_KEY_CHECKS=1;').transacting(trx);
        } catch (err) {
            // CASE: table does not exist || DB does not exist
            // If the table or DB are not present, we can safely ignore
            if (err.errno === 1146 || err.errno === 1049) {
                return Promise.resolve();
            }

            throw err;
        } finally {
            debug('Database teardown end');
        }
    });
}
Internal helper to attempt to truncate all tables as fast as possible
Has to run in a transaction for MySQL, otherwise the foreign key check does not work.
Sqlite3 has no truncate command.