mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -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:
parent
e6cddeca72
commit
828a5d4d5a
2 changed files with 12 additions and 6 deletions
|
@ -17,7 +17,7 @@ const urlServiceUtils = require('./url-service-utils');
|
||||||
|
|
||||||
const dbHash = Date.now();
|
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
|
// Only run this copy in CI until it gets fleshed out
|
||||||
if (process.env.CI && config.get('database:client') === 'sqlite3') {
|
if (process.env.CI && config.get('database:client') === 'sqlite3') {
|
||||||
const filename = config.get('database:connection:filename');
|
const filename = config.get('database:connection:filename');
|
||||||
|
@ -37,10 +37,16 @@ module.exports.reset = async () => {
|
||||||
await fs.copyFile(filename, filenameOrig);
|
await fs.copyFile(filename, filenameOrig);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await knexMigrator.reset({force: true});
|
if (truncate) {
|
||||||
|
// Perform a fast reset by tearing down all the tables and
|
||||||
// Do a full database initialisation
|
// inserting the fixtures
|
||||||
await knexMigrator.init();
|
await module.exports.teardown();
|
||||||
|
await knexMigrator.init({only: 2});
|
||||||
|
} else {
|
||||||
|
// Do a full database reset + initialisation
|
||||||
|
await knexMigrator.reset({force: true});
|
||||||
|
await knexMigrator.init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ const restartModeGhostStart = async ({frontend}) => {
|
||||||
// TODO: figure out why we need this if we reset again later?
|
// TODO: figure out why we need this if we reset again later?
|
||||||
urlServiceUtils.reset();
|
urlServiceUtils.reset();
|
||||||
|
|
||||||
await dbUtils.reset();
|
await dbUtils.reset({truncate: true});
|
||||||
|
|
||||||
debug('init done');
|
debug('init done');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue