Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 4.09 KB

test-data.md

File metadata and controls

97 lines (73 loc) · 4.09 KB

Working with Test Data

Ghost includes a data generator for building repeatable local datasets. Use it instead of copying data from a real publication.

Reset the Development Site

From the repository root, run:

pnpm reset:data

This clears generated data from the checkout's development database, preserves the owner account, and creates 1,000 members and 100 posts using a fixed seed. The main checkout uses the ghost_dev database and a worktree uses its own dev_<worktree> database, which starts as a copy of ghost_dev, as described in development setup.

Other prepared datasets are available:

pnpm reset:data:empty
pnpm reset:data:xxl

reset:data:empty keeps the owner but generates no members or posts. reset:data:xxl creates two million members for testing behaviour at scale.

These commands are destructive and need the development MySQL container, which pnpm dev starts and leaves running. Do not point the generator at a database containing data you need to keep. Restart pnpm dev after resetting data so running processes do not retain state from the old dataset.

Generate a Custom Dataset

Run the generator from the repository root when the prepared datasets do not cover the scenario. gx uses the same checkout database configuration as the reset:data shortcuts:

pnpm gx data generate --clear-database --quantities members:10000,posts:500 --seed 123

The generator supports:

  • --clear-database to clear the tables being generated while preserving the owner account;
  • --tables=members:10000,posts:500 to generate only named tables and their dependencies, with optional quantities;
  • --with-default to add the other default tables when using --tables;
  • --quantities=members:10000,posts:500 to override quantities without changing which default tables are generated;
  • --base-data-pack=/path/to/data.json to import compatible newsletters, posts, tags, products, settings, and custom theme settings before generating the remaining tables. Importing a base pack replaces the existing settings;
  • --seed=123 to make generated values repeatable. Timestamps can still move so that generated content remains current;
  • --print-dependencies to show the table dependency order without importing.

Use --tables for a narrow dataset and --quantities when the relationships from the full default dataset matter. The generator adds required table dependencies automatically and rejects unknown table names.

An installed Ghost tree, such as the production image, has no gx. Run node bin/generate-data.js from its install directory with the same options.

For the implementation and instructions for adding an importer, see the data generator README.

Multi-subscription scenarios

Run pnpm gx data multi-sub-scenarios to create the named subscription-resolution scenarios for manual verification. This uses the same development-environment runner but writes its scenario records directly, independently of the general data generator. It requires an existing paid tier, Stripe product and recurring price; pnpm reset:data can create those prerequisites.

Re-running replaces the scenario members and their subscriptions. The script prints expected and actual resolved subscriptions. It can also seed before the lookup-table migration, skipping that table until it exists. The legacy pnpm seed:multi-sub-scenarios shortcut forwards to gx.

Shift Dates

Run pnpm gx data shift-dates to shift all dateTime fields forward based on the last member login, or use --offset=<days> to specify the shift. Negative values shift dates backwards. This is destructive and is restricted to the development and local environments. The command asks for confirmation; --force skips that prompt.

REPL

Run pnpm gx repl to open a shell with the checkout's configured database and Ghost models. knex/k refer to the connection and models/m to the models. .clear restores those bindings and .exit closes the database connection. This command is also restricted to development and local.