Seed
ghostrow seed in detail: how many rows each table gets, repeatable output with --seed, CSV, JSON and SQL files, inserting into a database, validation and exit codes.
ghostrow seed generates consistent, realistic rows for every table in a schema. Foreign keys point at real parent rows, unique columns stay unique, and every CHECK and inferred rule holds.
ghostrow seed --schema schema.sql --rows 300 --seed 42 --out fixtures/
ghostrow seed · schema.sql · seed 42 · Free
products 100 rows
tenants 12 rows
customers 34 rows
orders 100 rows
order_lines 300 rows
wrote 5 CSV files to fixtures
wrote 546 rows, 0 violations · 4 foreign keys, 7 unique, 5 check, 3 cross-column rules verified
Seed needs a place to put the rows. Without --out (files), --db (insert) or --dry-run, it stops with Say where the rows go: --out <dir> to write files, or --db <url> to insert into a database.
How many rows
- Without
--rows, the table nothing else references gets 500 rows. - With
--rows <n>, the tables that no other table references getnrows. Each step up the chain of foreign keys gets a third as many, rounded up. With--rows 300,order_lineshas 300,ordersandproducts100,customers34 andtenants12. - A one-to-one reference (a foreign key that is also unique) never has more rows than its parent.
rows:on a table in the rules file replaces the calculation for that table.--table name=nreplaces both. Repeat it for more tables.--table orders=500 --table customers=50is valid; an unknown name stops with the list of tables, and a value that is notname=rowsis rejected.
Free runs are limited to 5 tables and 10,000 rows in total. A bigger run stops before anything is written, with exit code 4.
Repeatable output
The same schema, rules file, row counts and --seed give the same rows, byte for byte. Running the command above twice produces identical files.
--seedtakes a whole number from 0 to 4294967295. Without it Ghostrow uses0, so output is repeatable even if you forget the flag.- Change the seed to get a different dataset of the same shape.
- With
--db, existing rows matter. Ghostrow avoids values that already exist in unique columns and continues numeric keys after the largest one, so a second run against the same database is a different run.
Output files
--out <dir> creates the folder if needed. --format picks the layout:
| Format | Files |
|---|---|
csv (default) | One <table>.csv per table, a header row, LF line endings. NULL is an empty cell, booleans are true and false |
json | One <table>.json per table, an array of objects. NULL is null |
sql | One seed.sql, wrapped in a transaction, tables in parent-first order, in the dialect of your schema (for example "name" quoting for Postgres, backticks for MySQL, brackets for SQL Server) |
ghostrow seed --schema schema.sql --seed 42 --format sql --out fixtures/
psql app_test -f fixtures/seed.sql
-- Generated by Ghostrow. Same schema, rules and seed give the same file.
BEGIN;
INSERT INTO "products" ("id", "sku", "name", "price", "stock") VALUES
(1, 'ZC-1000-QHE', 'Compact Jacket', 567.79, 11),
Insert into a database
ghostrow seed --db postgres://app:secret@localhost/app_test --rows 5000 --seed 42
All rows go in one transaction, parents first. If anything fails, the transaction is rolled back. Afterwards Ghostrow moves Postgres sequences past the new keys. With --db and --out together, Ghostrow reads the schema from the database and writes files; nothing is inserted (1.0.1 and later). See Databases for permissions.
Preview with --dry-run
--dry-run writes nothing but the rules file. It prints how each column was understood, the rules, and the row counts the run would use. Review it before the first real run.
Validation and exit codes
Before anything is written, Ghostrow checks every generated row against every enabled rule. If a rule cannot be met, the exit code is 2 and nothing is written. For example, with this rule added by hand to the rules file:
rules:
- { kind: check, table: products, expr: "stock < 0" }
stock has a declared CHECK (stock >= 0), so no row can satisfy both:
ghostrow: Could not generate row 1 of products: CHECK (stock < 0) failed.
Lower --rows or --table products=…, or relax the rule in ghostrow.rules.yaml.
When rows are generated but would break a rule, the message reads N generated row(s) would break a rule, so nothing was written: followed by the first few rows and rules.
| Code | Seed cases |
|---|---|
0 | Rows written, or dry run finished |
1 | Bad input: no --schema or --db, both given, an unknown --table, a wrong --format, an invalid seed, an unreadable rules file, or a connection that fails |
2 | Generated rows would break a rule |
4 | Free limit exceeded, or the database type or option needs a paid license |
Machine-readable output
--json prints one JSON document on stdout. --quiet prints nothing on success. Notices and progress go to stderr, so stdout stays clean for pipes.
ghostrow seed --schema schema.sql --out fixtures/ --json
{
"ok": true,
"plan": "free",
"seed": 0,
"rows": 782,
"violations": 0,
"tables": [{ "table": "products", "rows": 40 }, { "table": "tenants", "rows": 19 }],
"files": ["..."],
"rulesFile": "ghostrow.rules.yaml",
"checked": { "foreignKeys": 4, "uniques": 7, "checks": 5, "orderings": 2, "sums": 1 }
}
The tables list is shortened here. Real output has one entry per table, and files lists each path written.