Spec & format · target: openapi example to postgres insert

OpenAPI to SQL for Customer schema for an example usability table: Full Mapping

User has example values in the spec and wants them as rows.

Direct answer

Converting the Customer schema for an example usability table schema to SQL is a one-to-one mapping for 6 constraints in the DDL, and the foreign key order is the only part that needs reasoning.

The mapping assumes the PostgreSQL dialect, which is the only dialect the CLI emits; a native enum type is not used because it cannot be altered in a transaction.

The mapping table below lists the constructs of Customer schema for an example usability table and their SQL form; the enum row shows the one construct that is written as a CHECK constraint rather than as a native enum type.

Data as of 2026-11-18 · source: 0 Stack Overflow questions, 2 Hacker News stories, @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

The mapping — Customer schema

The table below maps each construct in the Customer schema for an example usability table fixture to what it becomes in SQL. 6 constraints in the DDL all have a SQL equivalent: a primary key per table, a foreign key per reference, a NOT NULL per required column and a CHECK for every enum, range and length declaration. The rows are ordered so the parent table comes first.

The cases that need a decision

One construct needs a decision rather than a translation. On Customer schema for an example usability table, the declaration on customers.tier is tier IN ('free','pro'). The generator does not create a native enum type, because a native enum has to be created separately and cannot be changed inside a transaction; it writes the declaration as a CHECK constraint on the column instead. The value that breaks the declaration ships as a negative case, and the reference engine rejected it with "CHECK constraint failed: customers_tier_check".

A worked example

The Customer schema for an example usability table fixture is small enough to convert by hand, which is the point. The generator produces 1 tables — customers — and each child table is written after the table it references. Doing it by hand for one fixture takes a few minutes; doing it for every schema change after that is the cost this removes.

Type mapping (PostgreSQL only)

SchemaSeed emits one SQL dialect, and it is PostgreSQL. The fixture on this page is written in it: uuid stays uuid, a timestamp becomes timestamptz, and json becomes jsonb, and every constraint is emitted with PostgreSQL semantics. No other database engine is targeted, so the type mapping below is the whole mapping.

Checking the result

A converted schema is worth checking against the database rather than by eye. The reference engine accepted the DDL for all 64 fixtures in this matrix and rejected the deliberately invalid rows with the expected error class each time, which is the check that catches a mistranslated constraint before it reaches a developer database.

Boundary probes for every constrained column in Customer schema for an example usability tableOne violating value per constraint, with the boundary it crosses.
TableColumnDeclared ruleProbe valueWhy it is invalid
customerstierone of free, pronot_a_real_membernot a declared member
customerstierone of free, proFREEwrong case
Insert order for Customer schema for an example usability table, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
customers—first, no dependencies
Schema construct to SQL construct for Customer schema for an example usability tableDerived from the fixture itself, not from a generic table.
Schema constructSQL formExample in this fixture
object schemaCREATE TABLE customers4 NOT NULL columns
required + foreign keyNOT NULL + FOREIGN KEY REFERENCESnone in this fixture
enumCHECK (col IN (...))free, pro
minimum / rangeCHECK (col >= n)no range constraint in this fixture
uniquea plain column; the DDL carries no UNIQUE constraintemail is declared unique in the schema
seed.sql

npx --yes @wenlu8848/schemaseed generate --input ./spec_customer.openapi.yaml --out ./seed --formats sql --count 10 --seed 42

Download spec_customer.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 "customers" (
  "id" UUID,
  "email" TEXT NOT NULL,
  "name" TEXT NOT NULL,
  "tier" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ NOT NULL,
  CONSTRAINT "customers_pkey" PRIMARY KEY ("id"),
  CONSTRAINT "customers_tier_check" CHECK ("tier" IN ('free', 'pro'))
);


INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('ce294ce8-d9c9-4d3e-b536-3ffc029fbe47', 'dara.adler807@mail.example', 'Toronto, Riverside Lane 215', 'free', '2020-12-09T11:25:18.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('2aab9a7c-d513-4bc4-9545-fd906875c133', 'chen.ibarra273@mail.example', 'Gus Holt', 'pro', '2020-02-15T19:32:17.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('cc5d7736-6775-44da-a410-c6cdcc8ce814', 'quinn.moreau133@example.com', 'Quinn Ibarra', 'free', '2025-09-25T12:56:54.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('7cb42ce9-7e2e-4218-b228-858b7f91573a', 'milo.fontaine747@mail.example', 'indigo-ember-280', 'free', '2025-06-23T06:07:26.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('aff6d559-b3ac-4140-8ebe-1a3ba8deeda8', 'ada.adler857@example.net', 'alpha-harbor-128', 'pro', '2024-01-26T03:56:48.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('5f98ce59-da3b-4190-8286-4b1d8d2163db', 'kai.novak218@example.org', 'zephyr-delta-401', 'pro', '2020-02-18T14:56:29.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('ed6e2b32-1f53-4bff-a74d-dd255d145b96', 'kai.novak347@test.dev', 'umbra indigo', 'free', '2024-05-07T12:14:47.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('0a99c185-2b5e-4e97-9de6-d4fd88d99b52', 'rosa.bianchi784@example.org', 'alpha-grove-283', 'pro', '2022-02-19T19:50:08.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('4dd69736-a602-46f4-8d04-9880d717408e', 'sami.bianchi408@example.com', 'summit juniper', 'free', '2024-07-24T00:04:06.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "customers" ("id", "email", "name", "tier", "created_at")
  VALUES ('e0307a39-73d2-450c-82f2-ec1cf5490503', 'kai.adler321@example.com', 'Nairobi, Harbor Road 95', 'free', '2024-09-07T15:36:35.000Z')
  ON CONFLICT DO NOTHING;

-- (no foreign keys)
COMMIT;

Frequently asked questions

Is the mapping lossless?
For Customer schema for an example usability table, 6 constraints in the DDL all have a SQL equivalent, and the mapping table above lists each one with the construct it came from. The enum, range and length declarations become CHECK constraints on the column.
Why not use a native enum type?
Because CREATE TYPE runs outside the transaction and cannot be altered while it is open. The CLI does not create an enum type either: it reads the members out of the schema and writes them as a CHECK constraint on the column, so the database refuses a value that is not a member — customers.tier on this fixture.
Does SchemaSeed emit SQL for a database other than PostgreSQL?
No. The SQL export is PostgreSQL only: uuid, timestamptz and jsonb are the PostgreSQL types and every constraint is emitted with PostgreSQL semantics. The Customer schema for an example usability table fixture was accepted by the reference engine.
How are foreign keys ordered?
Topologically, from the reference graph in the schema. For Customer schema for an example usability table the order is customers, and the insert-order table lists each parent.

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