DEV Community

MD Mehedi Hasan
MD Mehedi Hasan

Posted on

From PRD to PostgreSQL: how one paragraph becomes a database schema

From PRD to PostgreSQL: how one paragraph becomes a database schema

Most PRD generators stop at prose. You get a nice document that says "the system shall support sprints," and then a developer still has to decide what a sprint is in the database: which table, which columns, who can see it, and what the API accepts.

That gap is where builds drift. The PRD says one thing, the schema says another, and by the time anyone notices, there is production data in the wrong shape.

I built my generator to close that gap: one paragraph in, and out comes the PRD and the PostgreSQL schema and the typed API contracts, all agreeing with each other. Here is what that path actually looks like, using the sample spec the generator produces for a sprint-tracking app called TaskPulse.

Step 1: the requirement names the entity

The PRD says, in plain language: "An engineering lead creates a sprint with a name, a start date, an end date, and a target story-point capacity. Sprints belong to a workspace."

That one sentence already contains the whole table: an entity (sprint), its fields (name, start, end, target points), and its relationship (belongs to a workspace). The generator's job is to turn that sentence into DDL instead of leaving it as prose:

CREATE TABLE public.sprints (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  workspace_id UUID NOT NULL REFERENCES public.workspaces(id) ON DELETE CASCADE,
  name TEXT NOT NULL,
  start_date TIMESTAMPTZ NOT NULL,
  end_date TIMESTAMPTZ NOT NULL,
  target_points INTEGER DEFAULT 0 CHECK (target_points >= 0),
  created_at TIMESTAMPTZ DEFAULT now()
);
Enter fullscreen mode Exit fullscreen mode

Nothing here is invented. Every column traces back to a line in the PRD, and the CHECK on target points traces back to the acceptance criteria ("target capacity must be a positive number"). When a column cannot be traced to a requirement, that is a smell — it means someone guessed.

Step 2: the schema carries its own security

A table without an access rule is a leak waiting for a query. So the same file that defines the table also defines who can touch it — a Row Level Security policy that ties every row to workspace membership:

ALTER TABLE public.sprints ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Tenant Workspace Isolation" ON public.sprints
  FOR ALL USING (
    workspace_id IN (
      SELECT workspace_id FROM public.workspace_members
      WHERE user_id = auth.uid()
    )
  );
Enter fullscreen mode Exit fullscreen mode

This matters because the policy is generated with the schema, not bolted on later. The most common multi-tenant bug I have seen is a table that shipped without RLS because "we will add it in the hardening sprint" — and the hardening sprint never came. When the schema and the policy arrive together, there is no later.

Step 3: the API contract is typed against the same names

The PRD's acceptance criteria say a sprint is created with a name of 3–64 characters and a positive target. The API contract enforces exactly that, with the same names the table uses:

// POST /api/v1/sprints/create
export const CreateSprintSchema = z.object({
  workspaceId: z.string().uuid(),
  name: z.string().min(3).max(64),
  startDate: z.string().datetime(),
  endDate: z.string().datetime(),
  targetPoints: z.number().int().positive().default(40),
});
Enter fullscreen mode Exit fullscreen mode

Three documents, one set of names. The PRD says target_points, the table has target_points, the payload has targetPoints — and the rules file (the fourth file of the suite) tells the coding agent never to invent a different name. That is the whole trick: the schema is not a separate artefact. It is the PRD, written in SQL.

Why generate it instead of writing it by hand

Writing this by hand is not hard. Writing it by hand consistently — every table, every policy, every contract, all agreeing, across a whole product — is where humans slip. The generator does the boring, mechanical part (extract entities, name columns, add the policy, type the contract) so the human can spend their review time on the one thing a generator cannot do: deciding whether the requirement itself is right.

If you want the full shape, the free template behind this format is on GitHub, no signup: https://github.com/web-dev-mehedi/ai-prd-template

And if you would rather generate the whole four-file suite from one paragraph — PRD, UI/UX spec, schema with RLS, and agent rules — the generator is here: https://webdevmehedi.com/ai-prd-generator — 50 free credits on signup, plans from ৳99/mo with bKash and Nagad.

A PRD that never becomes a schema is a wish list. The schema is where the product stops being an idea and starts being a database.

Top comments (0)