mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
4ff467794f
refs: https://github.com/TryGhost/DevOps/issues/11 This is a pretty huge commit, but the relevant points are: * Each importer no longer needs to be passed a set of data, it just gets the data it needs * Each importer specifies its dependencies, so that the order of import can be determined at runtime using a topological sort * The main data generator function can just tell each importer to import the data it has This makes working on the data generator much easier. Some other benefits are: * Batched importing, massively speeding up the whole process * `--tables` to set the exact tables you want to import, and specify the quantity of each
39 lines
1.3 KiB
JavaScript
39 lines
1.3 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;
|
|
|
|
constructor(knex, transaction) {
|
|
super(NewslettersImporter.table, knex, transaction);
|
|
this.sortOrder = 0;
|
|
// TODO: Use random names if we ever need more than 2 newsletters
|
|
this.names = ['Regular premium', 'Occasional freebie'];
|
|
}
|
|
|
|
generate() {
|
|
const name = this.names.shift();
|
|
const sortOrder = this.sortOrder;
|
|
this.sortOrder = this.sortOrder + 1;
|
|
const weekAfter = new Date(blogStartDate);
|
|
weekAfter.setDate(weekAfter.getDate() + 7);
|
|
return {
|
|
id: faker.database.mongodbObjectId(),
|
|
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;
|