Populate your database with initial or test data.
Prax provides flexible database seeding with support for multiple file formats. Use seeding to populate your database with initial data during development, create test fixtures, or set up demo environments.
.rs, .sql, .json, and .toml seed files
Prevent accidental production seeding
Auto-seed after migrations
now(), uuid() in declarative formats
Configure seeding in your prax.toml file:
Production Protection
By default, seeding is disabled for production and staging environments.
Use --force to override, but be careful!
| Format | Extension | Description | Best For |
|---|---|---|---|
| Rust | .rs |
Full programmatic control with Prax client | Complex seeding logic, computed data |
| SQL | .sql |
Raw SQL statements executed directly | Simple data, database-specific features |
| JSON | .json |
Declarative data definition | Structured data, API compatibility |
| TOML | .toml |
Human-readable declarative format | Configuration-like seed data |
The simplest format - raw SQL executed against your database:
Declarative format with table-based structure:
Human-readable alternative to JSON:
Full programmatic control using the Prax client:
Add a binary target to your Cargo.toml:
JSON and TOML seed files support special functions for dynamic values:
Seeding integrates seamlessly with the migration workflow:
Prax automatically searches for seed files in common locations:
| Command | Description |
|---|---|
prax db seed |
Run the seed file |
prax db seed --seed-file <path> |
Run a specific seed file |
prax db seed --reset |
Reset database before seeding |
prax db seed --environment <env> |
Seed for specific environment |
prax db seed --force |
Force seeding even if disabled for environment |
prax migrate dev |
Run migrations + seed |
prax migrate dev --skip-seed |
Run migrations without seeding |
prax migrate reset --seed |
Reset database and run seed |
Write seeds that can run multiple times safely. Use ON CONFLICT DO NOTHING
in SQL or check for existing records in Rust.
Keep production = false in your seed configuration.
Never seed production accidentally.
When you need computed values, relationships, or conditional logic, use a Rust seed script for full control.
In JSON/TOML files, use the order array
to ensure tables are seeded in the correct order for foreign key constraints.