SaaS subscriptions
Accounts on weighted plans, their subscriptions and invoices, written as SQL inserts.
- Languages
eng- Formats
sql
Recipe
gbddl 1
language eng
table accounts rows 8 (
id int64 autoincrement primarykey
company text unique company()
plan text enum(values: ["free", "starter", "pro", "enterprise"], weights: [50, 30, 15, 5])
created_on date date(min: "2023-01-01", max: "2024-06-30")
)
table subscriptions rows 12 per(accounts, 1, 2) (
id int64 autoincrement primarykey
account_id int64 fk(accounts.id)
seats int64 integer(min: 1, max: 250)
status text enum(values: ["active", "trialing", "past_due", "cancelled"], weights: [70, 10, 8, 12])
started_on date date(min: "2023-01-01", max: "2024-12-31")
)
table invoices rows 30 per(subscriptions, 1, 4) (
id int64 autoincrement primarykey
subscription_id int64 fk(subscriptions.id)
number text unique pattern(pattern: "INV-######")
amount decimal(10, 2) money(min: 9, max: 4999)
issued_on date date(min: "2023-01-01", max: "2024-12-31")
)
output sql (rowsPerInsert: 3)
This is the exact recipe.gbddl committed to the repository. Copy it, or download the raw source.
About this recipe
SaaS subscriptions
A multi-table recipe for recurring billing: customer accounts on weighted plans, their subscriptions and the invoices those subscriptions issue, written as SQL inserts.
What it demonstrates
- Relationships:
subscriptionsreferencesaccounts, andinvoicesreferencessubscriptions. - Weighted values:
enum(..., weights: [...])makes most accounts free or starter and few enterprise, and most subscriptions active. - Row distribution:
per(...)gives each account 1 to 2 subscriptions and each subscription 1 to 4 invoices. - SQL output: each table is written as
CREATE TABLEplus multi-rowINSERTstatements.
Run it
Submit the recipe body to POST /api/v1/jobs?input_format=gbddl, or paste it
into Chef, to generate the data. The repository's local runner (run by
task test) also generates it and verifies its output.
The recipe outputs SQL files for the accounts, subscriptions and
invoices tables.
Guarantees
Every primary key is unique, every foreign key names an existing parent row,
invoice numbers are unique and per(...) grouping holds. Values are
synthetic: amounts do not follow plan prices.
Tested features
Smart types, physical types, rules and formats this recipe exercises and verifies.
companyenumintegerpatternmoneydateuniquefkperautoincrementprimary-keysql.rowsPerInsert