Skip to content

From a Database

This walks the whole loop against a live database: connect, inspect, generate, validate, look at the output. Pick your database.

import { Tabs, TabItem } from ‘@astrojs/starlight/components’;

```bash dbsprout init --db postgresql://user:pass@localhost:5432/mydb ``` ```bash dbsprout init --db mysql+pymysql://user:pass@localhost:3306/mydb ``` ```bash dbsprout init --db sqlite:///myapp.db ```

The connection URL can also come from the DBSPROUT_TARGET_DB environment variable. init reads tables, columns, primary keys, foreign keys, indexes and constraints via SQLAlchemy.

init writes dbsprout.toml:

[schema]
dialect = "postgresql"
source = "postgresql://user:***@localhost:5432/mydb"
snapshot = ".dbsprout/snapshots/a1b2c3d4.json"
[generation]
default_rows = 100
seed = 42
engine = "heuristic"
output_format = "sql"
output_dir = "./seeds"
[privacy]
tier = "local"

Edit per-table row counts before generating:

[tables.users]
rows = 50
[tables.audit_logs]
exclude = true
Terminal window
dbsprout generate --rows 1000

Files are written to ./seeds/, numbered by insertion order so they apply cleanly:

seeds/
001_authors.sql
002_books.sql
003_orders.sql
Terminal window
dbsprout validate

DBSprout checks FK satisfaction, PK uniqueness, UNIQUE and NOT NULL — all must be 100%.

Terminal window
dbsprout doctor --db postgresql://user:pass@localhost:5432/mydb
  • Install database drivers with the [db] extra: pip install "dbsprout[db]" (SQL Server: pip install "dbsprout[mssql]").
  • doctor checks connectivity, drivers, Python version, disk, and scans dbsprout.toml for secrets.