Recipes
A recipe is a YAML file you keep next to your tests. It says which tables to make, how many rows each one has, how they relate and what fills each column.
A recipe from start to end
version: "0.1"
seed: "readme"
locale: en-US
entities:
customer:
count: 1000
primary_key: ssn
fields:
first_name: { generator: first_name, required: true }
last_name: { generator: last_name, required: true, max_length: 30 }
gender: { generator: gender }
birth_date: { generator: birth_date }
ssn: { generator: ssn, unique: true }
city: { generator: city }
state: { generator: region }
zip: { generator: postal_code }
plan: { values: [free, pro, team] }
consistency:
- first_name matches: [gender]
payment:
belongs_to: { customer: 0-5 }
fields:
card: { generator: card }
output:
format: csv
dir: ./data
This one makes a thousand customers and zero to five payments for each. The customers are in en-US, so a region is a state and a postal code is a ZIP code. seed makes every run give the same rows.
Every key
| Key | Where | What it does |
|---|---|---|
seed | top | makes the run repeatable |
locale | top | which word lists to draw names and places from |
count | entity | how many rows |
belongs_to | entity | the parent table and how many rows each parent gets, such as { customer: 0-5 } |
primary_key | entity | the column, or columns, that identify a row |
consistency | entity | rules such as first_name matches: [gender] |
generator | field | what fills the column |
values | field | a list to draw from, such as [free, pro, team] |
type: integer or type: decimal | field | a random number: a whole number from 0 to 999999, or one with two decimal places from 0.00 to 999.99 |
type: uuid | field | a random UUID, the same as generator: uuid |
min_value and max_value | field | the smallest and the largest number a type: integer or type: decimal field draws, both included, such as min_value: 1 and max_value: 10. Either can be left out, and either can be negative |
unique | field | no value repeats |
required | field | the column is never empty |
max_length | field | the longest value allowed, counted in characters unless counted_in says bytes or graphemes |
empty | field | the share of rows left empty, such as 15%. In sql an empty cell is NULL |
policy | top | what to damage: layers, the share of rows, per_row and exclude_fields |
output | top | which files a run writes and where, with the keys below |
format | output | csv, the default, json, or sql for INSERT statements |
dialect | output | for sql, the database the statements are written for: postgresql, mysql (MySQL and MariaDB), sqlserver or sqlite. sql needs one |
create_tables | output | for sql: true starts each table with a CREATE TABLE typed from the recipe, with its keys and checks, and false, the default, fills tables that are already there |
dir | output | the folder the files go to, relative to where you run qadg. --out takes its place, and the Recipe screen writes to the folder chosen at its top |
delimiter | output | for csv, the one character between values: a comma when left out, or any other in quotes, such as a semicolon or a tab written "\t". A double quote and a line break are refused |
file_per_entity | output | for json and sql: true writes a file per table, such as customer.json, and false, the default, writes one dataset.json with each row’s children inside it, or one dataset.sql with the tables in order. csv always writes a file per table |
encoding | output | utf-8, the only encoding written today |
Check a recipe before you run it
qadg validate reads a recipe and reports every problem in it at once, rather than stopping at the first. A recipe that passes says what a run would write:
$ qadg validate shop.yaml $ qadg generate shop.yaml customer: state follows city, though no rule says so customer: zip follows city and state, though no rule says so shop.yaml can be used. Understood 2 entities and 10 fields. A run of it would write 3524 rows in 2 tables.
The Recipe screen of the window checks the recipe the same way as you type.
Numbers
type: integer fills a column with random whole numbers from 0 to 999999, and type: decimal with random numbers with two decimal places from 0.00 to 999.99. min_value and max_value set the smallest and the largest number, and both are included:
fields:
quantity: { type: integer, min_value: 1, max_value: 10 }
price: { type: decimal, min_value: 0.5, max_value: 99.99 }
change: { type: integer, min_value: -50, max_value: 50 }
Leave one of the two out and that end stays where it was, so max_value: 10 on its own gives numbers from 0 to 10. A bound of a decimal has at most two decimal places, and a bound of an integer has none. With max_length beside them, both ends have to fit in it. validate says which bound is wrong and why.
Where the files go
output says which files a run writes and where. Every key in it can be left out:
output:
format: csv
dir: ./data
delimiter: "\t"
formatiscsv, the default,json, orsql, which writes an INSERT statement for each row.dialectnames the database asqlfile is for:postgresql,mysql,sqlserverorsqlite.mysqlalso covers MariaDB.sqlneeds it, andvalidatesays so when it is missing.qadg generate --dialecttakes its place.create_tables: truemakes asqlfile start each table with aCREATE TABLEtyped from the recipe, described under Tables from the recipe.false, the default, writes only the rows. The other forms create no tables, andvalidatewarns abouttruethere.diris the folder the files go to, relative to where you runqadg, and that folder itself when left out.qadg generate --outtakes its place, and the Recipe screen writes to the folder chosen at its top.delimiteris the character between values in acsvfile, a comma when left out. Any other single character works in quotes, such as a semicolon for a spreadsheet set to use one, or"\t"for a tab. A double quote and a line break are refused, because they already mean something in the file.jsonandsqlhave no delimiter, andvalidatewarns about one.file_per_entitymatters tojsonandsql. Forjson,truewrites a file per table, such ascustomer.jsonandpayment.json, each a list of rows with a child row naming its parent in a field, andfalse, the default, writes onedataset.jsonwith each row’s children inside it. Forsql,truewritescustomer.sqlandpayment.sql, andfalsewrites onedataset.sqlwith the parent tables first.csvalways writes a file per table, sovalidatewarns thatfalsechanges nothing there.encodingcan only beutf-8, which is also what a run writes without it.
SQL files
format: sql writes every row as an INSERT statement for the database named under dialect:
output:
format: sql
dialect: postgresql
SET client_encoding = 'UTF8';
INSERT INTO "customer" ("customer_id", "last_name", "coupon") VALUES ('746861', 'Michael', NULL);
INSERT INTO "customer" ("customer_id", "last_name", "coupon") VALUES ('516920', 'Lara', 'WELCOME');
INSERT INTO "order" ("total", "customer") VALUES ('230.73', '746861');
INSERT INTO "order" ("total", "customer") VALUES ('85.20', '516920');
Without create_tables, the file creates no tables: load it into a database whose tables already have these names and columns. Tables from the recipe below shows how to have the file create them.
- Every value is written as text in quotes, and the database converts it to the type of its column, as it does when it imports a CSV file. A value the column cannot take, such as text in a number column, is refused by the database, which is often what a test of broken data wants to see.
- A cell left empty by
emptyisNULL. A value that is an empty text, which damage can write, stays''. - A child row names its parent by the parent’s primary key. With
sql, every table that has child rows needs aprimary_keyof one field, andvalidaterefuses the recipe otherwise, because a database has no row numbers for a child to point at. - Names of tables and columns are always quoted, so
orderorfirst namework as they are. A name the database refuses, such as one longer than 64 bytes in MySQL or 128 characters in SQL Server, is refused before anything is written. MySQL also limits the name of a table by the name of its file on disk, whichvalidatedoes not check. - Each file starts with the settings its database needs to read it as written: the client encoding for PostgreSQL, and for MySQL
SET NAMES utf8mb4and a line that keeps backslash escapes on for this session, with the rest of itssql_modeleft as your server has it. A SQL Server file starts withSET NOCOUNT ONandSET QUOTED_IDENTIFIER ON, without which sqlcmd cannot insert a row into a table that has a filtered index, and every statement in it is followed byGO.
Each row is its own statement, so a row the database refuses stops only that row:
| Database | Load the file | When a row is refused |
|---|---|---|
| PostgreSQL | psql -d testdb -f dataset.sql | psql reports it and goes on |
| MySQL, MariaDB | mysql --force testdb < dataset.sql | without --force, the client stops at the first one |
| SQL Server | sqlcmd -d testdb -f 65001 -i dataset.sql | sqlcmd reports it and goes on |
| SQLite | sqlite3 test.db < dataset.sql | sqlite3 reports it and goes on |
-f 65001 makes sqlcmd read the file as UTF-8. Without it, sqlcmd reads the file in the current code page, which on Windows is usually not UTF-8, so letters outside English can change.
A statement for each row loads slowly when the file is large: one to several milliseconds a row in our measurements. Inside one transaction the same file loads many times faster, but then one refused row means that nothing is loaded:
psql -d testdb --single-transaction -f dataset.sql
sqlite3 test.db "BEGIN" ".read dataset.sql" "COMMIT"
psql ends with exit code 0 even when it rolled the transaction back, so check its output for ERROR.
Tables from the recipe
With create_tables: true under output, each table starts with a CREATE TABLE statement, a parent before its children. For the recipe above:
CREATE TABLE "customer" (
"customer_id" integer NOT NULL,
"last_name" text,
"coupon" text,
PRIMARY KEY ("customer_id"),
CHECK ("coupon" IN ('SPRING10', 'WELCOME'))
);
CREATE TABLE "order" (
"total" numeric(5,2),
"customer" integer NOT NULL,
FOREIGN KEY ("customer") REFERENCES "customer" ("customer_id")
);
The type of each column comes from the recipe:
| In the recipe | PostgreSQL | MySQL, MariaDB | SQL Server | SQLite |
|---|---|---|---|---|
text with max_length: 40 | varchar(40) | varchar(40) | nvarchar(40) | varchar(40) |
text without max_length | text | longtext | nvarchar(max) | text |
type: integer | integer, bigint past nine digits | int, bigint past nine digits | int, bigint past nine digits | integer |
type: decimal | numeric(5,2) | decimal(5,2) | decimal(5,2) | decimal(5,2) |
| a date | date | date | date | date |
| a UUID | uuid | varchar(36) | uniqueidentifier | varchar(36) |
A decimal column is as wide as the widest number the field can hold, 999.99 without min_value or max_value, and keeps two places, or as many as the longest number under values.
required: trueand the fields ofprimary_keyareNOT NULL.primary_keyis thePRIMARY KEY,unique: trueisUNIQUE, and the column naming the parent has aFOREIGN KEYto the key of the parent.min_valueandmax_valuebecome aCHECKon the range, and a list undervaluesbecomes aCHECKthat the value is on the list. An empty cell passes both.- In MySQL and SQL Server a text column in a key compares text exactly (
utf8mb4_bin,Latin1_General_100_BIN2), because their default comparison takesZakandzakfor one value and would refuse a row the recipe calls correct. A text field in a key withoutmax_lengthisvarchar(255)ornvarchar(255)there, because neither indexes longer text. - In SQL Server a unique column that can be empty gets a filtered index instead of
UNIQUE, because SQL Server lets only one row leave aUNIQUEcolumn empty. - A MySQL table says
DEFAULT CHARSET=utf8mb4, so that a database created with another character set still takes Polish letters and emoji. - The file never drops a table. A table that is already there makes
CREATE TABLEfail, and the rows go into the existing table.
What happens in the database, measured with PostgreSQL 18, MySQL, MariaDB 12, SQL Server 2025 and SQLite 3.53:
- Every row of a recipe without damage loads, apart from the two cases below. A damaged row is taken or refused by the type, key or check it breaks, and the rows of a refused parent are refused by their foreign key.
- SQL Server counts a character such as an emoji as two in
nvarchar(n), so a value of n characters with emoji in it can be refused. - SQLite keeps a decimal as a floating point number, so
12.30reads back as12.3. It does not check the length ofvarchar(n), and it checks foreign keys only afterPRAGMA foreign_keys = ON. - MySQL and SQL Server compare text outside a key without regard to case, so
FREEpasses a check forfree. validaterefuses tables the database would not create: in MySQL a key longer than 3072 bytes, a row longer than 65,535 bytes (4 bytes for each character of a text column) or a table whose constraints MySQL would name with more than 64 bytes, in SQL Server text longer than 4000 characters in a key.
Related tables
belongs_to names the parent table and how many rows each parent gets. { customer: 0-5 } gives every customer between zero and five payments, and each payment carries the key of its customer in a column named after the parent. primary_key names the column, or columns, that identify a row, and that is the value a child row carries.
Rules between columns
consistency holds rules such as first_name matches: [gender], which keeps first names in line with the gender column. A city, its region and its postal code agree without a rule, and validate says so.
Damage from a recipe
policy says what to damage when the recipe runs: which kinds of damage in layers, the share of rows, how many values in one row with per_row, and columns to leave alone with exclude_fields. What it breaks lists every kind.