SynthForge SynthForge SynthForge IO

Integration · CockroachDB · Distributed SQL

Generate CockroachDB test data, with foreign keys intact

Multi-table fixtures that load with userfile upload + IMPORT INTO via import_cockroachdb.sql. Free web sessions.

Short answer

Design a multi-table schema in SynthForge, generate, and download the CockroachDB export. You get import_cockroachdb.sql (CREATE TABLE with FKs plus IMPORT INTO … CSV DATA) and per-table CSVs. Upload each CSV to userfile first, then run the script. Every child row references a real parent by construction.

Why generate rather than hand-roll

Distributed SQL still needs multi-table fixtures for integration tests and staging. Hand-rolled seed scripts drift; broken foreign keys fail later under concurrency.

SynthForge sorts tables by dependency, generates parents first, and samples FKs from IDs that exist. The same schema also exports Postgres-style loaders when you run CRDB and Postgres side by side.

How to do it

1. Define the schema

Describe tables in plain English, build them in the visual editor, or paste CREATE TABLE DDL. AI forge and SQL import both produce multi-table schemas with single-column foreign keys.

2. Set cardinality (optional)

Use relationship ratios such as "1 to 4 orders per customer" instead of inventing every child row count. Parents generate first; child foreign keys are sampled from real parent IDs.

3. Generate and export CockroachDB

Pick CockroachDB as the SQL dialect (or include SQL export in formats). The download ZIP contains import_cockroachdb.sql (CREATE TABLE with FKs plus IMPORT INTO … CSV DATA loaders) and csv/<table>.csv data files. Types use STRING, INT, and JSONB-friendly mappings.

4. Upload CSVs to userfile, then run the import script

CockroachDB IMPORT INTO reads from userfile:// (or cloud storage URLs), not from arbitrary local paths. The script header documents the prerequisite. Extract the ZIP, upload each CSV so the destination path matches userfile:///csv/<table>.csv, then run the SQL script.

bash
# From the extracted bundle directory
export DATABASE_URL='postgresql://root@localhost:26257/defaultdb?sslmode=disable'
# or your Cockroach Cloud connection string

for f in csv/*.csv; do
  base=$(basename "$f")
  cockroach userfile upload "$f" "csv/$base" --url "$DATABASE_URL"
done

cockroach sql --url "$DATABASE_URL" -f import_cockroachdb.sql

# Loaders look like:
#   IMPORT INTO "customers" CSV DATA ('userfile:///csv/customers.csv')
#   WITH skip = '1', nullif = '';
#   IMPORT INTO "orders"    CSV DATA ('userfile:///csv/orders.csv')
#   WITH skip = '1', nullif = '';

5. Local single-node / Docker tip

For a quick local check, start an insecure single-node (dev only), upload, and import. Production Cockroach Cloud uses the same userfile (or external storage) pattern with TLS credentials.

bash
# Dev only
docker run -d --name crdb -p 26257:26257 cockroachdb/cockroach:latest-v24.3 \
  start-single-node --insecure

# then userfile upload + cockroach sql -f import_cockroachdb.sql as above

6. (Optional) Agent path

With an API key and hosted MCP, agents can run description_to_dataset, download the ZIP, upload userfiles, and load with the same import_cockroachdb.sql. First API key includes 10 free credits; web sessions stay free.

text
# MCP endpoint: https://mcp.synthforge.io/mcp
# Auth: Authorization: Bearer sfk_live_…
# Docs: https://synthforge.io/docs/mcp

Frequently asked questions

Why userfile upload before IMPORT?
CockroachDB IMPORT INTO CSV DATA expects a storage URL the cluster can read (userfile://, s3://, gs://, …), not a bare path on your laptop. The import_cockroachdb.sql header documents cockroach userfile upload csv/<table>.csv csv/<table>.csv. Our load harness runs that step before IMPORT and checks row counts and FK orphans.
Does CockroachDB enforce the foreign keys?
Yes. SynthForge emits ALTER TABLE … ADD CONSTRAINT FOREIGN KEY after IMPORT, and the data is referentially valid by construction: child keys are drawn from generated parent IDs.
Does this work with Cockroach Cloud?
Yes, with a Cloud connection string (TLS). Use the same userfile upload + import_cockroachdb.sql flow, or point IMPORT at cloud object storage if your ops prefers that over userfile.
How large a dataset can I generate?
Up to 10,000,000 rows per table per request, with per-account rate limits. Flat formats stream out of core; nested JSON stays full-RAM and is gated earlier.
Can I use the same schema for Postgres or SQL Server?
Yes. One schema exports to PostgreSQL, MySQL, SQLite, SQL Server, MariaDB, DuckDB, and CockroachDB, plus CSV, JSON, JSONL, and Parquet. Cockroach wire protocol is Postgres-compatible, but the loader script is dialect-specific (IMPORT INTO vs \\copy).
Does SynthForge use my real production data?
No. It generates greenfield data from the schema you provide. It does not ingest or de-identify a live database. For anonymizing real data, use tools like Tonic or NVIDIA NeMo.

Related

Ready to seed CockroachDB staging?

Generate multi-table Cockroach data with real foreign keys, upload to userfile, IMPORT once. No credit card for the web app.