0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Restored quick database reset method via table truncation

refs a3cc66be50

- 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
This commit is contained in:
Daniel Lockyer 2022-02-07 16:46:35 +01:00
parent e6cddeca72
commit 828a5d4d5a
2 changed files with 12 additions and 6 deletions

View file

@ -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();
}
}
};

View file

@ -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');