How to seed a PostgreSQL database with realistic data
By the Ground team
Generate data against the target schema, load parent tables first and child tables second, and let PostgreSQL enforce foreign keys. Use COPY for large CSV files and keep test fixtures out of production databases.
Run the Acme Cloud fixture in CI
Start with the eight related tables in Acme Cloud. The fixture loads a pinned Ground CSV export into a new schema, checks keys and invoice totals, and confirms that credited invoices, overdue invoices, cancelled organizations and unresolved tickets are present.
Run this in a Python 3.11+ environment with GROUND_FIXTURE_DATABASE_URL set to a PostgreSQL 15+ test database. The script prints the verified counts as JSON and exits nonzero if the import or a check fails. Set your test connection's search_path to ground_fixture, or to the name you pass with --schema.
base=https://useground.dev/fixtures/acme-cloud
for file in seed.py scenario.json schema.sql checks.sql; do
curl -fsSLO "$base/$file" || exit 1
done
python -m pip install 'psycopg[binary]>=3.2,<4'
python seed.py runChange the volume or case mix
Save seed.py, scenario.json, schema.sql and checks.sql with your tests. Keep a copy of the CSV ZIP in a CI artifact store so each rerun uses the same bytes.
Edit the row counts, case minima or scenario in scenario.json. Run python seed.py request and use its output to create a dataset in Ground. For automation, send python seed.py request --json as the create API body with an idempotency key. Review and confirm the design when the build waits for approval. Download the finished CSV ZIP by version and save it with its SHA-256.
Run python seed.py run --artifact fixture.zip in CI against a clean test database or pass --schema with a new schema name. Ground download labels such as Usage events map to usage_events. If you use a different table label, rename the CSV in the ZIP before hashing it. For a local ZIP, archive.url can be omitted from the manifest.
Start with the target schema
Export only the schema or describe its constraints. Include composite keys, unique fields, NOT NULL constraints and enum values. Do not upload production secrets or personal data to create a test fixture.
Example request
Create customers, products, orders and order_items matching my PostgreSQL schema; include cancelled orders, zero-stock products and customers with no orders.
Import into an isolated database
Review column order and types. Run COPY or client-side \copy in a test database, loading parents before children. For reproducible integration tests, keep a versioned artifact and reset the database between runs.
Check behavior, not only row counts
Run application queries against the imported data and compare aggregate totals. Include boundary dates, empty relationships and unusual statuses in separate test scenarios.
Common questions
Do I need a generator for ten test rows?
No. A checked-in SQL seed is often simpler for a small deterministic fixture.
Try it with your own dataset
Get started, see pricing or use the API.
Review security and privacy when evaluating Ground for your team.