mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Optimized database resets for local testing
- we've had an optimization in CI that copies a fresh SQLite DB to a file, and copies it back when we need to do a DB reset - I originally only let this run in CI but we've had it around for a while so we should GA it to run on local machines - there may be edge cases, but we should fix them instead of letting tests run slower for development - this also makes sure we clean up any existing files before initializing the DB
This commit is contained in:
parent
9f38e8c49c
commit
b27ea8f504
1 changed files with 9 additions and 7 deletions
|
@ -16,7 +16,7 @@ const schemaTables = Object.keys(schema);
|
|||
// Other Test Utilities
|
||||
const urlServiceUtils = require('./url-service-utils');
|
||||
|
||||
const dbHash = Date.now();
|
||||
let dbInitialized = false;
|
||||
|
||||
/**
|
||||
* Checks if the current active connection is a MySQL database
|
||||
|
@ -43,21 +43,23 @@ module.exports.isSQLite = () => {
|
|||
* @param {Boolean} options.truncate whether to truncate rather thann fully reset
|
||||
*/
|
||||
module.exports.reset = async ({truncate} = {truncate: false}) => {
|
||||
// Only run this copy in CI until it gets fleshed out
|
||||
if (process.env.CI && module.exports.isSQLite()) {
|
||||
if (module.exports.isSQLite()) {
|
||||
const filename = config.get('database:connection:filename');
|
||||
const filenameOrig = `${filename}.${dbHash}-orig`;
|
||||
const filenameOrig = `${filename}-orig`;
|
||||
|
||||
const dbExists = await fs.pathExists(filenameOrig);
|
||||
|
||||
if (dbExists) {
|
||||
if (dbInitialized) {
|
||||
await db.knex.destroy();
|
||||
await fs.copyFile(filenameOrig, filename);
|
||||
} else {
|
||||
await fs.remove(filename);
|
||||
await fs.remove(`${filename}-journal`);
|
||||
await fs.remove(filenameOrig);
|
||||
|
||||
// Do a full database reset & initialisation
|
||||
await forceReinit();
|
||||
|
||||
await fs.copyFile(filename, filenameOrig);
|
||||
dbInitialized = true;
|
||||
}
|
||||
} else {
|
||||
if (truncate) {
|
||||
|
|
Loading…
Add table
Reference in a new issue