Scenario · target: seed data for local development database

Seed Support tickets API from OpenAPI: seed data for Guide

Dev wants a docker-compose init script that builds a usable database on first boot.

Direct answer

SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for Support tickets API in which every foreign key resolves to a row that was actually inserted.

This holds for OpenAPI 3.0 and 3.1 with local $ref only; remote $ref URLs and oneOf polymorphism are reported as warnings, and the output targets PostgreSQL 13 or newer.

Run npx --yes @wenlu8848/schemaseed generate --input [the fixture that ships with this page] --out ./seed --formats sql --seed 42 and the script contains 3 CREATE TABLE statements followed by the rows in dependency order, inside one BEGIN/COMMIT pair.

Data as of 2026-11-18 · source: 30 Stack Overflow questions, 15 Hacker News stories, @prisma/dev at 44,947,569 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

What the generated script actually contains — Support tickets

Running the generator over the Support tickets API fixture produces 3 tables and 14 columns in one transaction. The parent table is written first, the child rows reuse the parent key that was just inserted, and the whole file is wrapped in a single BEGIN/COMMIT pair, so a failure halfway through rolls the database back instead of leaving orphaned rows behind. The constraint count that the generator honours is 20, which is the number of primary key, foreign key, NOT NULL and CHECK clauses it read out of the schema rather than invented. The enum, range and length declarations in the same schema are read out as well, and the value that breaks each of them ships as a negative case.

The failure you are trying to avoid

Hand-written INSERT statements for Support tickets API fail at exactly one point: the first child row whose parent does not exist yet. The engine reports it as foreign_key_violation with SQLSTATE 23503, and the message text on the reference engine was "FOREIGN KEY constraint failed". The generator removes that failure by ordering the tables topologically before it writes a single row, so tickets is never written before the row it points at.

Boundary cases that come with the seed

The seed is paired with a negative fixture set. For Support tickets API, the range probe on tickets.priority uses the value not_a_real_member, which the constraint priority IN ('low','normal','high','urgent') rejects. The engine produced "CHECK constraint failed: priority IN ('low','normal','high','urgent')" for that insert. A test suite that only checks the happy path never notices that the API accepts a value it should refuse.

What the output looks like in review

The output is plain SQL, not a binary blob, so it diffs cleanly in code review. Every INSERT in the Support tickets API fixture names its columns explicitly rather than relying on column order, which means the file survives someone adding a column to the schema. The seed file creates the tables contacts, tickets, ticket_messages, and each of those tables appears exactly once per seed file.

When a different tool fits better

If the Support tickets API fixture has a single table with no foreign key, a per-schema faker is enough and this page is not the fastest route. The generator earns its place when a schema has more than one table that reference each other, when the output has to be SQL rather than JSON, or when the test suite needs the invalid instances as well as the valid ones.

Real constraint failures for the Support tickets API fixtureReproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) on 2026-11-18T11:53:54.233Z. The message column is verbatim engine output; the SQLSTATE column is the PostgreSQL error class for the same constraint class.
Failure classColumnSQLSTATEError nameEngine message (verbatim)
Missing required fieldcontacts.email23502not_null_violationNOT NULL constraint failed: contacts.email
Out-of-contract valuetickets.priority23514check_violationCHECK constraint failed: priority IN ('low','normal','high','urgent')
Dangling foreign keytickets.contact_id23503foreign_key_violationFOREIGN KEY constraint failed
Insert order for Support tickets API, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
contactsticketsafter tickets
ticketsticket_messagesafter ticket_messages
ticket_messages—first, no dependencies
seed.sql

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

