seedkit 2.1.1

Generate realistic, constraint-safe seed data for PostgreSQL, MySQL, and SQLite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<p align="center">
  <h1 align="center">SeedKit</h1>
  <p align="center">
    <strong>Generate realistic, constraint-safe seed data for any database.</strong>
  </p>
  <p align="center">
    <a href="https://github.com/kclaka/seedkit/actions/workflows/ci.yml"><img src="https://github.com/kclaka/seedkit/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
    <img src="https://img.shields.io/badge/version-2.1.1-blue" alt="Version">
    <img src="https://img.shields.io/badge/rust-1.91%2B-orange?logo=rust" alt="Rust">
    <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT"></a>
    <img src="https://img.shields.io/badge/databases-PostgreSQL%20%7C%20MySQL%20%7C%20SQLite-blueviolet" alt="Databases">
  </p>
</p>

---

SeedKit connects to your PostgreSQL, MySQL, or SQLite database, reads the schema, and generates seed data that respects foreign keys, unique constraints, check constraints, and enum types -- all without copying production data.

```bash
seedkit generate --db postgres://localhost/myapp --rows 1000 --output seed.sql
```

## Why SeedKit?

SeedKit is useful when a developer, QA engineer, or CI job needs a repeatable dataset from an existing database schema. A native CLI handles introspection, generation, and export. Teams can share a TOML configuration and lock file across application languages.

