Tutorial · target: how to seed postgres in ci pipeline
How to Generate Multi-tenant fixture for a CI walkthrough Seed Data with One Command
User wants CI to boot a database and load fixtures on every pull request.
Direct answer
Generating a seed and a negative fixture set for Multi-tenant fixture for a CI 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, 3 Hacker News stories, pg at 372,007,475 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 — Multi-tenant fixture
You need a schema document for Multi-tenant fixture for a CI walkthrough and a Node.js runtime. The Multi-tenant fixture for a CI 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 Multi-tenant fixture for a CI walkthrough that is 2 tables in dependency order, with 10 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 Multi-tenant fixture for a CI 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 Multi-tenant fixture for a CI 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 Multi-tenant fixture for a CI walkthrough, the constructs worth knowing about are the range declaration on tenants.plan and the reference from tenant_users to tenants. 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 | tenants.slug | 23502 | not_null_violation | NOT NULL constraint failed: tenants.slug |
| Out-of-contract value | tenants.plan | 23514 | check_violation | CHECK constraint failed: tenants_plan_check |
| Dangling foreign key | tenant_users.tenant_id | 23503 | foreign_key_violation | FOREIGN KEY constraint failed |
| Table | Referenced by | Written |
|---|---|---|
| tenants | tenant_users | after tenant_users |
| tenant_users | — | first, no dependencies |
npx --yes @wenlu8848/schemaseed generate --input ./tut_tenants.openapi.yaml --out ./seed --formats sql --count 10 --seed 42
Download tut_tenants.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 "tenants" (
"id" UUID,
"slug" TEXT NOT NULL,
"plan" TEXT NOT NULL,
CONSTRAINT "tenants_pkey" PRIMARY KEY ("id"),
CONSTRAINT "tenants_plan_check" CHECK ("plan" IN ('free', 'pro', 'enterprise'))
);
CREATE TABLE IF NOT EXISTS "tenant_users" (
"id" UUID,
"tenant_id" UUID NOT NULL,
"email" TEXT NOT NULL,
"role" TEXT NOT NULL,
CONSTRAINT "tenant_users_pkey" PRIMARY KEY ("id"),
CONSTRAINT "tenant_users_role_check" CHECK ("role" IN ('owner', 'admin', 'member'))
);
DO $schema_seed$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'tenant_users_tenant_id_fkey') THEN
ALTER TABLE "tenant_users" ADD CONSTRAINT "tenant_users_tenant_id_fkey" FOREIGN KEY ("tenant_id") REFERENCES "tenants" ("id");
END IF;
END
$schema_seed$;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('58b66e81-0200-45a2-b39c-4b53d893e079', 'kelp nimbus', 'pro')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('4b8132c0-e9ec-4b45-9418-e6376ae7b0ba', 'jun.kaur@example.net', 'enterprise')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('3007d23c-b571-4be1-b979-2ba0c0b1357e', 'rosa.grant@test.dev', 'pro')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('d1847e69-bafe-4b41-824d-64b2e9dee0ee', 'kelp-quartz-841', 'enterprise')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('26283019-2720-4133-9cfe-f3b09878d64d', 'fay.costa@example.net', 'pro')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('2c399ca5-13dc-4ec5-ac21-c7e42a1d3261', 'Toronto, Elm Avenue 207', 'pro')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('d435f336-ad9b-49e9-baf8-6edbf40bc0e8', 'delta lumen', 'free')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('3c2096e4-8b9b-49f3-99bc-b65564857048', 'juniper-vertex-152', 'pro')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('5f4bc890-a6c7-4af1-a9f1-755e4aaf8812', 'onyx-delta-710', 'free')
ON CONFLICT DO NOTHING;
INSERT INTO "tenants" ("id", "slug", "plan")
VALUES ('9f26f226-b3ad-4e09-939d-72d0199cf8fb', 'umbra harbor', 'enterprise')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('8b5a6a15-654c-45e5-83c5-6f1b6afba88d', '3c2096e4-8b9b-49f3-99bc-b65564857048', 'milo.duarte704@example.com', 'member')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('9f899ee3-c3d6-434c-9aca-0f2a5c4b350e', '5f4bc890-a6c7-4af1-a9f1-755e4aaf8812', 'milo.duarte936@example.org', 'owner')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('7158dc5f-2c47-4b94-927a-1a9a686cb28a', 'd1847e69-bafe-4b41-824d-64b2e9dee0ee', 'milo.petrov613@example.com', 'owner')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('3bf1873b-7065-460c-a8c1-2792f26a4b38', 'd1847e69-bafe-4b41-824d-64b2e9dee0ee', 'eli.fontaine25@example.com', 'admin')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('a0207476-55d0-4845-8f0a-f9a16831812d', '58b66e81-0200-45a2-b39c-4b53d893e079', 'gus.grant531@mail.example', 'owner')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('9c1a7d4f-253d-404a-9e25-0583c15de287', 'd435f336-ad9b-49e9-baf8-6edbf40bc0e8', 'ada.okafor277@example.net', 'member')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('b748c299-bac6-4314-8f2d-985b6c16cf10', '9f26f226-b3ad-4e09-939d-72d0199cf8fb', 'chen.jansen816@test.dev', 'admin')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('1af09802-b013-4721-a1ab-226943dc46b3', 'd1847e69-bafe-4b41-824d-64b2e9dee0ee', 'milo.grant868@mail.example', 'owner')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('2bb4b1e8-13b2-4a2a-a8b8-5a02476d5e94', '5f4bc890-a6c7-4af1-a9f1-755e4aaf8812', 'dara.fontaine744@example.net', 'owner')
ON CONFLICT DO NOTHING;
INSERT INTO "tenant_users" ("id", "tenant_id", "email", "role")
VALUES ('35a9e5f5-4478-4e6b-a440-66d8c00bf099', 'd1847e69-bafe-4b41-824d-64b2e9dee0ee', 'fay.adler246@example.org', 'admin')
ON CONFLICT DO NOTHING;
COMMIT;
Frequently asked questions
- How long does the whole workflow take?
- One generate command and a moment on the Multi-tenant fixture for a CI 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 Multi-tenant fixture for a CI 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