From 828a5d4d5aaa3b68438063cb4c6a1cbf10eca090 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 7 Feb 2022 16:46:35 +0100 Subject: [PATCH] Restored quick database reset method via table truncation refs https://github.com/TryGhost/Ghost/commit/a3cc66be50af0419cbe7970299d08fab8f5d3533 - in the referenced commit, I made a util to speed up resetting the DB for SQLite by copying the database file - I inadvertently removed an optimization we had before - where we truncate the tables and insert the fixtures instead of dropping the entire database - this would be missing on MySQL tests - this seems to have a big difference so this commit re-adds the optimization in --- test/utils/db-utils.js | 16 +++++++++++----- test/utils/e2e-utils.js | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/utils/db-utils.js b/test/utils/db-utils.js index d01c6d3d5e..1c5cee7934 100644 --- a/test/utils/db-utils.js +++ b/test/utils/db-utils.js @@ -17,7 +17,7 @@ const urlServiceUtils = require('./url-service-utils'); const dbHash = Date.now(); -module.exports.reset = async () => { +module.exports.reset = async ({truncate} = {truncate: false}) => { // Only run this copy in CI until it gets fleshed out if (process.env.CI && config.get('database:client') === 'sqlite3') { const filename = config.get('database:connection:filename'); @@ -37,10 +37,16 @@ module.exports.reset = async () => { await fs.copyFile(filename, filenameOrig); } } else { - await knexMigrator.reset({force: true}); - - // Do a full database initialisation - await knexMigrator.init(); + if (truncate) { + // Perform a fast reset by tearing down all the tables and + // inserting the fixtures + await module.exports.teardown(); + await knexMigrator.init({only: 2}); + } else { + // Do a full database reset + initialisation + await knexMigrator.reset({force: true}); + await knexMigrator.init(); + } } }; diff --git a/test/utils/e2e-utils.js b/test/utils/e2e-utils.js index aa0566d1f4..bd04863a44 100644 --- a/test/utils/e2e-utils.js +++ b/test/utils/e2e-utils.js @@ -105,7 +105,7 @@ const restartModeGhostStart = async ({frontend}) => { // TODO: figure out why we need this if we reset again later? urlServiceUtils.reset(); - await dbUtils.reset(); + await dbUtils.reset({truncate: true}); debug('init done');