0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added --print-dependencies to data generator

refs https://github.com/TryGhost/DevOps/issues/119

- this allows you to debug the dependency chain to understand why a
  particular table is being generated
This commit is contained in:
Daniel Lockyer 2023-12-07 13:03:56 +01:00 committed by Daniel Lockyer
parent ff34a98b94
commit db16e565bc
2 changed files with 13 additions and 1 deletions

View file

@ -10,6 +10,7 @@ module.exports = class DataGeneratorCommand extends Command {
this.argument('--clear-database', {type: 'boolean', defaultValue: false, desc: 'Clear all entries in the database before importing'});
this.argument('--tables', {type: 'string', desc: 'Only import the specified list of tables, where quantities can be specified by appending a colon followed by the quantity for each table. Example: --tables=members:1000,posts,tags,members_login_events'});
this.argument('--with-default', {type: 'boolean', defaultValue: false, desc: 'Include default tables as well as those specified (simply override quantities)'});
this.argument('--print-dependencies', {type: 'boolean', defaultValue: false, desc: 'Prints the dependency tree for the data generator and exits'});
}
initializeContext(context) {
@ -51,7 +52,8 @@ module.exports = class DataGeneratorCommand extends Command {
baseUrl: config.getSiteUrl(),
clearDatabase: argv['clear-database'],
tables,
withDefault: argv['with-default']
withDefault: argv['with-default'],
printDependencies: argv['print-dependencies']
});
try {
await dataGenerator.importData();

View file

@ -18,6 +18,7 @@ class DataGenerator {
baseDataPack = '',
baseUrl,
logger,
printDependencies,
withDefault
}) {
this.knex = knex;
@ -28,6 +29,7 @@ class DataGenerator {
this.baseUrl = baseUrl;
this.logger = logger;
this.withDefault = withDefault;
this.printDependencies = printDependencies;
}
sortTableList() {
@ -158,6 +160,14 @@ class DataGenerator {
this.sortTableList();
if (this.printDependencies) {
this.logger.info('Table dependencies:');
for (const table of this.tableList) {
this.logger.info(`\t${table.name}: ${table.dependencies.join(', ')}`);
}
process.exit(0);
}
if (this.willClearData) {
await this.clearData(transaction);
}