Ghost/ghost/data-generator/lib/importers/NewslettersImporter.js
Simon Backx d2cb23c3fa
Wired up Docker setup script and increased data generation performance (#19420)
ref PROD-233

- Stored whether Docker is used in the config files
- When running `yarn setup`, any existing Docker container will be
reset. Run with `-y` to skip the confirmation step.
- `yarn setup` will always init the database and generate fake data
- Increased amount of default generated data to 100,000 members + 500
posts.
- Made lots of performance improvements in the data generator so we can
generate the default data in ±170s
2024-01-05 13:42:30 +00:00

41 lines
1.2 KiB
JavaScript

const TableImporter = require('./TableImporter');
const {blogStartDate} = require('../utils/blog-info');
const {faker} = require('@faker-js/faker');
const {slugify} = require('@tryghost/string');
class NewslettersImporter extends TableImporter {
static table = 'newsletters';
static dependencies = [];
defaultQuantity = 2;
sortOrder = 0;
constructor(knex, transaction) {
super(NewslettersImporter.table, knex, transaction);
}
generate() {
const name = `${faker.commerce.productAdjective()} ${faker.word.noun()}`;
const sortOrder = this.sortOrder;
this.sortOrder = this.sortOrder + 1;
const weekAfter = new Date(blogStartDate);
weekAfter.setDate(weekAfter.getDate() + 7);
return {
id: this.fastFakeObjectId(),
uuid: faker.datatype.uuid(),
name: name,
slug: `${slugify(name)}-${faker.random.numeric(3)}`,
sender_reply_to: 'newsletter',
status: 'active',
subscribe_on_signup: faker.datatype.boolean(),
sort_order: sortOrder,
created_at: faker.date.between(blogStartDate, weekAfter)
};
}
}
module.exports = NewslettersImporter;