The community-maintained Snaplet Seed project provides a schema-aware TypeScript client for writing synthetic fixtures. [Community Seed](https://github.com/supabase-community/seed)

## Features

| Category | Feature |
|---|---|
| **Databases** | PostgreSQL, MySQL, and SQLite out of the box |
| **Schema Files** | Generate from `CREATE TABLE` statements or a `pg_dump --schema-only` file, without a running database |
| **Introspection** | Auto-reads tables, columns, FKs, unique constraints, check constraints, enums |
| **Classification** | 50+ semantic types (Email, FirstName, Price, CreatedAt, etc.) via pattern matching |
| **FK Safety** | Topological ordering ensures parent rows exist before child rows reference them |
| **Cycle Resolution** | Detects circular FKs (Tarjan SCC), breaks cycles with deferred `UPDATE` statements |
| **Correlations** | city/state/zip stay consistent, `created_at < updated_at`, first+last derive full name |
| **Determinism** | Lock file (`seedkit.lock`) + seed guarantees identical output across machines |
| **Column Generators** | Weighted value lists, text patterns, number ranges, semantic types, and null rates in `seedkit.toml` |
| **Locales** | `--locale de_DE` for German, French, Italian, Portuguese, Japanese, Chinese, Arabic, or Welsh names, addresses, companies, and phone numbers |
| **Smart Sampling** | Extract production distributions and generate data that mirrors real patterns (with PII masking) |
| **LLM-Enhanced** | Optional `--ai` flag sends schema to Claude, GPT, or Gemini for smarter classification |
| **Output Formats** | SQL (`INSERT`/`COPY`), JSON, CSV, or direct database insertion |
| **CI Integration** | `seedkit check` detects schema drift (exit code 0/1) |
| **Visualization** | `seedkit graph` exports Mermaid.js or Graphviz DOT dependency diagrams |

## Quick Start

```bash
# Install from source
cargo install --path crates/seedkit-cli

# Generate 1000 rows per table, output SQL
seedkit generate --db postgres://localhost/myapp --rows 1000 --output seed.sql

# Insert directly into database
seedkit generate --db postgres://localhost/myapp --rows 1000 --output direct

# Use .env or seedkit.toml for connection -- no --db needed
seedkit generate --rows 500 --output seed.sql
```

## Installation

### PyPI (recommended)

```bash
pip install seedkit
# or
pipx install seedkit
```

### crates.io

```bash
cargo install seedkit
```

Builds from source with Rust 1.91 or later.

### npm

```bash
npm install -g @seed-kit/cli
# or run without installing
npx @seed-kit/cli --help
```

### GitHub Releases

Download pre-built binaries for Linux (x64/ARM64), macOS (Intel/Apple Silicon), and Windows from
[Releases](https://github.com/kclaka/seedkit/releases).

### From Source

```bash
git clone https://github.com/kclaka/seedkit.git
cd seedkit
cargo install --path crates/seedkit-cli
```

**Requirements:** Rust 1.91+ (2021 edition)

### Verify Installation

```bash
seedkit --version
# seedkit 2.1.1
```

### Generate From a Schema File

No database running? Point SeedKit at the DDL instead. It reads `CREATE TABLE` statements, PostgreSQL enum types, unique indexes, and constraints added with `ALTER TABLE`. A `pg_dump --schema-only` file works as is.

```bash
seedkit generate --schema-file schema.sql --dialect postgres --rows 100 --output seed.sql
pg_dump --schema-only myapp > schema.sql && seedkit preview --schema-file schema.sql --dialect postgres
seedkit check --schema-file schema.sql --dialect postgres     # CI: has the schema drifted from seedkit.lock?
```

`--schema-file` works with `generate` (SQL, JSON, and CSV output), `preview`, `introspect`, `graph`, and `check`. `--output direct`, `reset`, `sample`, and `[[existing_parents]]` need a live connection. The file produces the same types, keys, uniqueness, enum labels, and CHECK constraints as introspecting a database built from it. Catalog details such as constraint names differ, though, so check a lock written from a schema file against a schema file.

### Zero-Config Database Detection

SeedKit automatically finds your database URL by checking (in order):

1. `--db` CLI flag
2. `DATABASE_URL` environment variable
3. `.env` file in the current directory
4. `seedkit.toml` config file

## Usage

### `seedkit generate`

Generate seed data for your database.

```bash
# SQL file output
seedkit generate --db postgres://localhost/myapp --rows 500 --output seed.sql

# Direct insert into database
seedkit generate --db postgres://localhost/myapp --rows 1000 --output direct

# JSON or CSV
seedkit generate --rows 100 --output data.json
seedkit generate --rows 100 --output data.csv

# One CSV file per table, with a header row, for \copy, LOAD DATA, or spreadsheets
seedkit generate --rows 100 --format csv --output seed/

# PostgreSQL COPY format (10-50x faster bulk loading)
seedkit generate --rows 10000 --output seed.sql --copy

# Deterministic with seed
seedkit generate --rows 100 --seed 42 --output seed.sql

# Reproduce from lock file
seedkit generate --from-lock

# Per-table row counts
seedkit generate --rows 100 --table-rows users=500,orders=2000

# Include/exclude tables
seedkit generate --include users,orders --rows 100
seedkit generate --exclude audit_logs,migrations --rows 100

# LLM-enhanced classification (requires ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY)
export ANTHROPIC_API_KEY=sk-ant-...
seedkit generate --rows 100 --ai --output seed.sql
seedkit generate --rows 100 --ai --model claude-sonnet-5-5 --output seed.sql
seedkit generate --rows 100 --ai --model gpt-6-luna --output seed.sql   # OpenAI
seedkit generate --rows 100 --ai --model gemini-3.5-flash-lite --output seed.sql   # Gemini

# Production-like with sampled distributions
seedkit generate --rows 1000 --subset seedkit.distributions.json

# Localized names, addresses, companies, and phone numbers
seedkit generate --rows 100 --locale de_DE
```

`--ai` sends the schema and the columns the naming rules could not classify. Without `--model`, SeedKit uses the first key it finds, in this order: `ANTHROPIC_API_KEY` (`claude-opus-5-5`), `OPENAI_API_KEY` (`gpt-6-luna`), and `GEMINI_API_KEY` or `GOOGLE_API_KEY` (`gemini-3.5-flash-lite`). A `--model` name selects its provider: `claude-*` calls Anthropic, `gpt-*` or `o*` calls OpenAI, and `gemini-*` calls Gemini. Rate-limit and overload errors are retried twice.

`--locale` (or `locale = "de_DE"` under `[generate]`) accepts `ar_SA`, `cy_GB`, `de_DE`, `fr_FR`, `it_IT`, `ja_JP`, `pt_BR`, `pt_PT`, `zh_CN`, and `zh_TW`. Names are localized in every locale. Addresses, companies, phone numbers, and job titles are localized where the locale has its own data for them, and otherwise use English values. Emails and usernames stay ASCII, so `Jürgen König` gets `juergen.koenig@example.com`. The lock records the locale for replay.

With no output path, `generate` writes SQL to stdout. When importing a SQL file with references to auto-increment keys, use a fresh database whose sequences start at 1. To append to a populated database, use `--output direct`. SeedKit uses the keys assigned during that run for child inserts and deferred updates, all in one transaction.

SQL and PostgreSQL COPY exports run in a single transaction. If an import fails partway through, for example on a constraint the target database adds, the database keeps none of the generated rows.

PostgreSQL array, interval, XML, range, and point columns get values in their own syntax. Arrays hold one to three elements of the column's element type, and a `tags TEXT[]` column holds tag-like words.

SeedKit omits database-computed columns from generated rows, including SQL and PostgreSQL COPY exports. The database evaluates their expressions during insertion.

Foreign keys can reference a primary key, a unique column, or an ordered set of columns. SeedKit draws all components of a composite reference from the same generated parent row.

### `seedkit reset`

Empty the tables SeedKit generates and reseed them, all in one transaction. Use it in a development loop to return a database to a known state. It accepts the same options as `generate`, including `--include`, `--exclude`, `--scenario`, and `--from-lock`.

```bash
seedkit reset --db postgres://localhost/myapp --rows 50        # asks before deleting
seedkit reset --rows 50 --exclude audit_logs --yes             # no prompt, for scripts and CI
seedkit reset --from-lock --yes                                # restore the dataset in seedkit.lock
```

- Reset lists the tables and asks before deleting anything. Without a terminal, it requires `--yes`.
- It stops before touching anything when a table outside the reset references a table inside it. Deleting those rows would fail, or cascade into the other table.
- PostgreSQL restarts identity columns, so IDs begin at 1, and SQLite resets `AUTOINCREMENT` counters. MySQL keeps its counters, because resetting them would end the transaction early.
- If any step fails, the transaction rolls back and the database keeps its previous rows.

### `seedkit sample`

SeedKit samples numeric aggregates, row-count ratios and database enum frequencies. To record literal labels from a text column, select it with `--allow-text table.column`. SeedKit skips known PII columns before querying labels.

```bash
# Sample all tables
seedkit sample --db postgres://readonly-replica:5432/myapp

# Sample specific tables with custom limits
seedkit sample --db postgres://localhost/myapp --tables users,orders --allow-text orders.status --categorical-limit 100

# Custom output path
seedkit sample --db postgres://localhost/myapp -o profiles.json
```

This creates `seedkit.distributions.json` with:
- **Categorical distributions** -- value frequencies for enums and explicitly selected text columns
- **Numeric distributions** -- min, max, mean, stddev for numeric columns
- **FK ratios** -- child-to-parent row count ratios (e.g., 3.2 orders per user)

Use `seedkit generate --subset seedkit.distributions.json` to generate data with these distributions. Existing profile files retain any literal text saved by earlier versions. Run `sample` again to apply the new defaults.

### `seedkit introspect`

Analyze your database schema and show classification results. SeedKit recognizes single-column `CHECK (column IN (...))` lists of literal values, including PostgreSQL’s normalized `= ANY (ARRAY[...])` form. Generation chooses from the allowed values and reports a conflicting override before output.

```bash
seedkit introspect --db postgres://localhost/myapp
seedkit introspect --db postgres://localhost/myapp --format json
```

### `seedkit preview`

Preview uses the same configuration, table selection, and generation plan as `generate`, then displays up to five rows per table. Use `--limit` to change the display limit, or `--from-lock` to see the values from a recorded run. Preview leaves the database and lock file untouched.

```bash
seedkit preview --db postgres://localhost/myapp --rows 5
```

### `seedkit check`

Detect schema drift against the lock file. Designed for CI pipelines.

```bash
seedkit check --db postgres://localhost/myapp
# Exit code 0 = no drift, 1 = drift detected

seedkit check --db postgres://localhost/myapp --format json
```

### `seedkit graph`

Visualize table dependencies.

```bash
seedkit graph --db postgres://localhost/myapp --format mermaid > schema.mmd
seedkit graph --db postgres://localhost/myapp --format dot | dot -Tpng > schema.png
```

All seven PostgreSQL commands accept `--schema`. Set `schema = "tenant_a"` under `[database]` in `seedkit.toml` to use it by default. The flag takes precedence over the config file. The default schema is `public`.

### Named relational scenarios

Select a fixture with `seedkit generate --scenario workspace` or inspect it with `seedkit preview --scenario workspace`. For example, this `seedkit.toml` creates two workspaces with three members and two projects each. Every project gets five tasks, all assigned to members of its own workspace.

```toml
[scenarios.workspace.rows]
workspaces = 2

[scenarios.workspace.per_parent]
"members.workspace_id" = 3
"projects.workspace_id" = 2
"tasks.project_id" = 5

[scenarios.workspace.scope."tasks.assignee_id"]
via = "project_id"
parent_scope = "workspace_id"  # on projects
target_scope = "workspace_id"  # on members
```

Scenario counts take precedence over general row settings for the tables they size. Per-parent counts and scope paths use single-column foreign keys. Both scope columns must reference the same table and key. If a workspace needs an assignee and has no eligible member, generation stops before output. Lock replay restores the selected definition even if the configuration file changes.

Scenario records pin fields on the first rows of a table in declaration order. The remaining rows and fields use their normal generators. Records count toward the planned row total. Use scalar fields or natural keys in records and use the relationship settings above for foreign keys.

```toml
[scenarios.accounts.rows]
users = 10

[[scenarios.accounts.records.users]]
username = "owner"
is_admin = true
quota = 25

[[scenarios.accounts.records.users]]
username = "paused-user"
status = "suspended"

[columns."users.quota"]
values = [2, 5]
weights = [0.7, 0.3]
```

Lists and records preserve string, integer, boolean, and finite floating-point literals in JSON exports and lock replay.

## Configuration

Create a `seedkit.toml` in your project root:

```toml
[database]
url = "postgres://localhost/myapp"

[generate]
rows = 500
seed = 42
locale = "en"   # or de_DE, fr_FR, ja_JP, ...

[tables.users]
rows = 1000

[tables.orders]
rows = 5000

# Custom value lists with optional weights
[columns."products.color"]
values = ["red", "blue", "green", "black", "white"]
weights = [0.25, 0.20, 0.20, 0.20, 0.15]

# Text patterns: # is a digit, ? an uppercase letter, {row} the row number
[columns."orders.number"]
pattern = "INV-{row:06}"     # INV-000001, INV-000002, ...

[columns."products.sku"]
pattern = "??-####"          # KX-0417

# Numbers in an inclusive range (whole numbers for integer columns)
[columns."order_items.quantity"]
range = [1, 5]

# Choose a built-in generator instead of the naming rules' choice
[columns."accounts.employer"]
semantic = "CompanyName"

# Chance of NULL for a nullable column (default 0.05)
[columns."users.bio"]
null_rate = 0.4

# Explicit cycle-breaking for circular foreign keys
[graph]
break_cycle_at = ["users.invited_by_id", "comments.parent_id"]
```

### Seed children of existing rows

To give new users roles that already exist, select the child foreign key in `seedkit.toml`.

```toml
[[existing_parents]]
table = "users"
columns = ["role_id"]
```

Run `seedkit generate --include users --output direct` to add users. SeedKit reads only the referenced role keys. Other relationships still select newly generated parents. If another relationship requires new roles, those new rows can coexist with this existing-role pool. For a composite foreign key, list all child columns in constraint order. Each child takes the complete key from one parent row.

For PostgreSQL, the write scope is the namespace selected by `--schema`. For example, when `public.profiles.id` references `auth.users.id`, select `table = "profiles"` and `columns = ["id"]` in `[[existing_parents]]`. SeedKit reads the referenced keys from `auth.users` and writes only to the selected namespace. Without a configured pool, optional cross-schema references receive NULL and required ones report a planning error before output.

Preview and exports use the same selection. The lock records a fingerprint so replay detects changes to the parent keys. An empty pool stops generation before output.

## How It Works

```
                    seedkit generate
                          |
          [1] Introspect  |  Connect to DB, read information_schema
                          v
                   DatabaseSchema
                          |
          [2] Graph       |  Build FK dependency graph (petgraph)
                          |  Detect cycles (Tarjan SCC)
                          |  Break cycles, topological sort
                          v
                  Insertion Order
                          |
          [3] Classify    |  50+ regex rules match column names
                          |  Optional LLM pass (--ai flag)
                          |  Optional distribution profiles (--subset)
                          v
                  SemanticTypes
                          |
          [4] Generate    |  Row-by-row, FK-safe, unique-safe
                          |  Correlated groups, check constraints
                          |  Distribution-aware (normal, categorical)
                          v
                  Generated Data
                          |
          [5] Output      |  SQL / JSON / CSV / Direct Insert
                          v
                    seed.sql
```

## Lock File

`seedkit.lock` works like `package-lock.json`. It captures the schema snapshot, random seed, and all configuration so teammates can reproduce the exact same dataset:

```bash
# Generate (creates seedkit.lock)
seedkit generate --rows 100

# Teammate reproduces identical data
seedkit generate --from-lock
```

When generating with `--subset`, the lock records the profile path and a SHA-256 digest. Keep the profile alongside the project. Both `generate --from-lock` and `preview --from-lock` read it and verify its contents. For an older lock created with a profile, supply `--subset` once during replay to record it.

New locks use a random stream per table, row, and field. Adding an unrelated column preserves existing fixture values. Correlated fields share a stream. Locks written before this change replay with the original sequential generator.

If the schema changes after the lock is written, `--from-lock` stops and reports the hash mismatch. Add `--force` to replay the lock's seed and settings against the current schema. SeedKit then rewrites the lock with the new schema snapshot, so later replays and `seedkit check` pass.

If there's a merge conflict in `seedkit.lock`, don't resolve it by hand. Keep one side, then replay it against the merged schema:

```bash
git checkout --ours seedkit.lock
seedkit generate --from-lock --force --output /dev/null
```

Without `--from-lock`, `generate` ignores the lock's settings and starts over with a new random seed (unless `seedkit.toml` sets one) and the row counts from your flags and `seedkit.toml`.

## Performance

Benchmarked with [criterion](https://github.com/bheisler/criterion.rs) on Apple Silicon (M-series). Run `cargo bench` to reproduce.

| Operation | Throughput |
|---|---|
| Generation (10 cols, semantic providers) | ~480K rows/sec |
| Generation (FK references only) | ~3.7M rows/sec |
| Generation (weighted value lists) | ~6.9M rows/sec |
| Generation (distribution sampling) | ~8.6M rows/sec |
| Classification (100 tables x 20 cols) | ~2.1M cols/sec |
| SQL output formatting | ~1.5M rows/sec |
| JSON output formatting | ~1.1M rows/sec |
| CSV output formatting | ~1.5M rows/sec |

## Comparison

| Workflow | SeedKit | Community Seed (`@snaplet/seed`) |
|---|---|---|
| Define fixtures | Native CLI, TOML settings, and per-column value lists | Generated TypeScript client with model and field callbacks |
| Connect to a database | PostgreSQL, MySQL, SQLite | PostgreSQL, SQLite, MySQL (documented as alpha), and Prisma adapters |
| Describe relationships | Derive insertion order from foreign keys and resolve supported cycles | Nest records and connect rows through explicit pools |
| Repeat a dataset | Seed and lock file with a schema snapshot and pinned time | Deterministic Copycat values and per-plan seeds |
| Use in development and CI | Write SQL, JSON, or CSV, insert directly, and check for schema drift | Run fixture scripts through the client or preview SQL with dry-run mode |
| Generate realistic values | Semantic providers, optional AI classification, and optional sampled distributions | Synthetic values, custom generators, and optional AI-generated text examples |

For the community project’s supported behavior, see its [adapter reference](https://snaplet-seed.netlify.app/seed/reference/adapters), [client reference](https://snaplet-seed.netlify.app/seed/reference/client), and [project README](https://github.com/supabase-community/seed).

## Architecture

SeedKit is a Rust workspace with three crates:

```
seedkit/
  crates/
    seedkit-core/     # Library: introspection, graph, classification, generation, output, sampling
    seedkit-cli/      # Binary: clap-based CLI with 6 subcommands
    seedkit-testutil/  # Shared test helpers
  tests/
    fixtures/         # SQL schema fixtures for integration tests
```

**Test suite:** unit and CLI tests, plus PostgreSQL and MySQL integration suites that CI runs against real databases.

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, testing, and PR guidelines.

```bash
# Run the full test suite
cargo test

# Run integration tests (requires Docker)
docker compose -f docker/docker-compose.test.yml up -d
TEST_POSTGRES_URL=postgres://seedkit:seedkit@localhost:5432/seedkit_test \
TEST_MYSQL_URL=mysql://seedkit:seedkit@localhost:3307/seedkit_test \
  cargo test --test '*' -- --test-threads=1
```

## License

Licensed under the [MIT License](LICENSE).