Download support.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 "contacts" (
  "id" UUID,
  "email" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ NOT NULL,
  CONSTRAINT "contacts_pkey" PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "tickets" (
  "id" UUID,
  "contact_id" UUID NOT NULL,
  "subject" TEXT NOT NULL,
  "priority" TEXT NOT NULL,
  "state" TEXT NOT NULL,
  "opened_at" TIMESTAMPTZ NOT NULL,
  CONSTRAINT "tickets_pkey" PRIMARY KEY ("id"),
  CONSTRAINT "tickets_priority_check" CHECK ("priority" IN ('low', 'normal', 'high', 'urgent')),
  CONSTRAINT "tickets_state_check" CHECK ("state" IN ('open', 'pending', 'closed'))
);

CREATE TABLE IF NOT EXISTS "ticket_messages" (
  "id" UUID,
  "ticket_id" UUID NOT NULL,
  "author" TEXT NOT NULL,
  "body" TEXT NOT NULL,
  "sent_at" TIMESTAMPTZ NOT NULL,
  CONSTRAINT "ticket_messages_pkey" PRIMARY KEY ("id"),
  CONSTRAINT "ticket_messages_author_check" CHECK ("author" IN ('customer', 'agent', 'system')),
  CONSTRAINT "ticket_messages_body_check" CHECK (char_length("body") >= 1)
);

DO $schema_seed$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'tickets_contact_id_fkey') THEN
    ALTER TABLE "tickets" ADD CONSTRAINT "tickets_contact_id_fkey" FOREIGN KEY ("contact_id") REFERENCES "contacts" ("id");
  END IF;
END
$schema_seed$;

DO $schema_seed$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'ticket_messages_ticket_id_fkey') THEN
    ALTER TABLE "ticket_messages" ADD CONSTRAINT "ticket_messages_ticket_id_fkey" FOREIGN KEY ("ticket_id") REFERENCES "tickets" ("id");
  END IF;
END
$schema_seed$;


INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('062b76aa-5560-47ef-a796-1bccddacbded', 'hana.costa837@example.org', '2025-07-26T14:29:26.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('c4140939-41ef-4cc2-a9a9-188fbc746d22', 'kai.lund352@example.net', '2022-10-14T09:58:46.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('00ec3005-e8ab-421c-84fa-28913c36050a', 'iris.costa51@mail.example', '2025-07-28T23:23:47.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('4bc589ad-edb7-4e67-b62c-87d11c2189c5', 'milo.petrov193@test.dev', '2025-04-09T21:25:46.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('90cc24dd-9b9a-4f1a-885f-ff70d0be15ea', 'bao.duarte249@test.dev', '2023-05-20T01:37:48.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('310f50db-1b0f-496c-a082-0f39934b3706', 'kai.petrov172@example.com', '2021-05-18T23:22:31.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('869201cf-0be9-4072-b16d-279e6edf16e6', 'omar.okafor803@example.net', '2026-04-11T09:45:07.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('ab44c9a8-362a-4fe5-b73f-1a8bceed12ce', 'tara.kaur258@example.org', '2025-11-16T11:20:41.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('d1c451fb-262d-4a48-a9d2-8e4814cdb95f', 'bao.fontaine469@mail.example', '2023-07-04T15:56:59.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "contacts" ("id", "email", "created_at")
  VALUES ('a2fdfb24-f615-41c9-bb8e-469f90895232', 'pia.okafor397@test.dev', '2022-01-16T23:06:42.000Z')
  ON CONFLICT DO NOTHING;

INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('970c96f3-a2b5-439e-892f-ece6077be3dc', 'a2fdfb24-f615-41c9-bb8e-469f90895232', 'delta zephyr', 'normal', 'open', '2024-05-28T23:32:48.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('3df6f72c-b553-4cbc-935c-f657ee0e083e', '00ec3005-e8ab-421c-84fa-28913c36050a', 'fable onyx', 'normal', 'open', '2026-04-23T20:50:38.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('78c4b706-2760-48e1-98af-bb019f9e9fe7', '90cc24dd-9b9a-4f1a-885f-ff70d0be15ea', 'dara.okafor@test.dev', 'normal', 'open', '2024-06-11T06:46:41.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('4d082138-473f-42cb-b333-8e20a69331b4', 'd1c451fb-262d-4a48-a9d2-8e4814cdb95f', 'Ada Moreau', 'urgent', 'pending', '2026-01-18T06:05:22.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('e1a650f4-9cd5-4ad4-b574-5d1e601792dc', '310f50db-1b0f-496c-a082-0f39934b3706', 'sami.okafor@mail.example', 'high', 'closed', '2021-11-27T14:53:24.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('20bd3411-5b5b-4a7a-a5a9-3fdb6fe67579', '869201cf-0be9-4072-b16d-279e6edf16e6', 'chen.bianchi@test.dev', 'low', 'closed', '2020-10-14T05:53:19.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('d03186ab-94be-4ec0-ae06-5e4712bf74f8', 'ab44c9a8-362a-4fe5-b73f-1a8bceed12ce', 'milo.duarte@mail.example', 'high', 'open', '2023-05-03T18:02:52.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('0fde0fb9-b36f-48b6-856c-d7e00d0e5a84', '062b76aa-5560-47ef-a796-1bccddacbded', 'zephyr fable', 'low', 'closed', '2025-03-04T13:59:11.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('0c674318-5085-4050-9538-d04d92db4cb4', '062b76aa-5560-47ef-a796-1bccddacbded', 'river cedar', 'low', 'closed', '2020-09-17T11:31:16.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "tickets" ("id", "contact_id", "subject", "priority", "state", "opened_at")
  VALUES ('68eda8ea-e565-4b0c-acf7-8e3d30ca902f', 'd1c451fb-262d-4a48-a9d2-8e4814cdb95f', 'willow-pebble-203', 'high', 'pending', '2025-03-15T18:37:51.000Z')
  ON CONFLICT DO NOTHING;

INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('9e7e5399-059e-444d-96ec-41ed313d1591', '3df6f72c-b553-4cbc-935c-f657ee0e083e', 'system', 'Toronto, Oak Drive 219', '2022-02-22T08:22:34.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('2b5dc7e0-5fb6-44a0-a2fe-90a5b7fb74af', '4d082138-473f-42cb-b333-8e20a69331b4', 'agent', 'Nairobi, Harbor Road 15', '2023-11-08T02:39:29.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('2e166f36-356a-4511-a1d8-acea5e1f244d', '78c4b706-2760-48e1-98af-bb019f9e9fe7', 'customer', 'Bogota, Elm Avenue 61', '2024-08-14T14:00:16.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('4d7b75ba-7dd9-4de3-8a26-988a1b782cdb', '4d082138-473f-42cb-b333-8e20a69331b4', 'agent', 'Nairobi, Maple Street 120', '2021-04-28T23:16:35.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('e0b43d95-77de-4ede-b87c-956edbd569ad', '78c4b706-2760-48e1-98af-bb019f9e9fe7', 'customer', 'cedar-lumen-874', '2021-08-12T23:04:51.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('0328f4d1-2dcc-433b-a063-fa854d540270', '3df6f72c-b553-4cbc-935c-f657ee0e083e', 'system', 'Bogota, Riverside Lane 225', '2023-01-13T19:13:54.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('ffa4825d-2ea1-494a-b522-cb3f85840e82', 'd03186ab-94be-4ec0-ae06-5e4712bf74f8', 'system', 'cedar-tundra-401', '2025-01-03T18:50:25.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('4d9aabb3-45d2-4c77-823c-16cbdb508cb6', 'd03186ab-94be-4ec0-ae06-5e4712bf74f8', 'system', 'Toronto, Oak Drive 37', '2021-12-26T06:23:29.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('de5ce42e-6245-4ef2-bf3e-cd9d2d7a811a', '20bd3411-5b5b-4a7a-a5a9-3fdb6fe67579', 'agent', 'grove kelp', '2020-05-13T12:22:18.000Z')
  ON CONFLICT DO NOTHING;
INSERT INTO "ticket_messages" ("id", "ticket_id", "author", "body", "sent_at")
  VALUES ('f1826242-e199-4824-951e-2d511ff82fec', '20bd3411-5b5b-4a7a-a5a9-3fdb6fe67579', 'system', 'Nia Holt', '2021-08-08T13:01:57.000Z')
  ON CONFLICT DO NOTHING;

COMMIT;

Frequently asked questions

Does SchemaSeed need a database connection to generate the seed?
No. It reads the schema file locally and wrote 3 tables for Support tickets API with no network access, and --seed 42 reproduces the same bytes.
Which OpenAPI versions are supported?
OpenAPI 3.0 and 3.1 with local $ref. On the Support tickets API fixture that covers 20 constraints across 3 tables; remote $ref and oneOf come back as warnings.
What does it do with the CHECK, enum, range and length declarations in my schema?
It reads them and uses them to generate the negative cases that break each one. For Support tickets API the decisive one is priority IN ('low','normal','high','urgent') on tickets.priority, and the value that breaks it ships as a negative case. The DDL carries the same declaration as a CHECK constraint, so the database refuses the value too.
Is the output valid on a fresh database?
On the Support tickets API fixture, yes: the reference engine accepted the 3-table DDL and every row satisfied its 20 constraints.

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