Tutorial · target: how to generate sql inserts from yaml spec
How to Generate Inventory fixture for a YAML-to-SQL walkthrough Seed Data with One Command
User wants YAML definitions turned into INSERT statements.
Direct answer
Generating a seed and a negative fixture set for Inventory fixture for a YAML-to-SQL walkthrough takes one generate command and produces a set of committed files, with no hand-written INSERT statement in between.
The steps assume Node.js 22.6 or newer and the schema document that ships with this page; a schema with remote $ref URLs needs the files downloaded first.
One generate command writes 2 tables in dependency order into ./seed/sql/seed.sql, and the negative cases go to ./seed/sql/negatives.sql beside it; the same run also writes the pytest suite in ./seed/pytest, where each negative case is asserted against the schema keyword it breaks.
Data as of 2026-11-18 · source: 0 Stack Overflow questions, @electric-sql/pglite-tools at 59,400,999 monthly downloads · negative-case messages reproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) at 2026-11-18T11:53:54.233Z
Prerequisites — Inventory fixture
You need a schema document for Inventory fixture for a YAML-to-SQL walkthrough and a Node.js runtime. The Inventory fixture for a YAML-to-SQL walkthrough fixture used here has 2 tables, and the commands below assume the file is at openapi/file that ships with this page. Nothing else is required: no database connection, no API key, no network access at generation time.
The steps
One command does the work. The generate command reads the schema, writes the seed and the negative cases in a single pass, and prints what it produced: the tables it wrote, the rows per table and the number of negative cases. For Inventory fixture for a YAML-to-SQL walkthrough that is 2 tables in dependency order, with 11 constraints carried into the DDL. Two read-only commands sit next to it for checking instead of writing: validate reports the $ref chains that cannot be resolved and exits non-zero when one is broken, and inspect prints the tables, columns, primary keys and foreign keys the tool derived.
What you end up with
A set of committed artefacts: the PostgreSQL seed script, the negative SQL cases and the pytest suite. The seed for Inventory fixture for a YAML-to-SQL walkthrough contains 2 table definitions and their rows in dependency order. The negative file holds the instances the API must reject, one per constraint class that the fixture declares, and the pytest suite carries both the valid rows and the negative ones. All of them are text, all of them diff in review, and all of them are regenerated by re-running the same command.
Wiring it into CI
The CI step is a diff, not a test. Regenerate the seed and fail the build if the committed file differs from the regenerated one. That single check catches the case where Inventory fixture for a YAML-to-SQL walkthrough changed shape and the fixture did not, which is the failure that a hand-maintained seed produces silently for months.
Troubleshooting
If the generator warns about a schema it skipped, the warning names the construct. For Inventory fixture for a YAML-to-SQL walkthrough, the constructs worth knowing about are the range declaration on stock_items.quantity and the reference from stock_items to warehouses. A skipped construct is reported, never silently dropped, which is the behaviour to insist on from any tool in this position.
| Failure class | Column | SQLSTATE | Error name | Engine message (verbatim) |
|---|---|---|---|---|
| Missing required field | warehouses.code | 23502 | not_null_violation | NOT NULL constraint failed: warehouses.code |
| Out-of-contract value | stock_items.quantity | 23514 | check_violation | CHECK constraint failed: stock_items_quantity_check |
| Dangling foreign key | stock_items.warehouse_id | 23503 | foreign_key_violation | FOREIGN KEY constraint failed |
| Table | Referenced by | Written |
|---|---|---|
| warehouses | stock_items | after stock_items |
| stock_items | — | first, no dependencies |
npx --yes @wenlu8848/schemaseed generate --input ./tut_inventory.openapi.yaml --out ./seed --formats sql --count 10 --seed 42
Download tut_inventory.openapi.yaml
-- Generated by schemaseed.
-- seed: 42
-- rows per table: 10
-- Foreign key values are taken from the rows of the referenced table.
BEGIN;
CREATE TABLE IF NOT EXISTS "warehouses" (
"id" UUID,
"code" TEXT NOT NULL,
"region" TEXT NOT NULL,
CONSTRAINT "warehouses_pkey" PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "stock_items" (
"id" UUID,
"warehouse_id" UUID NOT NULL,
"sku" TEXT NOT NULL,
"quantity" INTEGER NOT NULL,
"reserved" INTEGER NOT NULL,
CONSTRAINT "stock_items_pkey" PRIMARY KEY ("id"),
CONSTRAINT "stock_items_quantity_check" CHECK ("quantity" >= 0),
CONSTRAINT "stock_items_reserved_check" CHECK ("reserved" >= 0)
);
DO $schema_seed$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'stock_items_warehouse_id_fkey') THEN
ALTER TABLE "stock_items" ADD CONSTRAINT "stock_items_warehouse_id_fkey" FOREIGN KEY ("warehouse_id") REFERENCES "warehouses" ("id");
END IF;
END
$schema_seed$;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('e650b77e-6e8b-44f7-b3d7-5d4bf5ce0770', 'willow meadow', 'Bogota, Elm Avenue 23')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('2bc9638c-dfa0-4d86-b558-d6af4aa39325', 'gus.fontaine@test.dev', 'willow tundra')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('139ba9a0-aeb7-4b98-828e-2fc562b35fda', 'onyx bravo', 'onyx-fable-735')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('1a44dbad-a2e6-455d-b3ec-60f66fa99de6', 'rosa.bianchi@test.dev', 'river river')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('20a834dc-819d-4514-a070-bc6d70607fd3', 'Toronto, Maple Street 161', 'indigo-bravo-974')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('114bf3d7-c2fc-48ed-8a1c-83ff1e8854bc', 'Gus Jansen', 'Toronto, Oak Drive 64')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('8a70acf0-374f-4715-8e24-03755cbadca6', 'Lisbon, Elm Avenue 207', 'umbra-willow-971')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('a9d76991-ebcc-47f2-9e9e-76de89775a4d', 'Omar Okafor', 'lena.fontaine@mail.example')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('068f07da-e189-4caf-921d-4969758a34b8', 'tara.duarte@example.net', 'cedar indigo')
ON CONFLICT DO NOTHING;
INSERT INTO "warehouses" ("id", "code", "region")
VALUES ('8dfc21c4-9f43-4d6f-bbb9-1181ce0485bc', 'summit-vertex-353', 'indigo cedar')
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('9e1172e2-1f6e-43bc-ab8a-d6c82a9d4722', '068f07da-e189-4caf-921d-4969758a34b8', 'onyx-kelp-373', 208, 36)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('9c1f244c-81f4-4a5f-b977-de4cbaf49e9d', '20a834dc-819d-4514-a070-bc6d70607fd3', 'delta lumen', 88, 647)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('aac8433f-2911-4c68-bbb1-21146ee6ffc5', '114bf3d7-c2fc-48ed-8a1c-83ff1e8854bc', 'willow grove', 12, 99)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('0a403c0e-7e8f-4f90-ab33-e3a40f94f146', 'a9d76991-ebcc-47f2-9e9e-76de89775a4d', 'Toronto, Riverside Lane 4', 707, 563)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('0614ba8f-8fbe-42d9-980a-3729b5c340a7', '20a834dc-819d-4514-a070-bc6d70607fd3', 'Bao Lund', 775, 462)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('6cc21919-7260-4bd6-86cb-26ef151b9677', '139ba9a0-aeb7-4b98-828e-2fc562b35fda', 'milo.duarte@example.net', 220, 944)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('dd5e46a4-1659-4eec-b856-f439a3820230', '20a834dc-819d-4514-a070-bc6d70607fd3', 'river grove', 341, 616)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('dee95a59-55fa-4b34-a1f8-eb80c2eb5c76', '1a44dbad-a2e6-455d-b3ec-60f66fa99de6', 'quartz-tundra-390', 871, 961)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('4db2ade6-ceda-4ae3-8202-686f4ceb456c', '20a834dc-819d-4514-a070-bc6d70607fd3', 'Berlin, Maple Street 86', 100, 37)
ON CONFLICT DO NOTHING;
INSERT INTO "stock_items" ("id", "warehouse_id", "sku", "quantity", "reserved")
VALUES ('4378efad-68be-4e8c-b186-52ce54840605', '114bf3d7-c2fc-48ed-8a1c-83ff1e8854bc', 'Quinn Jansen', 556, 645)
ON CONFLICT DO NOTHING;
COMMIT;
Frequently asked questions
- How long does the whole workflow take?
- One generate command and a moment on the Inventory fixture for a YAML-to-SQL walkthrough fixture of 2 tables; the slow part is deciding the row order, which is exactly what the generator removes.
- What do I commit to the repository?
- The generated files, all as text: the PostgreSQL seed script, the negative SQL cases and the pytest suite. Re-running with the same seed reproduces them byte for byte on the Inventory fixture for a YAML-to-SQL walkthrough schema.
- Does the CI step need a database?
- The drift check does not: it regenerates and fails if the committed file differs. Add a database service only if you also load the 2 tables.
- What happens if my schema changes?
- The regenerated file differs, CI fails with the diff attached, and every declaration in the schema is re-read, so a new one appears in the negative set immediately.
Run it against your own schema
SchemaSeed is MIT licensed and free: unlimited local generation, no account, no telemetry and no usage limit. It reads your schema file on your own machine, so nothing is uploaded anywhere. If it saves you time, you can support the project.
Get SchemaSeed — free Support the project
Questions: support@schemaseed.drz8848.win